Use hardhat-exposed to reduce the need for mocks (#3666)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-01-03 15:38:13 +01:00
committed by GitHub
parent a81b0d0b21
commit c1d9da4052
190 changed files with 2297 additions and 4311 deletions

View File

@ -1,9 +1,10 @@
const ethSigUtil = require('eth-sig-util');
const Wallet = require('ethereumjs-wallet').default;
const { EIP712Domain, domainSeparator } = require('../../helpers/eip712');
const { EIP712Domain, domainSeparator, hashTypedData } = require('../../helpers/eip712');
const { getChainId } = require('../../helpers/chainid');
const EIP712 = artifacts.require('EIP712External');
const EIP712Verifier = artifacts.require('$EIP712Verifier');
contract('EIP712', function (accounts) {
const [mailTo] = accounts;
@ -12,25 +13,30 @@ contract('EIP712', function (accounts) {
const version = '1';
beforeEach('deploying', async function () {
this.eip712 = await EIP712.new(name, version);
this.eip712 = await EIP712Verifier.new(name, version);
// We get the chain id from the contract because Ganache (used for coverage) does not return the same chain id
// from within the EVM as from the JSON RPC interface.
// See https://github.com/trufflesuite/ganache-core/issues/515
this.chainId = await this.eip712.getChainId();
this.domain = {
name,
version,
chainId: await getChainId(),
verifyingContract: this.eip712.address,
};
});
it('domain separator', async function () {
expect(
await this.eip712.domainSeparator(),
).to.equal(
await domainSeparator(name, version, this.chainId, this.eip712.address),
);
const expected = await domainSeparator(this.domain);
expect(await this.eip712.$_domainSeparatorV4()).to.equal(expected);
});
it('hash digest', async function () {
const structhash = web3.utils.randomHex(32);
const expected = await hashTypedData(this.domain, structhash);
expect(await this.eip712.$_hashTypedDataV4(structhash)).to.be.equal(expected);
});
it('digest', async function () {
const chainId = this.chainId;
const verifyingContract = this.eip712.address;
const message = {
to: mailTo,
contents: 'very interesting',
@ -44,7 +50,7 @@ contract('EIP712', function (accounts) {
{ name: 'contents', type: 'string' },
],
},
domain: { name, version, chainId, verifyingContract },
domain: this.domain,
primaryType: 'Mail',
message,
};