Test decoder using hardhat RPC, geth-statediff RPC and ipld-eth-server GQL endpoints for fetching storage slots (#77)

* Implement test for getStorageValue with geth server.

* Wait for transaction to complete in tests.

* Implement tests with ipld-eth-client using graphql endpoint.

Co-authored-by: nikugogoi <95nikass@gmail.com>
This commit is contained in:
Ashwin Phatak 2021-06-18 18:09:50 +05:30 committed by GitHub
parent 6a33c704b8
commit c9bf002675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 420 additions and 253 deletions

View File

@ -0,0 +1,3 @@
ETH_RPC_URL=http://127.0.0.1:8545
GQL_ENDPOINT=http://127.0.0.1:8083/graphql

View File

@ -6,3 +6,6 @@ artifacts
#yarn
yarn-error.log
#Environment variables
.env

View File

@ -10,10 +10,23 @@ Get value of state variable from storage for a solidity contract.
## Instructions
Run the tests using the following command
```bash
$ yarn test
```
* Create environment variable file
```bash
$ cp .env.example .env
```
* Run the tests using the following command
```bash
$ yarn test
# For testing on private network using RPC getStorageAt.
# Set ETH_RPC_URL in .env
$ yarn test:geth-rpc
# For testing on private network using ipld-eth-client getStorageAt.
# Set GQL_ENDPOINT in .env
$ yarn test:ipld-gql
```
## Different Types
@ -26,7 +39,7 @@ $ yarn test
* [x] Fixed-size byte arrays
* [x] Enums
* [ ] Function Types
* [x] Reference Types
* [ ] Reference Types
* [x] Arrays
* [x] Get all elements in array
* [x] Get element in array by index

View File

@ -1,3 +1,4 @@
import 'dotenv/config';
import { task, HardhatUserConfig } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
@ -35,6 +36,14 @@ const config: HardhatUserConfig = {
paths: {
sources: './test/contracts',
tests: './src'
},
networks: {
private: {
url: process.env.ETH_RPC_URL
}
},
mocha: {
timeout: 50000
}
};

View File

@ -12,6 +12,7 @@
"@types/mocha": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"@vulcanize/ipld-eth-client": "^0.1.0",
"chai": "^4.3.4",
"eslint": "^7.27.0",
"eslint-config-semistandard": "^15.0.1",
@ -29,7 +30,11 @@
"scripts": {
"build": "tsc",
"test": "hardhat test",
"test:geth-rpc": "hardhat --network private test",
"test:ipld-gql": "IPLD_GQL=true hardhat --network private test",
"lint": "eslint ."
},
"dependencies": {}
"dependencies": {
"dotenv": "^10.0.0"
}
}

View File

@ -1,4 +1,5 @@
import { expect } from 'chai';
import '@nomiclabs/hardhat-ethers';
import { artifacts, ethers } from 'hardhat';
import { getEventNameTopics } from './logs';

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
import { ContractInterface } from '@ethersproject/contracts';
import '@nomiclabs/hardhat-ethers';
import { artifacts, ethers } from 'hardhat';
import { CompilerOutput, CompilerOutputBytecode } from 'hardhat/types';
@ -68,3 +69,13 @@ export const getStorageAt: GetStorageAt = async ({ blockHash, contract, slot })
}
};
};
/**
* Generate array of dummy addresses of specified length.
* @param length
*/
export const generateDummyAddresses = (length: number): Array<string> => {
return Array.from({ length }, () => {
return ethers.utils.hexlify(ethers.utils.randomBytes(20));
});
};

View File

@ -5229,6 +5229,11 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
dotenv@^8.2.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"