Skip to content

Commit

Permalink
adding singRequest into utils
Browse files Browse the repository at this point in the history
PP-428: Refactor to use ethers and hardhat WIP

PP-428: Separete relay hub test into another file

PP-428: Working 27 tests

PP-428: Working 33 tests

PP-428: Troubleshooting timeout error. WIP

chore(test): relayhub testing. 31 tests passing. 1 pending

PP-428: wip debuggins final test

chore(test): all testing working for relayhub

chore(test): increase gas limit to 0.01 usd for relayhub tests

test: unit tests for relay verifier

test: unit tests for deployVerifier

test: customSmartWalletDeployVerifier tests

test: fix typo on function name

feat: add draft tests for verify method

feat: advance test on verify

feat: improve tests for verify() function

feat: add unit tests for SmartWallet.execute()

feat: add unit tests for SmartWallet.directExecute()

feat: delete not required tests

feat: add new test and delete not required expects after pair revision

fix: minor changes from pair revision

fix: refactoring the EIP712 library

fix: minor changes for pair revision

 test[relay-hub]: refactor with pr suggestions

test: remove duplicated code and fix type error in relayhub tests

test: remove comments from relay hub tests

feat: contract deployment with hardhat and ethers

chore: lint

test: divided deployment script into modules

test: fix test

fix: send in real contract instance

feat: do not deploy UtilToken on mainnet

refactor(ethers): cleans up deployer

chore(ethers): removes hh dependency compiler

refactor(ethers): cleans up deployer

chore: fix merge conflicts

test(rif-relay-contracts): add tests for the penalizer contract

test(rif-relay-contracts): update dependency

