Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable gas estimation in airnode-examples local flow and E2E test #1836

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-meals-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@api3/airnode-examples': patch
---

Use AirnodeRrpV0DryRun in E2E test
6 changes: 4 additions & 2 deletions packages/airnode-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ The [RRP contract](https://docs.api3.org/reference/airnode/latest/concepts/#airn
which the [requester](https://docs.api3.org/reference/airnode/latest/concepts/requester.html) triggers a request for
Airnode. This contract is common for all Airnodes and requesters on a chain.

If you are using a local blockchain, deploy the contact using the command below. Otherwise, the contract deployed by
API3 on the chosen chain will be used automatically.
If you are using a local blockchain, deploy the contract using the first command below. Otherwise, the contract deployed
by API3 on the chosen chain will be used automatically. The second command, also optional if using a public blockchain,
deploys the contract necessary for gas estimation.

```sh
yarn deploy-rrp
yarn deploy-rrp-dry-run
```

#### 5. (Only if deploying to AWS) Create AWS secrets file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

// We need to compile AirnodeRrp.sol and this is the easiest way to make hardhat do that
// We need to compile AirnodeRrp contracts and this is the easiest way to make hardhat do that
import "@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0.sol";
import "@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0DryRun.sol";
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think await here is redundant because after this line function is ending.

Copy link
Contributor Author

@dcroote dcroote Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks much for this self-explanatory example. It makes me understand the behavior. 🙏🏼

};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
29 changes: 27 additions & 2 deletions packages/airnode-examples/integrations/config-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { writeFileSync } from 'fs';
import { join } from 'path';
import { Config, LocalOrCloudProvider } from '@api3/airnode-node';
import { go } from '@api3/promise-utils';
import { format } from 'prettier';
import {
cliPrint,
Expand Down Expand Up @@ -65,9 +66,33 @@ export const createNodeVersion = () => {
return packageVersion;
};

export const generateConfigFile = (dirname: string, config: Config, generateExampleFile: boolean) => {
/**
* If the AirnodeRrpV0DryRun contract has been deployed, add its address to the config file,
* otherwise, return the config file as is.
*
* Note when using a public blockchain an AirnodeRrpV0DryRun deployment is not necessary as we default
* to using the API3 deployment
*/
export const addAirnodeRrpV0DryRunAddress = async (config: Config) => {
const goAirnodeRrpDryRun = await go(() =>
getDeployedContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0DryRun.sol')
);
if (!goAirnodeRrpDryRun.success) {
return config;
}
const airnodeRrpDryRun = goAirnodeRrpDryRun.data;
return {
...config,
chains: [
{ ...config.chains[0], contracts: { ...config.chains[0].contracts, AirnodeRrpDryRun: airnodeRrpDryRun.address } },
],
};
};

export const generateConfigFile = async (dirname: string, config: Config, generateExampleFile: boolean) => {
const filename = generateExampleFile ? 'config.example.json' : 'config.json';
const formattedConfig = format(JSON.stringify(config, null, 2), { parser: 'json', printWidth: 120 });
const updatedConfig = await addAirnodeRrpV0DryRunAddress(config);
const formattedConfig = format(JSON.stringify(updatedConfig, null, 2), { parser: 'json', printWidth: 120 });
writeFileSync(join(dirname, filename), formattedConfig);

cliPrint.info(`A '${filename}' has been created.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const createConfig = async (generateExampleFile: boolean): Promise<Config> => ({

const generateConfig = async (generateExampleFile = false) => {
const config = await createConfig(generateExampleFile);
generateConfigFile(__dirname, config, generateExampleFile);
await generateConfigFile(__dirname, config, generateExampleFile);
};

export default generateConfig;
1 change: 1 addition & 0 deletions packages/airnode-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"deploy-airnode": "ts-node src/scripts/deploy-airnode.ts",
"deploy-requester": "ts-node src/scripts/deploy-requester.ts",
"deploy-rrp": "ts-node src/scripts/deploy-rrp.ts",
"deploy-rrp-dry-run": "ts-node src/scripts/deploy-rrp-dry-run.ts",
"derive-and-fund-sponsor-wallet": "ts-node src/scripts/derive-and-fund-sponsor-wallet.ts",
"dev:generate-example-files": "ts-node dev-scripts/generate-example-files.ts",
"eth-node": "hardhat node",
Expand Down
8 changes: 8 additions & 0 deletions packages/airnode-examples/src/scripts/deploy-rrp-dry-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { cliPrint, deployContract, runAndHandleErrors } from '../';

const main = async () => {
const airnodeRrpDryRun = await deployContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0DryRun.sol');
cliPrint.info(`AirnodeRrpV0DryRun deployed to address: ${airnodeRrpDryRun.address}`);
};

runAndHandleErrors(main);
2 changes: 1 addition & 1 deletion packages/airnode-examples/src/scripts/deploy-rrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cliPrint, deployContract, runAndHandleErrors } from '../';

const main = async () => {
const airnodeRrp = await deployContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0.sol');
cliPrint.info(`AirnodeRrp deployed to address: ${airnodeRrp.address}`);
cliPrint.info(`AirnodeRrpV0 deployed to address: ${airnodeRrp.address}`);
};

runAndHandleErrors(main);
20 changes: 15 additions & 5 deletions packages/airnode-examples/test/e2e/coingecko-local.feature.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { writeFileSync } from 'fs';
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { Config } from '@api3/airnode-node';
import { logger } from '@api3/airnode-utilities';
import { runCommand, runCommandInBackground } from '../utils';

const integration = 'coingecko-cross-chain-authorizer';

const chooseIntegration = () => {
// We can't use the interactive script to choose the integration, so we specify the details manually
const content = JSON.stringify(
{
integration: 'coingecko-cross-chain-authorizer',
integration: integration,
airnodeType: 'local',
network: 'localhost',
mnemonic: 'test test test test test test test test test test test junk',
Expand All @@ -23,16 +26,23 @@ const chooseIntegration = () => {
writeFileSync(join(__dirname, '../../integration-info.json'), content);
};

const removeFulfillmentGasLimit = () => {
const configPath = join(__dirname, `../../integrations/${integration}/config.json`);
const config: Config = JSON.parse(readFileSync(configPath, 'utf8'));
delete config.chains[0].options.fulfillmentGasLimit;
writeFileSync(configPath, JSON.stringify(config, null, 2));
};

describe('Coingecko integration with containerized Airnode and hardhat', () => {
it('works', () => {
chooseIntegration();

runCommand('yarn deploy-rrp');
runCommand('yarn deploy-rrp-dry-run');
runCommand('yarn create-airnode-config');
runCommand('yarn create-airnode-secrets');

runCommand('yarn ts-node integrations/coingecko-cross-chain-authorizer/deploy-authorizers-and-update-config');

removeFulfillmentGasLimit();
runCommand(`yarn ts-node integrations/${integration}/deploy-authorizers-and-update-config`);
runCommandInBackground('yarn run-airnode-locally');

// Try running the rest of the commands, but make sure to kill the Airnode running in background process gracefully.
Expand Down