Skip to content

Commit

Permalink
Merge pull request #851 from NexusMutual/chore/remove-web3-truffle
Browse files Browse the repository at this point in the history
Chore/remove web3 truffle
  • Loading branch information
shark0der authored May 4, 2023
2 parents ebad150 + 1b8ccb2 commit 4b055d0
Show file tree
Hide file tree
Showing 38 changed files with 8,631 additions and 12,798 deletions.
2 changes: 0 additions & 2 deletions hardhat.config.js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require('dotenv').config();
require('@typechain/hardhat');
require('@nomiclabs/hardhat-web3');
require('@nomiclabs/hardhat-truffle5');
require('@nomiclabs/hardhat-etherscan');
require('@nomicfoundation/hardhat-chai-matchers');
require('solidity-coverage');
Expand Down
20 changes: 16 additions & 4 deletions hardhat.config.js/tasks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
const { task } = require('hardhat/config');
const { TASK_TYPECHAIN } = require('@typechain/hardhat/dist/constants');
const { TASK_COMPILE } = require('hardhat/builtin-tasks/task-names');
const { TASK_COMPILE, TASK_TEST_SETUP_TEST_ENVIRONMENT, TASK_TEST } = require('hardhat/builtin-tasks/task-names');

task('test', async (args, hre, runSuper) => {
task(TASK_TEST, async (args, hre, runSuper) => {
const testFiles = args.testFiles.length ? args.testFiles : ['test/index.js'];
await runSuper({ ...args, testFiles });
});

task('test:setup-test-environment', async (_, hre) => {
hre.accounts = await hre.web3.eth.getAccounts();
task(TASK_TEST_SETUP_TEST_ENVIRONMENT, async (_, hre) => {
const accounts = await hre.ethers.getSigners();
hre.accounts = {
defaultSender: accounts[0],
nonMembers: accounts.slice(1, 5),
members: accounts.slice(5, 10),
advisoryBoardMembers: accounts.slice(10, 15),
internalContracts: accounts.slice(15, 20),
nonInternalContracts: accounts.slice(20, 25),
governanceContracts: accounts.slice(25, 30),
stakingPoolManagers: accounts.slice(30, 35),
emergencyAdmin: accounts[35],
generalPurpose: accounts.slice(36),
};
});

task(TASK_TYPECHAIN, async (args, hre, runSuper) => {
Expand Down
34 changes: 1 addition & 33 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('assert');
const readline = require('readline');
const { BN, toBN } = require('web3').utils;
const { BigNumber } = require('ethers');

const toBytes = (string, size = 32) => {
Expand All @@ -20,7 +19,7 @@ const filterArgsKeys = args => {
for (const key of Object.keys(args)) {
if (isNaN(key) && key !== '__length__') {
const value = args[key];
params[key] = BN.isBN(value) ? value.toString() : value;
params[key] = BigNumber.isBigNumber(value) ? value.toString() : value;
}
}
return params;
Expand All @@ -45,36 +44,6 @@ function waitForInput(query) {
);
}

function bnEqual(actual, expected, message) {
if (BigNumber.isBigNumber(actual)) {
const fgYellow = '\x1b[33m';
const reset = '\x1b[0m';
console.warn(
`${fgYellow}%s${reset}`,
[
'Warning',
'Use Hardhat Chai Matchers instead of bnEqual',
'https://hardhat.org/hardhat-chai-matchers/docs/overview#big-numbers',
].join(': '),
);
}

const actualBN = toBN(actual);
const expectedBN = toBN(expected);
const error = message || `expected ${actualBN.toString()} to equal ${expectedBN.toString()}`;

if (actualBN.eq(expectedBN)) {
return;
}

throw new assert.AssertionError({
message: error,
actual: actualBN.toString(),
expected: expectedBN.toString(),
operator: 'bnEqual',
});
}

function zeroPadRight(bytes, length) {
return new Uint8Array(length).fill(0).map((x, i) => bytes[i] || x);
}
Expand All @@ -83,7 +52,6 @@ const daysToSeconds = days => days * 24 * 60 * 60;
const hoursToSeconds = hours => hours * 60 * 60;

module.exports = {
bnEqual,
filterArgsKeys,
hex,
toBytes,
Expand Down
Loading

0 comments on commit 4b055d0

Please sign in to comment.