Feature/PP-278/PP-329/tasks-over-scripts (#75)

* feat: implement hardhat tasks

* chore: lint

* chore: no .vscode folder

* fix: typo on function, relocate map creation

* chore: lint

Co-authored-by: Christos Otarola <christos@Christoss-MacBook-Pro.local>
  • Loading branch information
2 people authored and AndresQuijano committed Oct 14, 2022
1 parent b013360 commit 4e596d3
Show file tree
Hide file tree
Showing 24 changed files with 3,508 additions and 3,276 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
name: CI for RIF-Relay-Contract
on: [push]
jobs:
lint&test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16.x'
lint_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "16.x"

- name: Install dependencies
run: npm install
- name: Install dependencies
run: npm install

- name: Check Codestyles errors
run: npm run ci:format
- name: Check Codestyles errors
run: npm run ci:format

- name: Check Linter bugs for Typescript
run: npm run ci:lint
- name: Check Linter bugs for Typescript
run: npm run ci:lint

- name: Download rif-relay node configuration
run: |
wget https://raw.githubusercontent.com/rsksmart/rif-relay/develop/docker/node.conf
wget https://raw.githubusercontent.com/rsksmart/rif-relay/develop/docker/logback.xml
- name: Download rif-relay node configuration
run: |
wget https://raw.githubusercontent.com/rsksmart/rif-relay/develop/docker/node.conf
wget https://raw.githubusercontent.com/rsksmart/rif-relay/develop/docker/logback.xml
- name: Run docker image
run: docker run -d -p 127.0.0.1:4444:4444 -p 127.0.0.1:4445:4445 --name enveloping-rskj -it -v $PWD/logback.xml:/etc/rsk/logback.xml -v $PWD/node.conf:/etc/rsk/node.conf rsksmart/rskj:IRIS-3 --regtest
- name: Run docker image
run: docker run -d -p 127.0.0.1:4444:4444 -p 127.0.0.1:4445:4445 --name enveloping-rskj -it -v $PWD/logback.xml:/etc/rsk/logback.xml -v $PWD/node.conf:/etc/rsk/node.conf rsksmart/rskj:IRIS-3 --regtest

- name: Run tests
run: npm run ci:test
- name: Run tests
run: npm run ci:test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ artifacts
/build
/dist
/contracts-exposed

.vscode
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ The project is ready to be used at this point.

The contracts can be deployed in the following way:

1. Configure the `truffle.js` file on the root of the project to set your network
2. Run `npx truffle migrate --network <NETWORK_NAME>`
1. Configure the `hardhat.config.ts` file on the root of the project to set your network
2. Run `npm run deploy --network <NETWORK_NAME>`

This will start the migration on `<NETWORK_NAME>`; at the end of it you should see a summary with all the contract addresses.

Expand All @@ -62,7 +62,7 @@ This file also is being exported on the distributable version to provide the con

Once the smart contracts are deployed, tokens must be individually allowed to be able to work with the RIF Relay system. There are some helpful commands for this:

1. To allow a specific token, run `npm run allowTokens <TOKEN_ADDRESSES> <NETWORK_NAME>` where:
1. To allow a specific token, run `npm run allow-tokens <NETWORK_NAME> <TOKEN_ADDRESSES>` where:
- `<TOKEN_ADDRESSES>` is a comma-separated list of the token addresses to be allowed on the available verifiers
- `<NETWORK_NAME>` is an optional parameter for the network name, taken from the `truffle.js` file (default value is `regtest`) **important! This should be the same network name as the one used to deploy the contracts**
2. To query allowed tokens run `npm run allowedTokens <NETWORK_NAME>`. This will display them on the console.
Expand Down
1 change: 1 addition & 0 deletions contract-addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hardhat.31337":{"Penalizer":"0x5FbDB2315678afecb367f032d93F642f64180aa3","RelayHub":"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512","SmartWallet":"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0","SmartWalletFactory":"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9","DeployVerifier":"0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9","RelayVerifier":"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707","CustomSmartWallet":"0x0165878A594ca255338adfa4d48449f69242Eb8F","CustomSmartWalletFactory":"0xa513E6E4b8f2a923D98304ec87F64353C4D5C853","CustomSmartWalletDeployVerifier":"0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6","UtilToken":"0x610178dA211FEF7D417bC0e6FeD39F05609AD788","VersionRegistry":"0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"},"regtest.33":{"Penalizer":"0x77A151FE2Ac2300Ccc89FD00330Add038e6e6B45","RelayHub":"0x05840bf34268900b255eFdeAb4E8b18A74Ec822E","SmartWallet":"0xE66d6095193f9Bec61F46d47EB2AC3C4315b01F1","SmartWalletFactory":"0x55898Faccf2D03C6B4d0564b33cC6D397Ca32A17","DeployVerifier":"0xe3d09A82a6f07Ca1B4C6964866075473531E426E","RelayVerifier":"0x9F54ffdB097e4c87C539bcA6DBaeE4BA5F74700C","CustomSmartWallet":"0x4F64cCeC8e2692Bf674f5EAa4E0170B14db8e709","CustomSmartWalletFactory":"0x151A4b94c288a6be9eE48d63949b1d44Dc4e2999","CustomSmartWalletDeployVerifier":"0x091E9C08dA594c831002309E139389d8eCa2A99e","UtilToken":"0xB3647664cD22BcC7B1defEbD3767Df9a0B3E4009","VersionRegistry":"0xBa755AEF160f11185Fc2726DAdd9D3B029aEE50f"}}
22 changes: 21 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-contract-sizer';
import 'hardhat-docgen';
import 'hardhat-watcher';
import { HardhatUserConfig } from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';
import { allowTokens } from './scripts/allowTokens';
import { deploy } from './scripts/deploy';
import { HardhatUserConfig, task } from 'hardhat/config';

const config: HardhatUserConfig = {
solidity: {
Expand All @@ -26,6 +29,7 @@ const config: HardhatUserConfig = {
networks: {
regtest: {
url: 'http://localhost:4444',
chainId: 33,
},
},
typechain: {
Expand Down Expand Up @@ -66,6 +70,22 @@ const config: HardhatUserConfig = {
clear: true,
runOnCompile: false,
},
mocha: {
timeout: 20000,
},
};

task('deploy', 'Deploys rif-relay contracts to selected network')
.setAction(async (args, hre) => {
await deploy(hre);
}
);

task('allow-tokens', 'allows a list of tokens')
.addPositionalParam('tokenlist', 'list of tokens')
.setAction(async (taskArgs: { tokenlist: string }, hre) => {
await allowTokens(taskArgs, hre);
}
);

export default config;
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@
{
"name": "Francisco Tobar",
"url": "https://github.com/franciscotobar"
},
{
"name": "Christos Otarola",
"url": "https://github/ironFe93"
}
],
"main": "dist/index.js",
"scripts": {
"allow-tokens": "hardhat allow-tokens --network",
"ci:format": "prettier -c contracts/**/*.sol && prettier -c **/*.ts",
"ci:lint": "solhint 'contracts/**/*.sol' && eslint test --ext .ts ",
"ci:test": "npm run compile && npm run test",
"clean": "rm -rf typechain-types cache bin dist artifacts contracts-exposed && hardhat clean",
"compile": "npm run clean && hardhat compile --force",
"deploy": "hardhat run scripts/deploy.ts --network",
"deploy-configure": "hardhat run scripts/deploy.ts --network",
"deploy": "hardhat deploy --network",
"deploy-configure": "hardhat deploy --network",
"docs": "hardhat docgen",
"format": "npm run format:sol && npm run format:ts",
"format:sol": "prettier -c -w --no-editorconfig contracts/**/*.sol contracts/**/**/*.sol",
Expand All @@ -65,27 +70,32 @@
"lint:sol": "solhint --fix 'contracts/**/*.sol'",
"lint:ts": "eslint test --ext .ts --fix",
"prepare": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\"",
"tdd": "npm run compile && REPORT_GAS=true hardhat watch tdd",
"test": "REPORT_GAS=true hardhat test"
"tdd": "TEST=true npm run compile && REPORT_GAS=true hardhat watch tdd",
"test": "TEST=true REPORT_GAS=true hardhat test"
},
"lint-staged": {
"*.ts": "eslint --cache --fix",
"package.json": "npx sort-package-json"
},
"dependencies": {
"@metamask/eth-sig-util": "^4.0.1",
"@nomicfoundation/hardhat-toolbox": "^1.0.2",
"@nomiclabs/hardhat-ethers": "^2.1.1",
"@openzeppelin/contracts": "^3.4.0",
"hardhat": "^2.10.2",
"hardhat-contract-sizer": "^2.6.1",
"hardhat-docgen": "^1.3.0",
"hardhat-watcher": "^2.5.0",
"sinon": "^14.0.0",
"typechain": "^8.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@defi-wonderland/smock": "^2.2.0",
"@openzeppelin/contracts": "^3.4.0",
"@types/node": "^18.8.3",
"@types/sinon": "^10.0.13",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.33.1",
"chai-as-promised": "^7.1.1",
Expand Down
83 changes: 83 additions & 0 deletions scripts/allowTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ContractTransaction } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { getExistingConfig } from './deploy';

export const allowTokens = async (
taskArgs: { tokenlist: string },
hre: HardhatRuntimeEnvironment
) => {
const tokenAddresses = taskArgs.tokenlist.split(',');

const { ethers, network } = hre;

if (!network) {
throw new Error('Unknown Network');
}

const { chainId } = network.config;

if (!chainId) {
throw new Error('Unknown Chain Id');
}

const contractAddresses = getExistingConfig();

if (!contractAddresses) {
throw new Error('No contracts deployed');
}

const networkChainKey = `${network.name}.${chainId}`;

const deployVerifierAddress =
contractAddresses[networkChainKey].DeployVerifier;
const relayVerifierAddress = contractAddresses[networkChainKey].RelayVerifier;
const customDeployVerifierAddress =
contractAddresses[networkChainKey].CustomSmartWalletDeployVerifier;

if (!deployVerifierAddress) {
throw new Error('Could not obtain deploy verifier address');
}

if (!relayVerifierAddress) {
throw new Error('Could not obtain relay verifier address');
}

if (!customDeployVerifierAddress) {
throw new Error('Could not obtain custom deploy verifier address');
}

const deployVerifier = await ethers.getContractAt(
'DeployVerifier',
deployVerifierAddress
);
const relayVerifier = await ethers.getContractAt(
'RelayVerifier',
relayVerifierAddress
);
const customDeployVerifier = await ethers.getContractAt(
'CustomSmartWalletDeployVerifier',
customDeployVerifierAddress
);

const verifierMap: Map<
string,
{ acceptToken: (tokenAddress: string) => Promise<ContractTransaction> }
> = new Map();
verifierMap.set('deployVerifier', deployVerifier);
verifierMap.set('relayVerifier', relayVerifier);
verifierMap.set('customDeployVerifier', customDeployVerifier);

for (const tokenAddress of tokenAddresses) {
for (const [key, verifier] of verifierMap) {
try {
await verifier.acceptToken(tokenAddress);
} catch (error) {
console.error(
`Error adding token with address ${tokenAddress} to allowed tokens on ${key}`
);
throw error;
}
}
}
console.log('Tokens allowed successfully!');
};
Loading

0 comments on commit 4e596d3

Please sign in to comment.