From 3b0c4ddf9477536ec19f664fe17b4ff29844a55e Mon Sep 17 00:00:00 2001 From: Max Kalashnikoff Date: Tue, 6 Feb 2024 20:48:11 +0100 Subject: [PATCH] feat(testsing): splitting integration tests (#503) --- integration/generators.test.ts | 39 ++++ integration/health.test.ts | 14 ++ integration/history.test.ts | 67 +++++++ integration/identity.test.ts | 20 ++ integration/init.ts | 23 +++ integration/integration.test.ts | 335 -------------------------------- integration/middlewares.test.ts | 27 +++ integration/names.test.ts | 120 ++++++++++++ integration/portfolio.test.ts | 16 ++ integration/proxy.test.ts | 33 ++++ integration/tsconfig.json | 5 + 11 files changed, 364 insertions(+), 335 deletions(-) create mode 100644 integration/generators.test.ts create mode 100644 integration/health.test.ts create mode 100644 integration/history.test.ts create mode 100644 integration/identity.test.ts create mode 100644 integration/init.ts delete mode 100644 integration/integration.test.ts create mode 100644 integration/middlewares.test.ts create mode 100644 integration/names.test.ts create mode 100644 integration/portfolio.test.ts create mode 100644 integration/proxy.test.ts create mode 100644 integration/tsconfig.json diff --git a/integration/generators.test.ts b/integration/generators.test.ts new file mode 100644 index 000000000..4ad0b7091 --- /dev/null +++ b/integration/generators.test.ts @@ -0,0 +1,39 @@ +import { getTestSetup } from './init'; + +describe('Generators', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + it('onramp Pay SDK URL', async () => { + const expected_host = 'https://pay.coinbase.com/buy/select-asset'; + const address = '0x1234567890123456789012345678901234567890'; + const partnerUserId = 'someUserID'; + const payload = { + partnerUserId, + destinationWallets:[{ address }], + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, + payload + ) + expect(resp.status).toBe(200) + expect(typeof resp.data).toBe('object') + expect(typeof resp.data.url).toBe('string') + expect(resp.data.url).toContain(expected_host) + expect(resp.data.url).toContain(address) + expect(resp.data.url).toContain(partnerUserId) + }) + it('onramp Pay SDK URL wrong payload', async () => { + const address = '0x1234567890123456789012345678901234567890'; + const partnerUserId = 'someUserID'; + // Creating the wrong payload + const payload = { + partner: partnerUserId, + someWallets:[{ address }], + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, + payload + ) + expect(resp.status).toBe(400) + }) +}) diff --git a/integration/health.test.ts b/integration/health.test.ts new file mode 100644 index 000000000..0fe62d9ff --- /dev/null +++ b/integration/health.test.ts @@ -0,0 +1,14 @@ +import { getTestSetup } from './init'; + +describe('Health', () => { + it('is healthy', async () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + const resp: any = await httpClient.get(`${baseUrl}/health`) + + expect(resp.status).toBe(200) + expect(resp.data).toContain('OK v') + expect(resp.data).toContain('hash:') + expect(resp.data).toContain('features:') + expect(resp.data).toContain('uptime:') + }) +}) diff --git a/integration/history.test.ts b/integration/history.test.ts new file mode 100644 index 000000000..74810642e --- /dev/null +++ b/integration/history.test.ts @@ -0,0 +1,67 @@ +import { getTestSetup } from './init'; + +describe('Transactions history', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + const fulfilled_address = '0x63755B7B300228254FB7d16321eCD3B87f98ca2a' + const empty_history_address = '0x739ff389c8eBd9339E69611d46Eec6212179BB67' + + it('fulfilled history', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/${fulfilled_address}/history?projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + expect(typeof resp.data.data).toBe('object') + expect(resp.data.data).toHaveLength(50) + expect(typeof resp.data.next).toBe('string') + expect(resp.data.next).toHaveLength(80) + + for (const item of resp.data.data) { + expect(item.id).toBeDefined() + expect(typeof item.metadata).toBe('object') + // expect chain to be null or caip-2 format + if (item.metadata.chain !== null) { + expect(item.metadata.chain).toEqual(expect.stringMatching(/^(eip155:)?\d+$/)); + } else { + expect(item.metadata.chain).toBeNull(); + } + expect(typeof item.metadata.application).toBe('object') + expect(typeof item.transfers).toBe('object') + } + }) + it('empty history', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/${empty_history_address}/history?projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + expect(typeof resp.data.data).toBe('object') + expect(resp.data.data).toHaveLength(0) + expect(resp.data.next).toBeNull() + }) + it('wrong address', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/0X${fulfilled_address}/history?projectId=${projectId}`, + ) + expect(resp.status).toBe(400) + }) + it('onramp Coinbase provider', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/${fulfilled_address}/history?onramp=coinbase&projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + expect(typeof resp.data.next).toBe('string') + expect(typeof resp.data.data).toBe('object') + + const first = resp.data.data[0] + expect(first.id).toBeDefined() + expect(first.metadata.sentFrom).toBe('Coinbase') + expect(first.metadata.operationType).toBe('buy') + expect(first.metadata.status).toEqual(expect.stringMatching(/^ONRAMP_TRANSACTION_STATUS_/)); + }) + it('onramp wrong provider', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/${fulfilled_address}/history?onramp=some&projectId=${projectId}`, + ) + expect(resp.status).toBe(400) + }) +}) diff --git a/integration/identity.test.ts b/integration/identity.test.ts new file mode 100644 index 000000000..e0caa7e41 --- /dev/null +++ b/integration/identity.test.ts @@ -0,0 +1,20 @@ +import { getTestSetup } from './init'; + +describe('Identity', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + it('known ens', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63?chainId=eip155%3A1&projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + expect(resp.data.name).toBe('cyberdrk.eth') + }) + it('unknown ens', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA64?chainId=eip155%3A1&projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + expect(resp.data.name).toBe(null) + }) +}) diff --git a/integration/init.ts b/integration/init.ts new file mode 100644 index 000000000..aec4e61a2 --- /dev/null +++ b/integration/init.ts @@ -0,0 +1,23 @@ +import axios from 'axios' + +interface TestSetup { + baseUrl: string; + projectId: string; + httpClient: any; +} + +export const getTestSetup = (): TestSetup => { + const baseUrl = process.env.RPC_URL; + if (!baseUrl) { + throw new Error('RPC_URL environment variable not set'); + } + const projectId = process.env.PROJECT_ID; + if (!projectId) { + throw new Error('PROJECT_ID environment variable not set'); + } + const httpClient = axios.create({ + validateStatus: (_status) => true, + }) + + return { baseUrl, projectId, httpClient }; +}; diff --git a/integration/integration.test.ts b/integration/integration.test.ts deleted file mode 100644 index 5de9a3465..000000000 --- a/integration/integration.test.ts +++ /dev/null @@ -1,335 +0,0 @@ -import axios from 'axios' -import { ethers } from "ethers" - -const http = axios.create({ - validateStatus: (_status) => true, -}) - -declare let process: { - env: { - RPC_URL: string - PROJECT_ID: string - } -} - -describe('blockchain api', () => { - let baseUrl: string - let projectId: string - beforeAll(() => { - baseUrl = process.env.RPC_URL - if (!baseUrl) { - throw new Error('RPC_URL environment variable not set') - } - projectId = process.env.PROJECT_ID - if (!projectId) { - throw new Error('PROJECT_ID environment variable not set') - } - }) - describe('Health', () => { - it('is healthy', async () => { - const resp: any = await http.get(`${baseUrl}/health`) - - expect(resp.status).toBe(200) - expect(resp.data).toContain('OK v') - expect(resp.data).toContain('hash:') - expect(resp.data).toContain('features:') - expect(resp.data).toContain('uptime:') - }) - }) - describe('Middlewares', () => { - it('OK response should contain x-request-id header', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63/history?projectId=${projectId}`, - ) - expect(resp.headers).toBeDefined(); - expect(resp.status).toBe(200); - // Check if the header value is a valid UUIDv4 - const uuidv4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; - expect(resp.headers['x-request-id']).toMatch(uuidv4Pattern); - }) - it('Error response should contain x-request-id header', async () => { - // Wrong address request - let resp: any = await http.get( - `${baseUrl}/v1/account/0Ff3ea39310011333095CFCcCc7c4Ad74034CABA63/history?projectId=${projectId}`, - ) - expect(resp.headers).toBeDefined(); - expect(resp.status).toBe(400); - // Check if the header value is a valid UUIDv4 - const uuidv4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; - expect(resp.headers['x-request-id']).toMatch(uuidv4Pattern); - }) - }) - describe('Identity', () => { - it('known ens', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63?chainId=eip155%3A1&projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - expect(resp.data.name).toBe('cyberdrk.eth') - }) - it('unknown ens', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/identity/0xf3ea39310011333095CFCcCc7c4Ad74034CABA64?chainId=eip155%3A1&projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - expect(resp.data.name).toBe(null) - }) - }) - describe('Transactions history', () => { - const fulfilled_address = '0x63755B7B300228254FB7d16321eCD3B87f98ca2a' - const empty_history_address = '0x739ff389c8eBd9339E69611d46Eec6212179BB67' - - it('fulfilled history', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/${fulfilled_address}/history?projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - expect(typeof resp.data.data).toBe('object') - expect(resp.data.data).toHaveLength(50) - expect(typeof resp.data.next).toBe('string') - expect(resp.data.next).toHaveLength(80) - - for (const item of resp.data.data) { - expect(item.id).toBeDefined() - expect(typeof item.metadata).toBe('object') - // expect chain to be null or caip-2 format - if (item.metadata.chain !== null) { - expect(item.metadata.chain).toEqual(expect.stringMatching(/^(eip155:)?\d+$/)); - } else { - expect(item.metadata.chain).toBeNull(); - } - expect(typeof item.metadata.application).toBe('object') - expect(typeof item.transfers).toBe('object') - } - }) - it('empty history', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/${empty_history_address}/history?projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - expect(typeof resp.data.data).toBe('object') - expect(resp.data.data).toHaveLength(0) - expect(resp.data.next).toBeNull() - }) - it('wrong address', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/0X${fulfilled_address}/history?projectId=${projectId}`, - ) - expect(resp.status).toBe(400) - }) - it('onramp Coinbase provider', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/${fulfilled_address}/history?onramp=coinbase&projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - expect(typeof resp.data.next).toBe('string') - expect(typeof resp.data.data).toBe('object') - - const first = resp.data.data[0] - expect(first.id).toBeDefined() - expect(first.metadata.sentFrom).toBe('Coinbase') - expect(first.metadata.operationType).toBe('buy') - expect(first.metadata.status).toEqual(expect.stringMatching(/^ONRAMP_TRANSACTION_STATUS_/)); - }) - it('onramp wrong provider', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/${fulfilled_address}/history?onramp=some&projectId=${projectId}`, - ) - expect(resp.status).toBe(400) - }) - }) - describe('Portfolio', () => { - it('finds portfolio items', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/account/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63/portfolio?projectId=${projectId}`, - ) - expect(resp.status).toBe(200) - const first = resp.data.data[0] - expect(first.id).toBeDefined() - expect(first.name).toBeDefined() - expect(first.symbol).toBeDefined() - }) - }) - - describe('Account profile names', () => { - // Generate a new eth wallet - const wallet = ethers.Wallet.createRandom(); - const address = wallet.address; - const coin_type = 60; // SLIP-44 Ethereum - const chain_id = 1; // Ethereum mainnet - const attributes = { - bio: 'integration test domain', - }; - - // Generate a random name - const randomString = Array.from({ length: 10 }, - () => (Math.random().toString(36)[2] || '0')).join('') - const name = `${randomString}.connect.test`; - - // Create a message to sign - const messageObject = { - name, - coin_type, - chain_id, - address, - attributes, - timestamp: Math.round(Date.now() / 1000) - }; - const message = JSON.stringify(messageObject); - - it('register with wrong signature', async () => { - // Sign the message - const signature = await wallet.signMessage('some other message'); - - const payload = { - message, - signature, - coin_type, - address, - }; - let resp: any = await http.post( - `${baseUrl}/v1/profile/account/${name}`, - payload - ) - expect(resp.status).toBe(401) - }) - it('register new name', async () => { - // Sign the message - const signature = await wallet.signMessage(message); - - const payload = { - message, - signature, - coin_type, - address, - }; - let resp: any = await http.post( - `${baseUrl}/v1/profile/account/${name}`, - payload - ) - expect(resp.status).toBe(200) - }) - it('try register already registered name', async () => { - // Sign the message - const signature = await wallet.signMessage(message); - - const payload = { - message, - signature, - coin_type, - address, - }; - let resp: any = await http.post( - `${baseUrl}/v1/profile/account/${name}`, - payload - ) - expect(resp.status).toBe(400) - }) - it('inconsistent payload', async () => { - // Name in payload is different from the one in the request path - const signature = await wallet.signMessage(message); - - const payload = { - message, - signature, - coin_type, - address, - }; - let resp: any = await http.post( - `${baseUrl}/v1/profile/account/someothername.connect.id`, - payload - ) - expect(resp.status).toBe(400) - }) - it('name forward lookup', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/profile/account/${name}` - ) - expect(resp.status).toBe(200) - expect(resp.data.name).toBe(name) - expect(typeof resp.data.addresses).toBe('object') - // ENSIP-11 using the 60 for the Ethereum mainnet - const first = resp.data.addresses["60"] - expect(first.address).toBe(address) - }) - it('name reverse lookup', async () => { - let resp: any = await http.get( - `${baseUrl}/v1/profile/reverse/${address}` - ) - expect(resp.status).toBe(200) - expect(typeof resp.data).toBe('object') - const first_name = resp.data[0] - expect(first_name.name).toBe(name) - expect(typeof first_name.addresses).toBe('object') - // ENSIP-11 using the 60 for the Ethereum mainnet - const first_address = first_name.addresses["60"] - expect(first_address.address).toBe(address) - }) - }) - - describe('Generators', () => { - it('onramp Pay SDK URL', async () => { - const expected_host = 'https://pay.coinbase.com/buy/select-asset'; - const address = '0x1234567890123456789012345678901234567890'; - const partnerUserId = 'someUserID'; - const payload = { - partnerUserId, - destinationWallets:[{ address }], - }; - let resp: any = await http.post( - `${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, - payload - ) - expect(resp.status).toBe(200) - expect(typeof resp.data).toBe('object') - expect(typeof resp.data.url).toBe('string') - expect(resp.data.url).toContain(expected_host) - expect(resp.data.url).toContain(address) - expect(resp.data.url).toContain(partnerUserId) - }) - it('onramp Pay SDK URL wrong payload', async () => { - const address = '0x1234567890123456789012345678901234567890'; - const partnerUserId = 'someUserID'; - // Creating the wrong payload - const payload = { - partner: partnerUserId, - someWallets:[{ address }], - }; - let resp: any = await http.post( - `${baseUrl}/v1/generators/onrampurl?projectId=${projectId}`, - payload - ) - expect(resp.status).toBe(400) - }) - }) - - describe('Proxy', () => { - it('Exact provider request', async () => { - const providerId = 'Binance'; - const chainId = "eip155:56"; - const payload = { - jsonrpc: "2.0", - method: "eth_chainId", - params: [], - id: 1, - }; - - // Allowed projectID - // Only allowed projectID can make this type of request - let resp: any = await http.post( - `${baseUrl}/v1?chainId=${chainId}&projectId=${projectId}&providerId=${providerId}`, - payload - ) - expect(resp.status).toBe(200) - expect(typeof resp.data).toBe('object') - - // Not allowed projectID for this request type - const notAllowedProjectId = 'someprojectid'; - resp = await http.post( - `${baseUrl}/v1?chainId=${chainId}&projectId=${notAllowedProjectId}&providerId=${providerId}`, - payload - ) - expect(resp.status).toBe(401) - }) - }) -}) diff --git a/integration/middlewares.test.ts b/integration/middlewares.test.ts new file mode 100644 index 000000000..a3f01b06e --- /dev/null +++ b/integration/middlewares.test.ts @@ -0,0 +1,27 @@ +import { getTestSetup } from './init'; + +describe('Middlewares', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + it('OK response should contain x-request-id header', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63/history?projectId=${projectId}`, + ) + expect(resp.headers).toBeDefined(); + expect(resp.status).toBe(200); + // Check if the header value is a valid UUIDv4 + const uuidv4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + expect(resp.headers['x-request-id']).toMatch(uuidv4Pattern); + }) + it('Error response should contain x-request-id header', async () => { + // Wrong address request + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/0Ff3ea39310011333095CFCcCc7c4Ad74034CABA63/history?projectId=${projectId}`, + ) + expect(resp.headers).toBeDefined(); + expect(resp.status).toBe(400); + // Check if the header value is a valid UUIDv4 + const uuidv4Pattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + expect(resp.headers['x-request-id']).toMatch(uuidv4Pattern); + }) +}) diff --git a/integration/names.test.ts b/integration/names.test.ts new file mode 100644 index 000000000..2397ea843 --- /dev/null +++ b/integration/names.test.ts @@ -0,0 +1,120 @@ +import { getTestSetup } from './init'; +import { ethers } from "ethers" + +describe('Account profile names', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + // Generate a new eth wallet + const wallet = ethers.Wallet.createRandom(); + const address = wallet.address; + const coin_type = 60; // SLIP-44 Ethereum + const chain_id = 1; // Ethereum mainnet + const attributes = { + bio: 'integration test domain', + }; + + // Generate a random name + const randomString = Array.from({ length: 10 }, + () => (Math.random().toString(36)[2] || '0')).join('') + const name = `${randomString}.connect.test`; + + // Create a message to sign + const messageObject = { + name, + coin_type, + chain_id, + address, + attributes, + timestamp: Math.round(Date.now() / 1000) + }; + const message = JSON.stringify(messageObject); + + it('register with wrong signature', async () => { + // Sign the message + const signature = await wallet.signMessage('some other message'); + + const payload = { + message, + signature, + coin_type, + address, + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/profile/account/${name}`, + payload + ) + expect(resp.status).toBe(401) + }) + it('register new name', async () => { + // Sign the message + const signature = await wallet.signMessage(message); + + const payload = { + message, + signature, + coin_type, + address, + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/profile/account/${name}`, + payload + ) + expect(resp.status).toBe(200) + }) + it('try register already registered name', async () => { + // Sign the message + const signature = await wallet.signMessage(message); + + const payload = { + message, + signature, + coin_type, + address, + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/profile/account/${name}`, + payload + ) + expect(resp.status).toBe(400) + }) + it('inconsistent payload', async () => { + // Name in payload is different from the one in the request path + const signature = await wallet.signMessage(message); + + const payload = { + message, + signature, + coin_type, + address, + }; + let resp: any = await httpClient.post( + `${baseUrl}/v1/profile/account/someothername.connect.id`, + payload + ) + expect(resp.status).toBe(400) + }) + it('name forward lookup', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/profile/account/${name}` + ) + expect(resp.status).toBe(200) + expect(resp.data.name).toBe(name) + expect(typeof resp.data.addresses).toBe('object') + // ENSIP-11 using the 60 for the Ethereum mainnet + const first = resp.data.addresses["60"] + expect(first.address).toBe(address) + }) + it('name reverse lookup', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/profile/reverse/${address}` + ) + expect(resp.status).toBe(200) + expect(typeof resp.data).toBe('object') + const first_name = resp.data[0] + expect(first_name.name).toBe(name) + expect(typeof first_name.addresses).toBe('object') + // ENSIP-11 using the 60 for the Ethereum mainnet + const first_address = first_name.addresses["60"] + expect(first_address.address).toBe(address) + }) +}) diff --git a/integration/portfolio.test.ts b/integration/portfolio.test.ts new file mode 100644 index 000000000..953567738 --- /dev/null +++ b/integration/portfolio.test.ts @@ -0,0 +1,16 @@ +import { getTestSetup } from './init'; + +describe('Portfolio', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + it('finds portfolio items', async () => { + let resp: any = await httpClient.get( + `${baseUrl}/v1/account/0xf3ea39310011333095CFCcCc7c4Ad74034CABA63/portfolio?projectId=${projectId}`, + ) + expect(resp.status).toBe(200) + const first = resp.data.data[0] + expect(first.id).toBeDefined() + expect(first.name).toBeDefined() + expect(first.symbol).toBeDefined() + }) +}) diff --git a/integration/proxy.test.ts b/integration/proxy.test.ts new file mode 100644 index 000000000..adcc117b7 --- /dev/null +++ b/integration/proxy.test.ts @@ -0,0 +1,33 @@ +import { getTestSetup } from './init'; + +describe('Proxy', () => { + const { baseUrl, projectId, httpClient } = getTestSetup(); + + it('Exact provider request', async () => { + const providerId = 'Binance'; + const chainId = "eip155:56"; + const payload = { + jsonrpc: "2.0", + method: "eth_chainId", + params: [], + id: 1, + }; + + // Allowed projectID + // Only allowed projectID can make this type of request + let resp: any = await httpClient.post( + `${baseUrl}/v1?chainId=${chainId}&projectId=${projectId}&providerId=${providerId}`, + payload + ) + expect(resp.status).toBe(200) + expect(typeof resp.data).toBe('object') + + // Not allowed projectID for this request type + const notAllowedProjectId = 'someprojectid'; + resp = await httpClient.post( + `${baseUrl}/v1?chainId=${chainId}&projectId=${notAllowedProjectId}&providerId=${providerId}`, + payload + ) + expect(resp.status).toBe(401) + }) +}) diff --git a/integration/tsconfig.json b/integration/tsconfig.json new file mode 100644 index 000000000..2f9804271 --- /dev/null +++ b/integration/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "esModuleInterop": true + } +}