From 3ed1481812926dac28e20433760f127147d549cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Tesa=C5=99?= Date: Mon, 27 Nov 2023 11:07:27 +0100 Subject: [PATCH] Fix tests --- packages/airnode-adapter/package.json | 2 +- .../src/request-building/authentication.ts | 14 +++++++- packages/airnode-deployer/package.json | 2 +- .../config.example.json | 4 +-- .../create-config.ts | 35 ++++++++++--------- .../config.example.json | 2 +- .../coingecko-pre-processing/create-config.ts | 31 ++++++++-------- .../integrations/config-utils.ts | 2 +- packages/airnode-node/package.json | 2 +- packages/airnode-validator/package.json | 4 +-- yarn.lock | 12 ++----- 11 files changed, 58 insertions(+), 52 deletions(-) diff --git a/packages/airnode-adapter/package.json b/packages/airnode-adapter/package.json index d297314e73..cc31b6abdf 100644 --- a/packages/airnode-adapter/package.json +++ b/packages/airnode-adapter/package.json @@ -19,7 +19,7 @@ "test:watch": "yarn test:ts --watch" }, "dependencies": { - "@api3/ois": "2.2.1", + "@api3/ois": "2.3.0", "@api3/promise-utils": "^0.4.0", "axios": "^1.5.0", "bignumber.js": "^9.1.2", diff --git a/packages/airnode-adapter/src/request-building/authentication.ts b/packages/airnode-adapter/src/request-building/authentication.ts index 1d685e2535..addf09f310 100644 --- a/packages/airnode-adapter/src/request-building/authentication.ts +++ b/packages/airnode-adapter/src/request-building/authentication.ts @@ -88,7 +88,19 @@ function getSchemeAuthentication( credentials: BaseApiCredentials | null, options: CachedBuildRequestOptions ): Partial { - switch (apiSecurityScheme.type) { + // TODO: The ApiSecurityScheme type imported from OIS is typed as "any" by TypeScript making the switch statement + // below be non-exhaustive and generate a TS error. This is a workaround. + type ApiSecuritySchemeType = + | 'apiKey' + | 'http' + | 'relayChainId' + | 'relayChainType' + | 'relayRequesterAddress' + | 'relaySponsorAddress' + | 'relaySponsorWalletAddress' + | 'relayRequestId'; + + switch (apiSecurityScheme.type as ApiSecuritySchemeType) { case 'apiKey': return getApiKeyAuth(apiSecurityScheme, credentials); case 'http': diff --git a/packages/airnode-deployer/package.json b/packages/airnode-deployer/package.json index d21dda8419..61e1bcdb8f 100644 --- a/packages/airnode-deployer/package.json +++ b/packages/airnode-deployer/package.json @@ -43,7 +43,7 @@ "lodash": "^4.17.21", "ora": "^5.4.1", "yargs": "^17.7.2", - "zod": "^3.22.3" + "zod": "^3.22.4" }, "devDependencies": { "@aws-sdk/util-stream-node": "^3.370.0", diff --git a/packages/airnode-examples/integrations/coingecko-post-processing/config.example.json b/packages/airnode-examples/integrations/coingecko-post-processing/config.example.json index 627fb5587f..73331fb203 100644 --- a/packages/airnode-examples/integrations/coingecko-post-processing/config.example.json +++ b/packages/airnode-examples/integrations/coingecko-post-processing/config.example.json @@ -197,9 +197,9 @@ } ], "postProcessingSpecificationV2": { - "environment": "Node async", + "environment": "Node", "timeoutMs": 5000, - "value": "async function({ apiCallResponse }) {\n // Log out every coin data\n apiCallResponse.forEach((coinData) => {\n console.log(`[Post-processing snippet]: Received the following coin data: \\${JSON.stringify(coinData, null, 2)}`);\n });\n\n const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);\n const average = sum(apiCallResponse.map((coinData) => coinData.current_price)) / apiCallResponse.length;\n const percentageChange =\n sum(apiCallResponse.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / apiCallResponse.length;\n\n // Create the data to be sent on chain and multiply it by 10^8 to preserve precision\n return { apiCallResponse: [average, percentageChange].map((x) => x * 10 ** 8) };\n}" + "value": "async function({ apiCallResponse }) {\n // Log out every coin data\n apiCallResponse.forEach((coinData) => {\n console.log(`[Post-processing snippet]: Received the following coin data: \\${JSON.stringify(coinData, null, 2)}`);\n });\n\n const sum = (nums) => nums.reduce((acc, num) => acc + num, 0);\n const average = sum(apiCallResponse.map((coinData) => coinData.current_price)) / apiCallResponse.length;\n const percentageChange =\n sum(apiCallResponse.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / apiCallResponse.length;\n\n // Create the data to be sent on chain and multiply it by 10^8 to preserve precision\n return { apiCallResponse: [average, percentageChange].map((x) => x * 10 ** 8) };\n}" } } ] diff --git a/packages/airnode-examples/integrations/coingecko-post-processing/create-config.ts b/packages/airnode-examples/integrations/coingecko-post-processing/create-config.ts index 3f0a10e746..376a385a2c 100644 --- a/packages/airnode-examples/integrations/coingecko-post-processing/create-config.ts +++ b/packages/airnode-examples/integrations/coingecko-post-processing/create-config.ts @@ -203,25 +203,26 @@ const createConfig = async (generateExampleFile: boolean): Promise => ({ }, }, ], - postProcessingSpecifications: [ - { - environment: 'Node', - timeoutMs: 5000, - value: ` - // Log out every coin data - input.forEach((coinData) => { - console.log(\`[Post-processing snippet]: Received the following coin data: \\\${JSON.stringify(coinData, null, 2)}\`) - }) + postProcessingSpecificationV2: { + environment: 'Node', + timeoutMs: 5000, + value: ` +async function({ apiCallResponse }) { + // Log out every coin data + apiCallResponse.forEach((coinData) => { + console.log(\`[Post-processing snippet]: Received the following coin data: \\\${JSON.stringify(coinData, null, 2)}\`); + }); - const sum = (nums) => nums.reduce((acc, num) => acc + num, 0); - const average = sum(input.map((coinData) => coinData.current_price)) / input.length; - const percentageChange = sum(input.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / input.length; + const sum = (nums) => nums.reduce((acc, num) => acc + num, 0); + const average = sum(apiCallResponse.map((coinData) => coinData.current_price)) / apiCallResponse.length; + const percentageChange = + sum(apiCallResponse.map((coinData) => coinData.price_change_percentage_30d_in_currency)) / apiCallResponse.length; - // Create the data to be sent on chain and multiply it by 10^8 to preserve precision - const output = [average, percentageChange].map((x) => x * 10 ** 8); - `, - }, - ], + // Create the data to be sent on chain and multiply it by 10^8 to preserve precision + return { apiCallResponse: [average, percentageChange].map((x) => x * 10 ** 8) }; +} + `.trim(), + }, }, ], }, diff --git a/packages/airnode-examples/integrations/coingecko-pre-processing/config.example.json b/packages/airnode-examples/integrations/coingecko-pre-processing/config.example.json index de3956d4e1..cd5cbb4eb6 100644 --- a/packages/airnode-examples/integrations/coingecko-pre-processing/config.example.json +++ b/packages/airnode-examples/integrations/coingecko-pre-processing/config.example.json @@ -164,7 +164,7 @@ } ], "preProcessingSpecificationV2": { - "environment": "Node async", + "environment": "Node", "timeoutMs": 5000, "value": "async ({apiCallParameters}) => {\n const rawDate = new Date(apiCallParameters.unixTimestamp * 1000);\n const day = rawDate.getDate().toString().padStart(2, '0');\n const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0\n const year = rawDate.getFullYear();\n\n const formattedDate = day + '-' + month + '-' + year;\n const newApiCallParameters = {...apiCallParameters, unixTimestamp: formattedDate};\n\n console.log(`[Pre-processing snippet]: Formatted \\${apiCallParameters.unixTimestamp} to \\${formattedDate}.`)\n return {apiCallParameters: newApiCallParameters};\n}" } diff --git a/packages/airnode-examples/integrations/coingecko-pre-processing/create-config.ts b/packages/airnode-examples/integrations/coingecko-pre-processing/create-config.ts index 18d93f8e1c..cb7c103429 100644 --- a/packages/airnode-examples/integrations/coingecko-pre-processing/create-config.ts +++ b/packages/airnode-examples/integrations/coingecko-pre-processing/create-config.ts @@ -170,23 +170,24 @@ const createConfig = async (generateExampleFile: boolean): Promise => ({ }, }, ], - preProcessingSpecifications: [ - { - environment: 'Node', - timeoutMs: 5000, - value: ` - const rawDate = new Date(input.unixTimestamp * 1000); - const day = rawDate.getDate().toString().padStart(2, '0'); - const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0 - const year = rawDate.getFullYear(); + preProcessingSpecificationV2: { + environment: 'Node', + timeoutMs: 5000, + value: ` +async ({apiCallParameters}) => { + const rawDate = new Date(apiCallParameters.unixTimestamp * 1000); + const day = rawDate.getDate().toString().padStart(2, '0'); + const month = (rawDate.getMonth() + 1).toString().padStart(2, '0'); // Months start at 0 + const year = rawDate.getFullYear(); - const formattedDate = day + '-' + month + '-' + year; - const output = {...input, unixTimestamp: formattedDate}; + const formattedDate = day + '-' + month + '-' + year; + const newApiCallParameters = {...apiCallParameters, unixTimestamp: formattedDate}; - console.log(\`[Pre-processing snippet]: Formatted \\\${input.unixTimestamp} to \\\${formattedDate}.\`) - `, - }, - ], + console.log(\`[Pre-processing snippet]: Formatted \\\${apiCallParameters.unixTimestamp} to \\\${formattedDate}.\`) + return {apiCallParameters: newApiCallParameters}; +} + `.trim(), + }, }, ], }, diff --git a/packages/airnode-examples/integrations/config-utils.ts b/packages/airnode-examples/integrations/config-utils.ts index 364c01b861..022a46377a 100644 --- a/packages/airnode-examples/integrations/config-utils.ts +++ b/packages/airnode-examples/integrations/config-utils.ts @@ -91,7 +91,7 @@ export const addAirnodeRrpV0DryRunAddress = async (config: Config) => { export const generateConfigFile = async (dirname: string, config: Config, generateExampleFile: boolean) => { const filename = generateExampleFile ? 'config.example.json' : 'config.json'; - const updatedConfig = await addAirnodeRrpV0DryRunAddress(config); + const updatedConfig = generateExampleFile ? config : await addAirnodeRrpV0DryRunAddress(config); const formattedConfig = await format(JSON.stringify(updatedConfig, null, 2), { parser: 'json', printWidth: 120 }); writeFileSync(join(dirname, filename), formattedConfig); diff --git a/packages/airnode-node/package.json b/packages/airnode-node/package.json index a425e5f234..17c4655432 100644 --- a/packages/airnode-node/package.json +++ b/packages/airnode-node/package.json @@ -40,7 +40,7 @@ "google-auth-library": "^9.0.0", "lodash": "^4.17.21", "yargs": "^17.7.2", - "zod": "^3.22.3" + "zod": "^3.22.4" }, "devDependencies": { "@api3/airnode-operation": "^0.13.0", diff --git a/packages/airnode-validator/package.json b/packages/airnode-validator/package.json index bbae351a95..bf7bf6d4d3 100644 --- a/packages/airnode-validator/package.json +++ b/packages/airnode-validator/package.json @@ -22,14 +22,14 @@ }, "dependencies": { "@api3/airnode-protocol": "^0.13.0", - "@api3/ois": "2.2.1", + "@api3/ois": "2.3.0", "@api3/promise-utils": "^0.4.0", "dotenv": "^16.3.1", "ethers": "^5.7.2", "lodash": "^4.17.21", "ora": "^5.4.1", "yargs": "^17.7.2", - "zod": "^3.22.3" + "zod": "^3.22.4" }, "devDependencies": { "@types/yargs": "^17.0.29", diff --git a/yarn.lock b/yarn.lock index 66ef8d3357..2411cedf2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -64,15 +64,7 @@ winston-console-format "^1.0.8" zod "^3.22.4" -"@api3/ois@2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@api3/ois/-/ois-2.2.1.tgz#caa5c672c51b5572cf9bb30226a0647b3a51a57d" - integrity sha512-C4tSMBccDlD8NkZMVATQXOKctI46fSOlzpbZmZoFknsIdYfQvGNU49StGRJZ6fJJkwXEX1TlkRC7rY2yHEJjqw== - dependencies: - lodash "^4.17.21" - zod "^3.22.3" - -"@api3/ois@^2.3.0": +"@api3/ois@2.3.0", "@api3/ois@^2.3.0": version "2.3.0" resolved "https://registry.npmjs.org/@api3/ois/-/ois-2.3.0.tgz#f5407eab380396c70031a82b4d9e188200082474" integrity sha512-B/F9sirQLBZNGClnpK/U585/gqYvjEHNKR5Xgc92LTvPe6F8w9RSW3JNZo4qAc+7Tzly9xr6kmoWQJsgnwD9iQ== @@ -16169,7 +16161,7 @@ zksync-web3@^0.14.3: resolved "https://registry.yarnpkg.com/zksync-web3/-/zksync-web3-0.14.3.tgz#64ac2a16d597464c3fc4ae07447a8007631c57c9" integrity sha512-hT72th4AnqyLW1d5Jlv8N2B/qhEnl2NePK2A3org7tAa24niem/UAaHMkEvmWI3SF9waYUPtqAtjpf+yvQ9zvQ== -zod@^3.22.3, zod@^3.22.4: +zod@^3.22.4: version "3.22.4" resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff" integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==