Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Nov 27, 2023
1 parent 8dc05e9 commit 3ed1481
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/airnode-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion packages/airnode-adapter/src/request-building/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ function getSchemeAuthentication(
credentials: BaseApiCredentials | null,
options: CachedBuildRequestOptions
): Partial<Authentication> {
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':
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,26 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
},
},
],
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(),
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,24 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({
},
},
],
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(),
},
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-examples/integrations/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/airnode-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 2 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@
winston-console-format "^1.0.8"
zod "^3.22.4"

"@api3/[email protected]":
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/[email protected]", "@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==
Expand Down Expand Up @@ -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==

0 comments on commit 3ed1481

Please sign in to comment.