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

Add evm tests for ctx state after chain upgrade #277

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ts-tests/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAINNET_DEPLOYER_KEY = xxx
1 change: 1 addition & 0 deletions ts-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.env
5 changes: 0 additions & 5 deletions ts-tests/.mocharc.json

This file was deleted.

13 changes: 12 additions & 1 deletion ts-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo build --release --no-default-features --features manual-seal,rpc_binary_se
npm install
```

## Run the tests
## Run automated tests

```bash
npm run build && npm run test
Expand All @@ -34,3 +34,14 @@ ICE_LOG="warn,rpc=trace" npm run test
```

(The Ice node be listening for RPC on port 19933, mostly to avoid conflict with already running substrate node)

## Run tests for contracts state
Ensure that the deployed contract state is intact.
```bash
npm run test-ctx-state
```
`The contract is readily available on SNOW Network.`
*<b>Optionally:</b>* If you save your `private key` in `.env` file, you can deploy the contract to mainnet:
```bash
npm run deploy-upgrade-ctx
```
35 changes: 35 additions & 0 deletions ts-tests/contracts/NetworkUpgrade.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;

contract NetworkUpgrade {

uint256 number;
string message;
uint256[] testArray;

sharma66mahesh marked this conversation as resolved.
Show resolved Hide resolved
struct TS {
uint256 num;
string message;
}
TS testStruct;

struct ContractState {
uint256 number;
string message;
uint256[] testArray;
TS testStruct;
}

constructor(uint256 _num, string memory _msg) {
number = _num;
message = _msg;
testStruct = TS(_num, _msg);
testArray.push(_num);
testArray.push(_num * 2);
}

function get() public view returns(ContractState memory) {
return ContractState(number, message, testArray, testStruct);
}
}
6 changes: 5 additions & 1 deletion ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"fmt-check": "prettier ./tests --check",
"fmt": "prettier ./tests --write",
"build": "truffle compile",
"test": "mocha -r ts-node/register 'tests/**/test-*.{js,ts}'"
"test": "mocha -r ts-node/register 'tests/test-*.{js,ts}'",
"deploy-upgrade-ctx": "node -r ts-node/register -r dotenv/config tests/networkUpgradeTests/deploy-upgrade-ctx.ts",
"test-ctx-state": "mocha -r ts-node/register tests/networkUpgradeTests/test-ctx-state.ts"
},
"author": "",
"license": "ISC",
Expand All @@ -16,6 +18,7 @@
"@types/mocha": "^8.0.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.0.3",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.4.6",
"mocha": "^8.0.1",
Expand All @@ -28,6 +31,7 @@
},
"devDependencies": {
"@types/chai-as-promised": "^7.1.5",
"@types/node": "^18.13.0",
"prettier": "^2.6.2"
}
}
4 changes: 4 additions & 0 deletions ts-tests/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export const BLOCK_TIMESTAMP = 6; // 6 seconds per block
export const BLOCK_HASH_COUNT = 256;
export const EXISTENTIAL_DEPOSIT = 10_000_000_000_000_000; // The minimum amount required to keep an account open
export const BLOCK_GAS_LIMIT = 60000000;

export const SNOW_RPC_ENDPOINT = "https://snow-rpc.icenetwork.io:9933";
Copy link
Contributor

Choose a reason for hiding this comment

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

may be this should be configurable so that we can run these tests against other snow urls?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The RPC url, chain id and contract address can be moved to the .env file, to make these configurable.

These values however, are not used on the github actions since they need to be run manually with npm test-ctx-state on every mainnet network upgrade.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add two networks Arctic and Snow.
And possibility to run test on different networks

For example:

npm run test-ctx-state arctic
npm run test-ctx-state snow

or

npm run test-ctx-state --chain arctic
npm run test-ctx-state --chain snow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there would also be requirement to add command for local net, then staging too.

So how about setting the npm command as just
npm run test-ctx-state
and based on the node ws endpoint, chainID and contract address set on the env file, it will make checks on the respective env?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Source text
I think we will move these tests in to another Git Action task.(e2e tests) Because In my opinion It doesn't make any sense to run them in current flow. Because we should run this tests only after network upgrade and not for every commit.
In this case we need to configure network in the process of running.

What do you think?

export const SNOW_CHAIN_ID = 552;
export const SNOW_UPGRADE_CTX_ADDRESS = "0xa56D94F9b2412A639626C11855a72024345f2E17";
8 changes: 8 additions & 0 deletions ts-tests/tests/networkUpgradeTests/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ethers } from "ethers";

import { SNOW_CHAIN_ID, SNOW_RPC_ENDPOINT } from "../config";

export const ethersProvider = new ethers.providers.StaticJsonRpcProvider(SNOW_RPC_ENDPOINT, {
chainId: SNOW_CHAIN_ID,
name: "snow-mainnet",
});
23 changes: 23 additions & 0 deletions ts-tests/tests/networkUpgradeTests/deploy-upgrade-ctx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Contract, ContractFactory, Signer, Wallet } from "ethers";
import dotenv from "dotenv";

import { ethersProvider } from "./api";
import UpgradeCtx from "../../build/contracts/NetworkUpgrade.json";

dotenv.config();
const MAINNET_DEPLOYER_KEY = process.env["MAINNET_DEPLOYER_KEY"];

async function deployContract() {
let deployer: Signer = new Wallet(MAINNET_DEPLOYER_KEY, ethersProvider);
let factory = new ContractFactory(UpgradeCtx.abi, UpgradeCtx.bytecode, deployer);
const contract: Contract = await factory.deploy(20, "SNOW Network");

//wait until contract deployed
await contract.deployed();

console.log("Deployer wallet: ", await deployer.getAddress());
console.log("Contract address: ", contract.address);
console.log("\nSuccessfully deployed contract");
}

deployContract();
11 changes: 11 additions & 0 deletions ts-tests/tests/networkUpgradeTests/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BigNumber } from "ethers";

export interface ContractResponse {
number: BigNumber;
message: String;
testStruct: {
num: BigNumber;
message: String;
};
testArray: BigNumber[];
}
26 changes: 26 additions & 0 deletions ts-tests/tests/networkUpgradeTests/test-ctx-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Contract, BigNumber } from "ethers";
import { expect } from "chai";
import { step } from "mocha-steps";

import { ContractResponse } from "./interfaces";
import { ethersProvider } from "./api";
import UpgradeCtx from "../../build/contracts/NetworkUpgrade.json";
import { SNOW_UPGRADE_CTX_ADDRESS } from "../config";

describe("Tests for checking existing contracts storage", () => {
step("Ensure the contract state is intact", async function (done) {
this.timeout(10_000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we use sleep here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to ensure that if this particular test takes more than 10sec to execute, it will timeout and fail


const contract: Contract = new Contract(SNOW_UPGRADE_CTX_ADDRESS, UpgradeCtx.abi, ethersProvider);

const { number, message, testStruct, testArray }: ContractResponse = await contract.get();

expect(number.toNumber(), "Returned an invalid number").to.equal(20);
expect(message, "Returned an invalid string").to.equal("SNOW Network");
expect(testStruct.num.toNumber(), "Returned an invalid struct").to.equal(20);
expect(testStruct.message, "Returned an invalid struct").to.equal("SNOW Network");
expect(testArray, "Returned an invalid array").to.eql([BigNumber.from(20), BigNumber.from(40)]);

done();
});
});
10 changes: 5 additions & 5 deletions ts-tests/tests/test-assets-evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describeWithIce("Ice RPC (AssetsERC20)", (context) => {
const tx = await erc20.transfer(receiver, "10");
await tx.wait();
const balanceOf = await erc20.balanceOf(receiver);
expect(balanceOf.toString()).to.equal((Number.parseInt(prevBalance)+10).toString());
expect(balanceOf.toString()).to.equal((Number.parseInt(prevBalance) + 10).toString());
});
// erc20Plus

Expand All @@ -65,18 +65,18 @@ describeWithIce("Ice RPC (AssetsERC20)", (context) => {
it("should burn token", async function () {
this.timeout(15000);
const prevSupply = await erc20Plus.totalSupply();
const tx= await erc20Plus.burn(genesisAccount.getAddress(),"1", {gasLimit: 5000000});
const tx = await erc20Plus.burn(genesisAccount.getAddress(), "1", { gasLimit: 5000000 });
await tx.wait();
const totalSupply = await erc20Plus.totalSupply();
expect(totalSupply.toString()).to.equal((Number.parseInt(prevSupply)-1).toString());
expect(totalSupply.toString()).to.equal((Number.parseInt(prevSupply) - 1).toString());
});

it("should mint token", async function () {
this.timeout(15000);
const prevSupply = await erc20Plus.totalSupply();
const tx= await erc20Plus.mint(genesisAccount.getAddress(),"1", {gasLimit: 5000000});
const tx = await erc20Plus.mint(genesisAccount.getAddress(), "1", { gasLimit: 5000000 });
await tx.wait();
const totalSupply = await erc20Plus.totalSupply();
expect(totalSupply.toString()).to.equal((Number.parseInt(prevSupply)+1).toString());
expect(totalSupply.toString()).to.equal((Number.parseInt(prevSupply) + 1).toString());
});
});
41 changes: 33 additions & 8 deletions ts-tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz"
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==

"@types/node@^18.13.0":
version "18.13.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.13.0.tgz#0400d1e6ce87e9d3032c19eb6c58205b0d3f7850"
integrity sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==

"@types/pbkdf2@^3.0.0":
version "3.1.0"
resolved "https://registry.npmjs.org/@types/pbkdf2/-/pbkdf2-3.1.0.tgz"
Expand Down Expand Up @@ -2591,9 +2596,9 @@ camelcase@^6.0.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30000844:
version "1.0.30001449"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001449.tgz#a8d11f6a814c75c9ce9d851dc53eb1d1dfbcd657"
integrity sha512-CPB+UL9XMT/Av+pJxCKGhdx+yg1hzplvFJQlJ2n68PyQGMz9L/E2zCyLdOL8uasbouTUgnPl+y0tccI/se+BEw==
version "1.0.30001451"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001451.tgz#2e197c698fc1373d63e1406d6607ea4617c613f1"
integrity sha512-XY7UbUpGRatZzoRft//5xOa69/1iGJRBlrieH6QYrkKLIFn3m7OVEJ81dSrKoy2BnKsdbX5cLrOispZNYo9v2w==

caseless@~0.12.0:
version "0.12.0"
Expand Down Expand Up @@ -3169,7 +3174,7 @@ decamelize@^4.0.0:

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
resolved "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz"
integrity sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og==

decompress-response@^3.3.0:
Expand Down Expand Up @@ -3346,6 +3351,11 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"

dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==

dotignore@~0.1.2:
version "0.1.2"
resolved "https://registry.npmjs.org/dotignore/-/dotignore-0.1.2.tgz"
Expand Down Expand Up @@ -3377,9 +3387,9 @@ ee-first@1.1.1:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.3.47:
version "1.4.284"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz#61046d1e4cab3a25238f6bf7413795270f125592"
integrity sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==
version "1.4.289"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.289.tgz#02b59b1096486fc0bd4871a0484d8317802c6658"
integrity sha512-relLdMfPBxqGCxy7Gyfm1HcbRPcFUJdlgnCPVgQ23sr1TvUrRJz0/QPoGP0+x41wOVSTN/Wi3w6YDgHiHJGOzg==

elliptic@6.5.4, elliptic@^6.4.0, elliptic@^6.5.2, elliptic@^6.5.3, elliptic@^6.5.4:
version "6.5.4"
Expand Down Expand Up @@ -3689,6 +3699,14 @@ eth-sig-util@3.0.0:
tweetnacl "^1.0.0"
tweetnacl-util "^0.15.0"

eth-sig-util@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-1.4.2.tgz#8d958202c7edbaae839707fba6f09ff327606210"
integrity sha512-iNZ576iTOGcfllftB73cPB5AN+XUQAT/T8xzsILsghXC1o8gJUqe3RHlcDqagu+biFpYQ61KQrZZJza8eRSYqw==
dependencies:
ethereumjs-abi "git+https://github.com/ethereumjs/ethereumjs-abi.git"
ethereumjs-util "^5.1.1"

eth-tx-summary@^3.1.2:
version "3.2.4"
resolved "https://registry.npmjs.org/eth-tx-summary/-/eth-tx-summary-3.2.4.tgz"
Expand Down Expand Up @@ -3780,6 +3798,13 @@ ethereumjs-abi@0.6.8:
bn.js "^4.11.8"
ethereumjs-util "^6.0.0"

"ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git":
version "0.6.8"
resolved "git+https://github.com/ethereumjs/ethereumjs-abi.git#ee3994657fa7a427238e6ba92a84d0b529bbcde0"
dependencies:
bn.js "^4.11.8"
ethereumjs-util "^6.0.0"

ethereumjs-account@3.0.0, ethereumjs-account@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/ethereumjs-account/-/ethereumjs-account-3.0.0.tgz"
Expand Down Expand Up @@ -4404,7 +4429,7 @@ fs.realpath@^1.0.0:

fsevents@~2.3.1, fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

function-bind@^1.1.1:
Expand Down