From dafee9503d81e8879fd1875827b4c699480429d2 Mon Sep 17 00:00:00 2001 From: Naiem Yeganeh Date: Mon, 21 Nov 2022 01:56:37 +0200 Subject: [PATCH] Update tests --- contracts/dummy/DummyToken.sol | 5 +-- .../taxing/GeneralTaxDistributorDiscrete.sol | 3 +- hardhat.config.js | 4 --- hardhat.config.ts | 20 +++++++++++ package.json | 6 ++-- test/common/Eip712Utils.ts | 34 ++++++++++++++++++- test/common/TestMultiSigCheckable.ts | 5 ++- test/token/TestDaoMintableErc20.ts | 9 +++-- test/token/TestTokenDirect.ts | 10 +++--- tsconfig.json | 17 ++++++++++ yarn.lock | 13 +++---- 11 files changed, 94 insertions(+), 32 deletions(-) delete mode 100644 hardhat.config.js create mode 100644 hardhat.config.ts create mode 100644 tsconfig.json diff --git a/contracts/dummy/DummyToken.sol b/contracts/dummy/DummyToken.sol index 00cc7b5..c976901 100644 --- a/contracts/dummy/DummyToken.sol +++ b/contracts/dummy/DummyToken.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity ^0.8.2; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import "../common/IFerrumDeployer.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; @@ -11,4 +11,5 @@ contract DummyToken is ERC20Burnable { } } -contract DummyTokenOwnable is DummyToken, Ownable {} \ No newline at end of file +contract DummyTokenOwnable is DummyToken, Ownable { +} diff --git a/contracts/taxing/GeneralTaxDistributorDiscrete.sol b/contracts/taxing/GeneralTaxDistributorDiscrete.sol index abaf386..9c2e272 100644 --- a/contracts/taxing/GeneralTaxDistributorDiscrete.sol +++ b/contracts/taxing/GeneralTaxDistributorDiscrete.sol @@ -54,7 +54,7 @@ contract GeneralTaxDistributorDiscrete is GeneralTaxDistributor { amount = remaining; } if (amount != 0) { - distributeToTarget( + return distributeToTarget( i, ti.tokenSpecificConfig, token, @@ -63,5 +63,6 @@ contract GeneralTaxDistributorDiscrete is GeneralTaxDistributor { ); } } + return 0; } } \ No newline at end of file diff --git a/hardhat.config.js b/hardhat.config.js deleted file mode 100644 index 6b533d1..0000000 --- a/hardhat.config.js +++ /dev/null @@ -1,4 +0,0 @@ -/** @type import('hardhat/config').HardhatUserConfig */ -module.exports = { - solidity: "0.8.2", -}; diff --git a/hardhat.config.ts b/hardhat.config.ts new file mode 100644 index 0000000..cfdc6e0 --- /dev/null +++ b/hardhat.config.ts @@ -0,0 +1,20 @@ +import { HardhatUserConfig } from "hardhat/config"; +import '@typechain/hardhat' +import '@nomiclabs/hardhat-ethers' +import '@nomiclabs/hardhat-waffle' + + +const config: HardhatUserConfig = { + solidity: { + compilers: [{ version: "0.8.2", settings: { + optimizer: { + enabled: true, + runs: 200 + } + } }], + }, + +}; + +export default config; + diff --git a/package.json b/package.json index 138e90d..f5713d9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "Commonly used smart contracts from Ferrum Founday", "author": "Ferrum Network", "license": "MIT", + "scripts": { + "postinstall": "npx hardhat compile" + }, "dependencies": { "@openzeppelin/contracts": "^4.1.0", "@openzeppelin/contracts-upgradeable": "^4.3.2", @@ -25,11 +28,10 @@ "@nomiclabs/hardhat-etherscan": "^2.1.3", "@nomiclabs/hardhat-waffle": "^2.0.1", "@typechain/ethers-v5": "^7.0.1", - "@typechain/hardhat": "^2.0.2", + "@typechain/hardhat": "^6.1.4", "@typechain/truffle-v5": "^5.0.0", "@typechain/web3-v1": "^3.0.0", "ethereum-waffle": "^3.4.0", - "hardhat-typechain": "^0.3.5", "ts-generator": "^0.1.1", "typechain": "^5.0.0" } diff --git a/test/common/Eip712Utils.ts b/test/common/Eip712Utils.ts index fec1d21..186540e 100644 --- a/test/common/Eip712Utils.ts +++ b/test/common/Eip712Utils.ts @@ -102,4 +102,36 @@ export function multiSigToBytes(sigs: string[]): string { vs = vs + '0'.repeat(padding); sig = sig + vs; return '0x' + sig; -} \ No newline at end of file +} + +export async function getBridgeMethodCall( + contractName: string, + contractVersion: string, + chainId: number, + bridge: string, + methodName: string, + args: {type: string, name: string, value: string}[], sks: string[]) { + const web3 = new Web3(); + // console.log('We are going to bridge method call it ', args) + const msg = produceSignature( + web3.eth, chainId, bridge, { + contractName: contractName, + contractVersion: contractVersion, + method: methodName, + args, + } as Eip712Params, + ); + // console.log('About to producing msg ', msg) + const sigs = []; + for (const sk of sks) { + console.log(` About to sign with private key ${sk}`); + const {sig, addr} = await signWithPrivateKey(sk, msg.hash!); + sigs.push({sig, addr}); + } + // Make sure that signatures are in the order of the signer address + sigs.sort((s1, s2) => Buffer.from(s2.addr, 'hex') < Buffer.from(s1.addr, 'hex') ? 1 : -1); + const fullSig = multiSigToBytes(sigs.map(s => s.sig)); + console.log(' Full signature is hash: ', msg.hash, 'sig:', fullSig); + msg.signature = fullSig; + return msg; +} diff --git a/test/common/TestMultiSigCheckable.ts b/test/common/TestMultiSigCheckable.ts index 014d58e..200fbf9 100644 --- a/test/common/TestMultiSigCheckable.ts +++ b/test/common/TestMultiSigCheckable.ts @@ -1,9 +1,8 @@ import { expect } from "chai"; import { ethers } from "hardhat"; import { deployWithOwner, expiryInFuture, getCtx, TestContext, throws } from "./Utils"; -import { TestMultiSigCheckable } from '../../typechain/TestMultiSigCheckable'; -import { randomSalt } from "./Eip712Utils"; -import { getBridgeMethodCall } from "../bridge/BridgeUtilsV12"; +import { TestMultiSigCheckable } from '../../typechain-types/TestMultiSigCheckable'; +import { randomSalt, getBridgeMethodCall } from "./Eip712Utils"; interface MutliSigContext extends TestContext { multi: TestMultiSigCheckable; diff --git a/test/token/TestDaoMintableErc20.ts b/test/token/TestDaoMintableErc20.ts index 0b3b95f..9e77ff2 100644 --- a/test/token/TestDaoMintableErc20.ts +++ b/test/token/TestDaoMintableErc20.ts @@ -1,9 +1,8 @@ -import { ethers } from "hardhat"; -import { abi, deployUsingDeployer, deployWithOwner, getCtx, getTransactionLog, Salt, TestContext, throws, Wei, ZeroAddress } from "../common/Utils"; -import { DaoMintableErc20 } from '../../typechain/DaoMintableErc20'; -import { TokenDao } from '../../typechain/TokenDao'; +import { abi, deployWithOwner, getCtx, TestContext, throws, Wei, ZeroAddress } from "../common/Utils"; +import { DaoMintableErc20 } from '../../typechain-types/DaoMintableErc20'; +import { TokenDao } from '../../typechain-types/TokenDao'; import { randomBytes } from "crypto"; -import { getBridgeMethodCall } from "../bridge/BridgeUtilsV12"; +import { getBridgeMethodCall } from "../common/Eip712Utils"; import { expect } from "chai"; const GOV_GROUP_ID = 88; diff --git a/test/token/TestTokenDirect.ts b/test/token/TestTokenDirect.ts index bb7fe01..cc8ec34 100644 --- a/test/token/TestTokenDirect.ts +++ b/test/token/TestTokenDirect.ts @@ -1,11 +1,11 @@ import { ethers } from "hardhat"; import { abi, deployUsingDeployer, getCtx, getTransactionLog, Salt, TestContext, Wei, ZeroAddress } from "../common/Utils"; -import { GenericUpgradableTokenMintable } from '../../typechain/GenericUpgradableTokenMintable'; +import { GenericUpgradableTokenMintable } from '../../typechain-types/GenericUpgradableTokenMintable'; import { GenericUpgradableTokenMintable__factory } from - "../../typechain/factories/GenericUpgradableTokenMintable__factory"; -import { TransparentUpgradeableProxy__factory } from '../../typechain/factories/TransparentUpgradeableProxy__factory'; -import { DirectMinimalErc20__factory } from '../../typechain/factories/DirectMinimalErc20__factory'; -import { DirectMinimalErc20 } from '../../typechain/DirectMinimalErc20'; + "../../typechain-types/factories/GenericUpgradableTokenMintable__factory"; +import { TransparentUpgradeableProxy__factory } from '../../typechain-types/factories/TransparentUpgradeableProxy__factory'; +import { DirectMinimalErc20__factory } from '../../typechain-types/factories/DirectMinimalErc20__factory'; +import { DirectMinimalErc20 } from '../../typechain-types/DirectMinimalErc20'; const f = GenericUpgradableTokenMintable__factory; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5a6f33c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es2020", + "module": "commonjs", + "esModuleInterop": true, + "outDir": "dist", + "resolveJsonModule": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + }, + "include": [ + "./scripts", + "./test" + ], + "files": ["./hardhat.config.ts"] +} diff --git a/yarn.lock b/yarn.lock index 6118d9f..b81191c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1025,10 +1025,10 @@ lodash "^4.17.15" ts-essentials "^7.0.1" -"@typechain/hardhat@^2.0.2": - version "2.3.1" - resolved "https://registry.yarnpkg.com/@typechain/hardhat/-/hardhat-2.3.1.tgz#1e8a6e3795e115a5d5348526282b5c597fab0b78" - integrity sha512-BQV8OKQi0KAzLXCdsPO0pZBNQQ6ra8A2ucC26uFX/kquRBtJu1yEyWnVSmtr07b5hyRoJRpzUeINLnyqz4/MAw== +"@typechain/hardhat@^6.1.4": + version "6.1.4" + resolved "https://registry.yarnpkg.com/@typechain/hardhat/-/hardhat-6.1.4.tgz#da930bf17bdae5e0996b86d37992c6c58b8a49c8" + integrity sha512-S8k5d1Rjc+plwKpkorlifmh72M7Ki0XNUOVVLtdbcA/vLaEkuqZSJFdddpBgS5QxiJP+6CbRa/yO6EVTE2+fMQ== dependencies: fs-extra "^9.1.0" @@ -4428,11 +4428,6 @@ har-validator@~5.1.3: ajv "^6.12.3" har-schema "^2.0.0" -hardhat-typechain@^0.3.5: - version "0.3.5" - resolved "https://registry.yarnpkg.com/hardhat-typechain/-/hardhat-typechain-0.3.5.tgz#8e50616a9da348b33bd001168c8fda9c66b7b4af" - integrity sha512-w9lm8sxqTJACY+V7vijiH+NkPExnmtiQEjsV9JKD1KgMdVk2q8y+RhvU/c4B7+7b1+HylRUCxpOIvFuB3rE4+w== - hardhat@^2.11.2: version "2.12.2" resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.12.2.tgz#6ae985007b20c1f381c6573799d66c1438c4c802"