Finalize test migration: remove legacy dependencies and test helpers (#4797)
This commit is contained in:
@ -29,7 +29,7 @@ describe('Address', function () {
|
||||
it('reverts when sending non-zero amounts', async function () {
|
||||
await expect(this.mock.$sendValue(this.other, 1))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressInsufficientBalance')
|
||||
.withArgs(this.mock.target);
|
||||
.withArgs(this.mock);
|
||||
});
|
||||
});
|
||||
|
||||
@ -42,7 +42,7 @@ describe('Address', function () {
|
||||
|
||||
describe('with EOA recipient', function () {
|
||||
it('sends 0 wei', async function () {
|
||||
await expect(this.mock.$sendValue(this.recipient, 0)).to.changeEtherBalance(this.recipient.address, 0);
|
||||
await expect(this.mock.$sendValue(this.recipient, 0)).to.changeEtherBalance(this.recipient, 0);
|
||||
});
|
||||
|
||||
it('sends non-zero amounts', async function () {
|
||||
@ -60,7 +60,7 @@ describe('Address', function () {
|
||||
it('reverts when sending more than the balance', async function () {
|
||||
await expect(this.mock.$sendValue(this.recipient, funds + 1n))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressInsufficientBalance')
|
||||
.withArgs(this.mock.target);
|
||||
.withArgs(this.mock);
|
||||
});
|
||||
});
|
||||
|
||||
@ -145,7 +145,7 @@ describe('Address', function () {
|
||||
|
||||
await expect(this.mock.$functionCall(this.recipient, call))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressEmptyCode')
|
||||
.withArgs(this.recipient.address);
|
||||
.withArgs(this.recipient);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -170,7 +170,7 @@ describe('Address', function () {
|
||||
|
||||
await expect(this.mock.$functionCallWithValue(this.target, call, value))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressInsufficientBalance')
|
||||
.withArgs(this.mock.target);
|
||||
.withArgs(this.mock);
|
||||
});
|
||||
|
||||
it('calls the requested function with existing value', async function () {
|
||||
@ -240,7 +240,7 @@ describe('Address', function () {
|
||||
|
||||
await expect(this.mock.$functionStaticCall(this.recipient, call))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressEmptyCode')
|
||||
.withArgs(this.recipient.address);
|
||||
.withArgs(this.recipient);
|
||||
});
|
||||
});
|
||||
|
||||
@ -273,7 +273,7 @@ describe('Address', function () {
|
||||
|
||||
await expect(this.mock.$functionDelegateCall(this.recipient, call))
|
||||
.to.be.revertedWithCustomError(this.mock, 'AddressEmptyCode')
|
||||
.withArgs(this.recipient.address);
|
||||
.withArgs(this.recipient);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -12,15 +12,13 @@ function shouldBehaveLikeRegularContext() {
|
||||
|
||||
describe('msgSender', function () {
|
||||
it('returns the transaction sender when called from an EOA', async function () {
|
||||
await expect(this.context.connect(this.sender).msgSender())
|
||||
.to.emit(this.context, 'Sender')
|
||||
.withArgs(this.sender.address);
|
||||
await expect(this.context.connect(this.sender).msgSender()).to.emit(this.context, 'Sender').withArgs(this.sender);
|
||||
});
|
||||
|
||||
it('returns the transaction sender when called from another contract', async function () {
|
||||
await expect(this.contextHelper.connect(this.sender).callSender(this.context))
|
||||
.to.emit(this.context, 'Sender')
|
||||
.withArgs(this.contextHelper.target);
|
||||
.withArgs(this.contextHelper);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ describe('Create2', function () {
|
||||
.to.emit(this.factory, 'return$deploy')
|
||||
.withArgs(offChainComputed);
|
||||
|
||||
expect(this.constructorLessBytecode).to.include((await web3.eth.getCode(offChainComputed)).slice(2));
|
||||
expect(this.constructorLessBytecode).to.include((await ethers.provider.getCode(offChainComputed)).slice(2));
|
||||
});
|
||||
|
||||
it('deploys a contract with constructor arguments', async function () {
|
||||
@ -84,7 +84,7 @@ describe('Create2', function () {
|
||||
|
||||
const instance = await ethers.getContractAt('VestingWallet', offChainComputed);
|
||||
|
||||
expect(await instance.owner()).to.equal(this.other.address);
|
||||
expect(await instance.owner()).to.equal(this.other);
|
||||
});
|
||||
|
||||
it('deploys a contract with funds deposited in the factory', async function () {
|
||||
|
||||
@ -29,9 +29,9 @@ describe('Multicall', function () {
|
||||
]),
|
||||
)
|
||||
.to.emit(this.mock, 'Transfer')
|
||||
.withArgs(this.holder.address, this.alice.address, this.amount / 2n)
|
||||
.withArgs(this.holder, this.alice, this.amount / 2n)
|
||||
.to.emit(this.mock, 'Transfer')
|
||||
.withArgs(this.holder.address, this.bruce.address, this.amount / 3n);
|
||||
.withArgs(this.holder, this.bruce, this.amount / 3n);
|
||||
|
||||
expect(await this.mock.balanceOf(this.alice)).to.equal(this.amount / 2n);
|
||||
expect(await this.mock.balanceOf(this.bruce)).to.equal(this.amount / 3n);
|
||||
@ -54,7 +54,7 @@ describe('Multicall', function () {
|
||||
]),
|
||||
)
|
||||
.to.be.revertedWithCustomError(this.mock, 'ERC20InsufficientBalance')
|
||||
.withArgs(this.holder.address, 0, this.amount);
|
||||
.withArgs(this.holder, 0, this.amount);
|
||||
|
||||
expect(await this.mock.balanceOf(this.alice)).to.equal(0n);
|
||||
});
|
||||
@ -67,6 +67,6 @@ describe('Multicall', function () {
|
||||
]),
|
||||
)
|
||||
.to.be.revertedWithCustomError(this.mock, 'ERC20InsufficientBalance')
|
||||
.withArgs(this.holder.address, 0, this.amount);
|
||||
.withArgs(this.holder, 0, this.amount);
|
||||
});
|
||||
});
|
||||
|
||||
@ -69,7 +69,7 @@ describe('Nonces', function () {
|
||||
|
||||
await expect(this.mock.$_useCheckedNonce(this.sender, currentNonce + 1n))
|
||||
.to.be.revertedWithCustomError(this.mock, 'InvalidAccountNonce')
|
||||
.withArgs(this.sender.address, currentNonce);
|
||||
.withArgs(this.sender, currentNonce);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -39,7 +39,7 @@ describe('Pausable', function () {
|
||||
});
|
||||
|
||||
it('emits a Paused event', async function () {
|
||||
await expect(this.tx).to.emit(this.mock, 'Paused').withArgs(this.pauser.address);
|
||||
await expect(this.tx).to.emit(this.mock, 'Paused').withArgs(this.pauser);
|
||||
});
|
||||
|
||||
it('cannot perform normal process in pause', async function () {
|
||||
@ -67,7 +67,7 @@ describe('Pausable', function () {
|
||||
});
|
||||
|
||||
it('emits an Unpaused event', async function () {
|
||||
await expect(this.tx).to.emit(this.mock, 'Unpaused').withArgs(this.pauser.address);
|
||||
await expect(this.tx).to.emit(this.mock, 'Unpaused').withArgs(this.pauser);
|
||||
});
|
||||
|
||||
it('should resume allowing normal process', async function () {
|
||||
|
||||
@ -6,10 +6,6 @@ const TEST_MESSAGE = ethers.id('OpenZeppelin');
|
||||
const WRONG_MESSAGE = ethers.id('Nope');
|
||||
const NON_HASH_MESSAGE = '0xabcd';
|
||||
|
||||
function toSignature(signature) {
|
||||
return ethers.Signature.from(signature);
|
||||
}
|
||||
|
||||
async function fixture() {
|
||||
const [signer] = await ethers.getSigners();
|
||||
const mock = await ethers.deployContract('$ECDSA');
|
||||
@ -48,7 +44,7 @@ describe('ECDSA', function () {
|
||||
const signature = await this.signer.signMessage(TEST_MESSAGE);
|
||||
|
||||
// Recover the signer address from the generated message and signature.
|
||||
expect(await this.mock.$recover(ethers.hashMessage(TEST_MESSAGE), signature)).to.equal(this.signer.address);
|
||||
expect(await this.mock.$recover(ethers.hashMessage(TEST_MESSAGE), signature)).to.equal(this.signer);
|
||||
});
|
||||
|
||||
it('returns signer address with correct signature for arbitrary length message', async function () {
|
||||
@ -56,12 +52,12 @@ describe('ECDSA', function () {
|
||||
const signature = await this.signer.signMessage(NON_HASH_MESSAGE);
|
||||
|
||||
// Recover the signer address from the generated message and signature.
|
||||
expect(await this.mock.$recover(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.equal(this.signer.address);
|
||||
expect(await this.mock.$recover(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.equal(this.signer);
|
||||
});
|
||||
|
||||
it('returns a different address', async function () {
|
||||
const signature = await this.signer.signMessage(TEST_MESSAGE);
|
||||
expect(await this.mock.$recover(WRONG_MESSAGE, signature)).to.not.be.equal(this.signer.address);
|
||||
expect(await this.mock.$recover(WRONG_MESSAGE, signature)).to.not.be.equal(this.signer);
|
||||
});
|
||||
|
||||
it('reverts with invalid signature', async function () {
|
||||
@ -76,7 +72,6 @@ describe('ECDSA', function () {
|
||||
});
|
||||
|
||||
describe('with v=27 signature', function () {
|
||||
// Signature generated outside ganache with method web3.eth.sign(signer, message)
|
||||
const signer = '0x2cc1166f6212628A0deEf2B33BEFB2187D35b86c';
|
||||
// eslint-disable-next-line max-len
|
||||
const signatureWithoutV =
|
||||
@ -87,7 +82,7 @@ describe('ECDSA', function () {
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.equal(signer);
|
||||
|
||||
const { r, s, yParityAndS: vs } = toSignature(signature);
|
||||
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
||||
expect(await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s)).to.equal(
|
||||
signer,
|
||||
);
|
||||
@ -100,7 +95,7 @@ describe('ECDSA', function () {
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.not.equal(signer);
|
||||
|
||||
const { r, s, yParityAndS: vs } = toSignature(signature);
|
||||
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
||||
expect(
|
||||
await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
||||
).to.not.equal(signer);
|
||||
@ -118,7 +113,7 @@ describe('ECDSA', function () {
|
||||
'ECDSAInvalidSignature',
|
||||
);
|
||||
|
||||
const { r, s } = toSignature(signature);
|
||||
const { r, s } = ethers.Signature.from(signature);
|
||||
await expect(
|
||||
this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
||||
).to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignature');
|
||||
@ -128,7 +123,9 @@ describe('ECDSA', function () {
|
||||
it('rejects short EIP2098 format', async function () {
|
||||
const v = '0x1b'; // 27 = 1b.
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
await expect(this.mock.$recover(TEST_MESSAGE, toSignature(signature).compactSerialized))
|
||||
|
||||
const { compactSerialized } = ethers.Signature.from(signature);
|
||||
await expect(this.mock.$recover(TEST_MESSAGE, compactSerialized))
|
||||
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
||||
.withArgs(64);
|
||||
});
|
||||
@ -145,7 +142,7 @@ describe('ECDSA', function () {
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.equal(signer);
|
||||
|
||||
const { r, s, yParityAndS: vs } = toSignature(signature);
|
||||
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
||||
expect(await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s)).to.equal(
|
||||
signer,
|
||||
);
|
||||
@ -158,7 +155,7 @@ describe('ECDSA', function () {
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.not.equal(signer);
|
||||
|
||||
const { r, s, yParityAndS: vs } = toSignature(signature);
|
||||
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
||||
expect(
|
||||
await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
||||
).to.not.equal(signer);
|
||||
@ -176,7 +173,7 @@ describe('ECDSA', function () {
|
||||
'ECDSAInvalidSignature',
|
||||
);
|
||||
|
||||
const { r, s } = toSignature(signature);
|
||||
const { r, s } = ethers.Signature.from(signature);
|
||||
await expect(
|
||||
this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
||||
).to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignature');
|
||||
@ -184,9 +181,11 @@ describe('ECDSA', function () {
|
||||
});
|
||||
|
||||
it('rejects short EIP2098 format', async function () {
|
||||
const v = '0x1c'; // 27 = 1b.
|
||||
const v = '0x1b'; // 28 = 1b.
|
||||
const signature = ethers.concat([signatureWithoutV, v]);
|
||||
await expect(this.mock.$recover(TEST_MESSAGE, toSignature(signature).compactSerialized))
|
||||
|
||||
const { compactSerialized } = ethers.Signature.from(signature);
|
||||
await expect(this.mock.$recover(TEST_MESSAGE, compactSerialized))
|
||||
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
||||
.withArgs(64);
|
||||
});
|
||||
@ -208,7 +207,7 @@ describe('ECDSA', function () {
|
||||
await expect(this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s))
|
||||
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureS')
|
||||
.withArgs(s);
|
||||
expect(() => toSignature(highSSignature)).to.throw('non-canonical s');
|
||||
expect(() => ethers.Signature.from(highSSignature)).to.throw('non-canonical s');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,7 +4,6 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { getDomain, domainSeparator, hashTypedData } = require('../../helpers/eip712');
|
||||
const { formatType } = require('../../helpers/eip712-types');
|
||||
const { getChainId } = require('../../helpers/chainid');
|
||||
|
||||
const LENGTHS = {
|
||||
short: ['A Name', '1'],
|
||||
@ -21,7 +20,7 @@ const fixture = async () => {
|
||||
lengths[shortOrLong].domain = {
|
||||
name,
|
||||
version,
|
||||
chainId: await getChainId(),
|
||||
chainId: await ethers.provider.getNetwork().then(({ chainId }) => chainId),
|
||||
verifyingContract: lengths[shortOrLong].eip712.target,
|
||||
};
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ async function fixture() {
|
||||
};
|
||||
}
|
||||
|
||||
contract('ERC165', function () {
|
||||
describe('ERC165', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { expect } = require('chai');
|
||||
const { selector, interfaceId } = require('../../helpers/methods');
|
||||
const { interfaceId } = require('../../helpers/methods');
|
||||
const { mapValues } = require('../../helpers/iterate');
|
||||
|
||||
const INVALID_ID = '0xffffffff';
|
||||
@ -123,15 +123,6 @@ function shouldSupportInterfaces(interfaces = []) {
|
||||
|
||||
// Check the presence of each function in the contract's interface
|
||||
for (const fnSig of SIGNATURES[k]) {
|
||||
// TODO: Remove Truffle case when ethersjs migration is done
|
||||
if (this.contractUnderTest.abi) {
|
||||
const fnSelector = selector(fnSig);
|
||||
return expect(this.contractUnderTest.abi.filter(fn => fn.signature === fnSelector).length).to.equal(
|
||||
1,
|
||||
`did not find ${fnSig}`,
|
||||
);
|
||||
}
|
||||
|
||||
expect(this.contractUnderTest.interface.hasFunction(fnSig), `did not find ${fnSig}`).to.be.true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,10 +3,8 @@ const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');
|
||||
|
||||
const { Rounding } = require('../../helpers/enums');
|
||||
const { min, max } = require('../../helpers/math');
|
||||
const {
|
||||
bigint: { Rounding },
|
||||
} = require('../../helpers/enums.js');
|
||||
|
||||
const RoundingDown = [Rounding.Floor, Rounding.Trunc];
|
||||
const RoundingUp = [Rounding.Ceil, Rounding.Expand];
|
||||
|
||||
@ -9,7 +9,7 @@ async function fixture() {
|
||||
return { mock };
|
||||
}
|
||||
|
||||
contract('SafeCast', function () {
|
||||
describe('SafeCast', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
@ -14,7 +14,7 @@ async function fixture() {
|
||||
return { mock };
|
||||
}
|
||||
|
||||
contract('SignedMath', function () {
|
||||
describe('SignedMath', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@ const { ethers } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { VALUE_SIZES } = require('../../../scripts/generate/templates/Checkpoints.opts.js');
|
||||
const { VALUE_SIZES } = require('../../../scripts/generate/templates/Checkpoints.opts');
|
||||
|
||||
const last = array => (array.length ? array[array.length - 1] : undefined);
|
||||
|
||||
|
||||
@ -4,9 +4,7 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { product } = require('../../helpers/iterate');
|
||||
const { max } = require('../../helpers/math');
|
||||
const {
|
||||
bigint: { clock },
|
||||
} = require('../../helpers/time');
|
||||
const time = require('../../helpers/time');
|
||||
|
||||
const MAX_UINT32 = 1n << (32n - 1n);
|
||||
const MAX_UINT48 = 1n << (48n - 1n);
|
||||
@ -43,18 +41,18 @@ async function fixture() {
|
||||
return { mock };
|
||||
}
|
||||
|
||||
contract('Time', function () {
|
||||
describe('Time', function () {
|
||||
beforeEach(async function () {
|
||||
Object.assign(this, await loadFixture(fixture));
|
||||
});
|
||||
|
||||
describe('clocks', function () {
|
||||
it('timestamp', async function () {
|
||||
expect(await this.mock.$timestamp()).to.equal(await clock.timestamp());
|
||||
expect(await this.mock.$timestamp()).to.equal(await time.clock.timestamp());
|
||||
});
|
||||
|
||||
it('block number', async function () {
|
||||
expect(await this.mock.$blockNumber()).to.equal(await clock.blocknumber());
|
||||
expect(await this.mock.$blockNumber()).to.equal(await time.clock.blocknumber());
|
||||
});
|
||||
});
|
||||
|
||||
@ -92,7 +90,7 @@ contract('Time', function () {
|
||||
});
|
||||
|
||||
it('get & getFull', async function () {
|
||||
const timepoint = await clock.timestamp().then(BigInt);
|
||||
const timepoint = await time.clock.timestamp();
|
||||
const valueBefore = 24194n;
|
||||
const valueAfter = 4214143n;
|
||||
|
||||
@ -110,7 +108,7 @@ contract('Time', function () {
|
||||
});
|
||||
|
||||
it('withUpdate', async function () {
|
||||
const timepoint = await clock.timestamp().then(BigInt);
|
||||
const timepoint = await time.clock.timestamp();
|
||||
const valueBefore = 24194n;
|
||||
const valueAfter = 4214143n;
|
||||
const newvalueAfter = 94716n;
|
||||
|
||||
Reference in New Issue
Block a user