Await `.eventually` test matchers (#5408)

pull/5409/head^2
Ernesto García 1 month ago committed by GitHub
parent dd04dfe75d
commit 4c3ef87cf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 86
      test/account/utils/draft-ERC4337Utils.test.js
  2. 59
      test/account/utils/draft-ERC7579Utils.test.js
  3. 24
      test/governance/extensions/GovernorSequentialProposalId.test.js
  4. 50
      test/utils/Nonces.behavior.js

@ -27,7 +27,7 @@ describe('ERC4337Utils', function () {
const validAfter = 0x9abcdef0n;
const validationData = packValidationData(validAfter, validUntil, authorizer);
expect(this.utils.$parseValidationData(validationData)).to.eventually.deep.equal([
await expect(this.utils.$parseValidationData(validationData)).to.eventually.deep.equal([
authorizer.address,
validAfter,
validUntil,
@ -39,7 +39,7 @@ describe('ERC4337Utils', function () {
const validAfter = 0x12345678n;
const validationData = packValidationData(validAfter, 0, authorizer);
expect(this.utils.$parseValidationData(validationData)).to.eventually.deep.equal([
await expect(this.utils.$parseValidationData(validationData)).to.eventually.deep.equal([
authorizer.address,
validAfter,
MAX_UINT48,
@ -47,13 +47,13 @@ describe('ERC4337Utils', function () {
});
it('parse canonical values', async function () {
expect(this.utils.$parseValidationData(this.SIG_VALIDATION_SUCCESS)).to.eventually.deep.equal([
await expect(this.utils.$parseValidationData(this.SIG_VALIDATION_SUCCESS)).to.eventually.deep.equal([
ethers.ZeroAddress,
0n,
MAX_UINT48,
]);
expect(this.utils.$parseValidationData(this.SIG_VALIDATION_FAILED)).to.eventually.deep.equal([
await expect(this.utils.$parseValidationData(this.SIG_VALIDATION_FAILED)).to.eventually.deep.equal([
ADDRESS_ONE,
0n,
MAX_UINT48,
@ -68,7 +68,7 @@ describe('ERC4337Utils', function () {
const validAfter = 0x9abcdef0n;
const validationData = packValidationData(validAfter, validUntil, authorizer);
expect(
await expect(
this.utils.$packValidationData(ethers.Typed.address(authorizer), validAfter, validUntil),
).to.eventually.equal(validationData);
});
@ -79,22 +79,22 @@ describe('ERC4337Utils', function () {
const validAfter = 0x9abcdef0n;
const validationData = packValidationData(validAfter, validUntil, false);
expect(this.utils.$packValidationData(ethers.Typed.bool(success), validAfter, validUntil)).to.eventually.equal(
validationData,
);
await expect(
this.utils.$packValidationData(ethers.Typed.bool(success), validAfter, validUntil),
).to.eventually.equal(validationData);
});
it('packing reproduced canonical values', async function () {
expect(this.utils.$packValidationData(ethers.Typed.address(ethers.ZeroAddress), 0n, 0n)).to.eventually.equal(
this.SIG_VALIDATION_SUCCESS,
);
expect(this.utils.$packValidationData(ethers.Typed.bool(true), 0n, 0n)).to.eventually.equal(
await expect(
this.utils.$packValidationData(ethers.Typed.address(ethers.ZeroAddress), 0n, 0n),
).to.eventually.equal(this.SIG_VALIDATION_SUCCESS);
await expect(this.utils.$packValidationData(ethers.Typed.bool(true), 0n, 0n)).to.eventually.equal(
this.SIG_VALIDATION_SUCCESS,
);
expect(this.utils.$packValidationData(ethers.Typed.address(ADDRESS_ONE), 0n, 0n)).to.eventually.equal(
await expect(this.utils.$packValidationData(ethers.Typed.address(ADDRESS_ONE), 0n, 0n)).to.eventually.equal(
this.SIG_VALIDATION_FAILED,
);
expect(this.utils.$packValidationData(ethers.Typed.bool(false), 0n, 0n)).to.eventually.equal(
await expect(this.utils.$packValidationData(ethers.Typed.bool(false), 0n, 0n)).to.eventually.equal(
this.SIG_VALIDATION_FAILED,
);
});
@ -112,8 +112,8 @@ describe('ERC4337Utils', function () {
const expected = packValidationData(validAfter2, validUntil1, true);
// check symmetry
expect(this.utils.$combineValidationData(validationData1, validationData2)).to.eventually.equal(expected);
expect(this.utils.$combineValidationData(validationData2, validationData1)).to.eventually.equal(expected);
await expect(this.utils.$combineValidationData(validationData1, validationData2)).to.eventually.equal(expected);
await expect(this.utils.$combineValidationData(validationData2, validationData1)).to.eventually.equal(expected);
});
for (const [authorizer1, authorizer2] of [
@ -126,8 +126,8 @@ describe('ERC4337Utils', function () {
const expected = packValidationData(validAfter2, validUntil1, false);
// check symmetry
expect(this.utils.$combineValidationData(validationData1, validationData2)).to.eventually.equal(expected);
expect(this.utils.$combineValidationData(validationData2, validationData1)).to.eventually.equal(expected);
await expect(this.utils.$combineValidationData(validationData1, validationData2)).to.eventually.equal(expected);
await expect(this.utils.$combineValidationData(validationData2, validationData1)).to.eventually.equal(expected);
});
}
});
@ -139,7 +139,7 @@ describe('ERC4337Utils', function () {
const validUntil = MAX_UINT48;
const validationData = packValidationData(validAfter, validUntil, aggregator);
expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, false]);
await expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, false]);
});
it('returns the validation data with invalid validity range (expired)', async function () {
@ -148,7 +148,7 @@ describe('ERC4337Utils', function () {
const validUntil = 1;
const validationData = packValidationData(validAfter, validUntil, aggregator);
expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, true]);
await expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, true]);
});
it('returns the validation data with invalid validity range (not yet valid)', async function () {
@ -157,11 +157,11 @@ describe('ERC4337Utils', function () {
const validUntil = MAX_UINT48;
const validationData = packValidationData(validAfter, validUntil, aggregator);
expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, true]);
await expect(this.utils.$getValidationData(validationData)).to.eventually.deep.equal([aggregator.address, true]);
});
it('returns address(0) and false for validationData = 0', function () {
expect(this.utils.$getValidationData(0n)).to.eventually.deep.equal([ethers.ZeroAddress, false]);
it('returns address(0) and false for validationData = 0', async function () {
await expect(this.utils.$getValidationData(0n)).to.eventually.deep.equal([ethers.ZeroAddress, false]);
});
});
@ -172,13 +172,13 @@ describe('ERC4337Utils', function () {
const otherChainId = 0xdeadbeef;
// check that helper matches entrypoint logic
expect(entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(entrypoint, chainId));
await expect(entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(entrypoint, chainId));
// check library against helper
expect(this.utils.$hash(userOp.packed, entrypoint, chainId)).to.eventually.equal(
await expect(this.utils.$hash(userOp.packed, entrypoint, chainId)).to.eventually.equal(
userOp.hash(entrypoint, chainId),
);
expect(this.utils.$hash(userOp.packed, entrypoint, otherChainId)).to.eventually.equal(
await expect(this.utils.$hash(userOp.packed, entrypoint, otherChainId)).to.eventually.equal(
userOp.hash(entrypoint, otherChainId),
);
});
@ -202,34 +202,34 @@ describe('ERC4337Utils', function () {
});
it('returns factory', async function () {
expect(this.utils.$factory(this.userOp.packed)).to.eventually.equal(this.factory);
expect(this.utils.$factory(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
await expect(this.utils.$factory(this.userOp.packed)).to.eventually.equal(this.factory);
await expect(this.utils.$factory(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
});
it('returns factoryData', async function () {
expect(this.utils.$factoryData(this.userOp.packed)).to.eventually.equal('0x123456');
expect(this.utils.$factoryData(this.emptyUserOp.packed)).to.eventually.equal('0x');
await expect(this.utils.$factoryData(this.userOp.packed)).to.eventually.equal('0x123456');
await expect(this.utils.$factoryData(this.emptyUserOp.packed)).to.eventually.equal('0x');
});
});
it('returns verificationGasLimit', async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1, verificationGas: 0x12345678n });
expect(this.utils.$verificationGasLimit(userOp.packed)).to.eventually.equal(userOp.verificationGas);
await expect(this.utils.$verificationGasLimit(userOp.packed)).to.eventually.equal(userOp.verificationGas);
});
it('returns callGasLimit', async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1, callGas: 0x12345678n });
expect(this.utils.$callGasLimit(userOp.packed)).to.eventually.equal(userOp.callGas);
await expect(this.utils.$callGasLimit(userOp.packed)).to.eventually.equal(userOp.callGas);
});
it('returns maxPriorityFeePerGas', async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1, maxPriorityFee: 0x12345678n });
expect(this.utils.$maxPriorityFeePerGas(userOp.packed)).to.eventually.equal(userOp.maxPriorityFee);
await expect(this.utils.$maxPriorityFeePerGas(userOp.packed)).to.eventually.equal(userOp.maxPriorityFee);
});
it('returns maxFeePerGas', async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1, maxFeePerGas: 0x12345678n });
expect(this.utils.$maxFeePerGas(userOp.packed)).to.eventually.equal(userOp.maxFeePerGas);
await expect(this.utils.$maxFeePerGas(userOp.packed)).to.eventually.equal(userOp.maxFeePerGas);
});
it('returns gasPrice', async function () {
@ -239,7 +239,7 @@ describe('ERC4337Utils', function () {
maxPriorityFee: 0x12345678n,
maxFeePerGas: 0x87654321n,
});
expect(this.utils.$gasPrice(userOp.packed)).to.eventually.equal(userOp.maxPriorityFee);
await expect(this.utils.$gasPrice(userOp.packed)).to.eventually.equal(userOp.maxPriorityFee);
});
describe('paymasterAndData', function () {
@ -260,27 +260,27 @@ describe('ERC4337Utils', function () {
});
it('returns paymaster', async function () {
expect(this.utils.$paymaster(this.userOp.packed)).to.eventually.equal(this.userOp.paymaster);
expect(this.utils.$paymaster(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
await expect(this.utils.$paymaster(this.userOp.packed)).to.eventually.equal(this.userOp.paymaster);
await expect(this.utils.$paymaster(this.emptyUserOp.packed)).to.eventually.equal(ethers.ZeroAddress);
});
it('returns verificationGasLimit', async function () {
expect(this.utils.$paymasterVerificationGasLimit(this.userOp.packed)).to.eventually.equal(
await expect(this.utils.$paymasterVerificationGasLimit(this.userOp.packed)).to.eventually.equal(
this.userOp.paymasterVerificationGasLimit,
);
expect(this.utils.$paymasterVerificationGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
await expect(this.utils.$paymasterVerificationGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
});
it('returns postOpGasLimit', async function () {
expect(this.utils.$paymasterPostOpGasLimit(this.userOp.packed)).to.eventually.equal(
await expect(this.utils.$paymasterPostOpGasLimit(this.userOp.packed)).to.eventually.equal(
this.userOp.paymasterPostOpGasLimit,
);
expect(this.utils.$paymasterPostOpGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
await expect(this.utils.$paymasterPostOpGasLimit(this.emptyUserOp.packed)).to.eventually.equal(0n);
});
it('returns data', async function () {
expect(this.utils.$paymasterData(this.userOp.packed)).to.eventually.equal(this.userOp.paymasterData);
expect(this.utils.$paymasterData(this.emptyUserOp.packed)).to.eventually.equal('0x');
await expect(this.utils.$paymasterData(this.userOp.packed)).to.eventually.equal(this.userOp.paymasterData);
await expect(this.utils.$paymasterData(this.emptyUserOp.packed)).to.eventually.equal('0x');
});
});
});

@ -36,7 +36,7 @@ describe('ERC7579Utils', function () {
await expect(this.utils.$execSingle(data, EXEC_TYPE_DEFAULT)).to.emit(this.target, 'MockFunctionCalled');
expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value);
await expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value);
});
it('calls the target with value and args', async function () {
@ -51,7 +51,7 @@ describe('ERC7579Utils', function () {
.to.emit(this.target, 'MockFunctionCalledWithArgs')
.withArgs(42, '0x1234');
expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value);
await expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value);
});
it('reverts when target reverts in default ExecType', async function () {
@ -107,8 +107,8 @@ describe('ERC7579Utils', function () {
.to.emit(this.target, 'MockFunctionCalled')
.to.emit(this.anotherTarget, 'MockFunctionCalled');
expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(value2);
await expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
await expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(value2);
});
it('calls the targets with value and args', async function () {
@ -127,8 +127,8 @@ describe('ERC7579Utils', function () {
.to.emit(this.target, 'MockFunctionCalledWithArgs')
.to.emit(this.anotherTarget, 'MockFunctionCalledWithArgs');
expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(value2);
await expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
await expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(value2);
});
it('reverts when any target reverts in default ExecType', async function () {
@ -161,8 +161,8 @@ describe('ERC7579Utils', function () {
);
// Check balances
expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(0);
await expect(ethers.provider.getBalance(this.target)).to.eventually.equal(value1);
await expect(ethers.provider.getBalance(this.anotherTarget)).to.eventually.equal(0);
});
it('reverts with an invalid exec type', async function () {
@ -188,9 +188,9 @@ describe('ERC7579Utils', function () {
this.target.interface.encodeFunctionData('mockFunctionWritesStorage', [slot, value]),
);
expect(ethers.provider.getStorage(this.utils.target, slot)).to.eventually.equal(ethers.ZeroHash);
await expect(ethers.provider.getStorage(this.utils.target, slot)).to.eventually.equal(ethers.ZeroHash);
await this.utils.$execDelegateCall(data, EXEC_TYPE_DEFAULT);
expect(ethers.provider.getStorage(this.utils.target, slot)).to.eventually.equal(value);
await expect(ethers.provider.getStorage(this.utils.target, slot)).to.eventually.equal(value);
});
it('reverts when target reverts in default ExecType', async function () {
@ -227,7 +227,7 @@ describe('ERC7579Utils', function () {
const selector = '0x12345678';
const payload = ethers.toBeHex(0, 22);
expect(this.utils.$encodeMode(callType, execType, selector, payload)).to.eventually.equal(
await expect(this.utils.$encodeMode(callType, execType, selector, payload)).to.eventually.equal(
encodeMode({
callType,
execType,
@ -243,7 +243,7 @@ describe('ERC7579Utils', function () {
const selector = '0x12345678';
const payload = ethers.toBeHex(0, 22);
expect(
await expect(
this.utils.$decodeMode(
encodeMode({
callType,
@ -260,7 +260,7 @@ describe('ERC7579Utils', function () {
const value = 0x123;
const data = '0x12345678';
expect(this.utils.$encodeSingle(target, value, data)).to.eventually.equal(encodeSingle(target, value, data));
await expect(this.utils.$encodeSingle(target, value, data)).to.eventually.equal(encodeSingle(target, value, data));
});
it('decodes single', async function () {
@ -268,7 +268,7 @@ describe('ERC7579Utils', function () {
const value = 0x123;
const data = '0x12345678';
expect(this.utils.$decodeSingle(encodeSingle(target, value, data))).to.eventually.deep.equal([
await expect(this.utils.$decodeSingle(encodeSingle(target, value, data))).to.eventually.deep.equal([
target.target,
value,
data,
@ -281,7 +281,7 @@ describe('ERC7579Utils', function () {
[this.anotherTarget, 0x456, '0x12345678'],
];
expect(this.utils.$encodeBatch(entries)).to.eventually.equal(encodeBatch(...entries));
await expect(this.utils.$encodeBatch(entries)).to.eventually.equal(encodeBatch(...entries));
});
it('decodes batch', async function () {
@ -290,63 +290,66 @@ describe('ERC7579Utils', function () {
[this.anotherTarget.target, 0x456, '0x12345678'],
];
expect(this.utils.$decodeBatch(encodeBatch(...entries))).to.eventually.deep.equal(entries);
await expect(this.utils.$decodeBatch(encodeBatch(...entries))).to.eventually.deep.equal(entries);
});
it('encodes delegate', async function () {
const target = this.target;
const data = '0x12345678';
expect(this.utils.$encodeDelegate(target, data)).to.eventually.equal(encodeDelegate(target, data));
await expect(this.utils.$encodeDelegate(target, data)).to.eventually.equal(encodeDelegate(target, data));
});
it('decodes delegate', async function () {
const target = this.target;
const data = '0x12345678';
expect(this.utils.$decodeDelegate(encodeDelegate(target, data))).to.eventually.deep.equal([target.target, data]);
await expect(this.utils.$decodeDelegate(encodeDelegate(target, data))).to.eventually.deep.equal([
target.target,
data,
]);
});
describe('global', function () {
describe('eqCallTypeGlobal', function () {
it('returns true if both call types are equal', async function () {
expect(this.utilsGlobal.$eqCallTypeGlobal(CALL_TYPE_BATCH, CALL_TYPE_BATCH)).to.eventually.be.true;
await expect(this.utilsGlobal.$eqCallTypeGlobal(CALL_TYPE_BATCH, CALL_TYPE_BATCH)).to.eventually.be.true;
});
it('returns false if both call types are different', async function () {
expect(this.utilsGlobal.$eqCallTypeGlobal(CALL_TYPE_CALL, CALL_TYPE_BATCH)).to.eventually.be.false;
await expect(this.utilsGlobal.$eqCallTypeGlobal(CALL_TYPE_CALL, CALL_TYPE_BATCH)).to.eventually.be.false;
});
});
describe('eqExecTypeGlobal', function () {
it('returns true if both exec types are equal', async function () {
expect(this.utilsGlobal.$eqExecTypeGlobal(EXEC_TYPE_TRY, EXEC_TYPE_TRY)).to.eventually.be.true;
await expect(this.utilsGlobal.$eqExecTypeGlobal(EXEC_TYPE_TRY, EXEC_TYPE_TRY)).to.eventually.be.true;
});
it('returns false if both exec types are different', async function () {
expect(this.utilsGlobal.$eqExecTypeGlobal(EXEC_TYPE_DEFAULT, EXEC_TYPE_TRY)).to.eventually.be.false;
await expect(this.utilsGlobal.$eqExecTypeGlobal(EXEC_TYPE_DEFAULT, EXEC_TYPE_TRY)).to.eventually.be.false;
});
});
describe('eqModeSelectorGlobal', function () {
it('returns true if both selectors are equal', async function () {
expect(this.utilsGlobal.$eqModeSelectorGlobal('0x12345678', '0x12345678')).to.eventually.be.true;
await expect(this.utilsGlobal.$eqModeSelectorGlobal('0x12345678', '0x12345678')).to.eventually.be.true;
});
it('returns false if both selectors are different', async function () {
expect(this.utilsGlobal.$eqModeSelectorGlobal('0x12345678', '0x87654321')).to.eventually.be.false;
await expect(this.utilsGlobal.$eqModeSelectorGlobal('0x12345678', '0x87654321')).to.eventually.be.false;
});
});
describe('eqModePayloadGlobal', function () {
it('returns true if both payloads are equal', async function () {
expect(this.utilsGlobal.$eqModePayloadGlobal(ethers.toBeHex(0, 22), ethers.toBeHex(0, 22))).to.eventually.be
.true;
await expect(this.utilsGlobal.$eqModePayloadGlobal(ethers.toBeHex(0, 22), ethers.toBeHex(0, 22))).to.eventually
.be.true;
});
it('returns false if both payloads are different', async function () {
expect(this.utilsGlobal.$eqModePayloadGlobal(ethers.toBeHex(0, 22), ethers.toBeHex(1, 22))).to.eventually.be
.false;
await expect(this.utilsGlobal.$eqModePayloadGlobal(ethers.toBeHex(0, 22), ethers.toBeHex(1, 22))).to.eventually
.be.false;
});
});
});

@ -93,12 +93,12 @@ describe('GovernorSequentialProposalId', function () {
for (const i of iterate.range(1, 10)) {
this.proposal.description = `<proposal description #${i}>`;
expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.getProposalId(...this.proposal.shortProposal)).revertedWithCustomError(
this.mock,
'GovernorNonexistentProposal',
);
expect(this.mock.latestProposalId()).to.eventually.equal(i - 1);
await expect(this.mock.latestProposalId()).to.eventually.equal(i - 1);
await expect(this.helper.connect(this.proposer).propose())
.to.emit(this.mock, 'ProposalCreated')
@ -114,9 +114,9 @@ describe('GovernorSequentialProposalId', function () {
this.proposal.description,
);
expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
expect(this.mock.getProposalId(...this.proposal.shortProposal)).to.eventually.equal(i);
expect(this.mock.latestProposalId()).to.eventually.equal(i);
await expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.getProposalId(...this.proposal.shortProposal)).to.eventually.equal(i);
await expect(this.mock.latestProposalId()).to.eventually.equal(i);
}
});
@ -127,12 +127,12 @@ describe('GovernorSequentialProposalId', function () {
for (const i of iterate.range(offset + 1, offset + 10)) {
this.proposal.description = `<proposal description #${i}>`;
expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.getProposalId(...this.proposal.shortProposal)).revertedWithCustomError(
this.mock,
'GovernorNonexistentProposal',
);
expect(this.mock.latestProposalId()).to.eventually.equal(i - 1);
await expect(this.mock.latestProposalId()).to.eventually.equal(i - 1);
await expect(this.helper.connect(this.proposer).propose())
.to.emit(this.mock, 'ProposalCreated')
@ -148,15 +148,15 @@ describe('GovernorSequentialProposalId', function () {
this.proposal.description,
);
expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
expect(this.mock.getProposalId(...this.proposal.shortProposal)).to.eventually.equal(i);
expect(this.mock.latestProposalId()).to.eventually.equal(i);
await expect(this.mock.hashProposal(...this.proposal.shortProposal)).to.eventually.equal(this.proposal.hash);
await expect(this.mock.getProposalId(...this.proposal.shortProposal)).to.eventually.equal(i);
await expect(this.mock.latestProposalId()).to.eventually.equal(i);
}
});
it('can only initialize latest proposal id from 0', async function () {
await this.helper.propose();
expect(this.mock.latestProposalId()).to.eventually.equal(1);
await expect(this.mock.latestProposalId()).to.eventually.equal(1);
await expect(this.mock.$_initializeLatestProposalId(2)).to.be.revertedWithCustomError(
this.mock,
'GovernorAlreadyInitializedLatestProposalId',
@ -192,7 +192,7 @@ describe('GovernorSequentialProposalId', function () {
await this.helper.waitForDeadline();
expect(this.helper.execute())
await expect(this.helper.execute())
.to.eventually.emit(this.mock, 'ProposalExecuted')
.withArgs(1)
.emit(this.receiver, 'MockFunctionCalled');

@ -20,39 +20,39 @@ function shouldBehaveLikeNonces() {
await expect(this.mock.$_useNonce(sender)).to.emit(this.mock, eventName).withArgs(0n);
expect(this.mock.nonces(sender)).to.eventually.equal(1n);
await expect(this.mock.nonces(sender)).to.eventually.equal(1n);
});
it("increments only sender's nonce", async function () {
expect(this.mock.nonces(sender)).to.eventually.equal(0n);
expect(this.mock.nonces(other)).to.eventually.equal(0n);
await expect(this.mock.nonces(sender)).to.eventually.equal(0n);
await expect(this.mock.nonces(other)).to.eventually.equal(0n);
await this.mock.$_useNonce(sender);
expect(this.mock.nonces(sender)).to.eventually.equal(1n);
expect(this.mock.nonces(other)).to.eventually.equal(0n);
await expect(this.mock.nonces(sender)).to.eventually.equal(1n);
await expect(this.mock.nonces(other)).to.eventually.equal(0n);
});
});
describe('_useCheckedNonce', function () {
it('increments a nonce', async function () {
// current nonce is 0n
expect(this.mock.nonces(sender)).to.eventually.equal(0n);
await expect(this.mock.nonces(sender)).to.eventually.equal(0n);
await this.mock.$_useCheckedNonce(sender, 0n);
expect(this.mock.nonces(sender)).to.eventually.equal(1n);
await expect(this.mock.nonces(sender)).to.eventually.equal(1n);
});
it("increments only sender's nonce", async function () {
// current nonce is 0n
expect(this.mock.nonces(sender)).to.eventually.equal(0n);
expect(this.mock.nonces(other)).to.eventually.equal(0n);
await expect(this.mock.nonces(sender)).to.eventually.equal(0n);
await expect(this.mock.nonces(other)).to.eventually.equal(0n);
await this.mock.$_useCheckedNonce(sender, 0n);
expect(this.mock.nonces(sender)).to.eventually.equal(1n);
expect(this.mock.nonces(other)).to.eventually.equal(0n);
await expect(this.mock.nonces(sender)).to.eventually.equal(1n);
await expect(this.mock.nonces(other)).to.eventually.equal(0n);
});
it('reverts when nonce is not the expected', async function () {
@ -73,14 +73,14 @@ function shouldBehaveLikeNoncesKeyed() {
const keyOffset = key => key << 64n;
it('gets a nonce', async function () {
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
});
describe('_useNonce', function () {
it('default variant uses key 0', async function () {
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.$_useNonce(sender)).to.emit(this.mock, 'return$_useNonce_address').withArgs(0n);
@ -88,13 +88,13 @@ function shouldBehaveLikeNoncesKeyed() {
.to.emit(this.mock, 'return$_useNonce_address_uint192')
.withArgs(keyOffset(0n) + 1n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 2n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 2n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
});
it('use nonce at another key', async function () {
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 0n);
await expect(this.mock.$_useNonce(sender, ethers.Typed.uint192(17n)))
.to.emit(this.mock, 'return$_useNonce_address_uint192')
@ -104,8 +104,8 @@ function shouldBehaveLikeNoncesKeyed() {
.to.emit(this.mock, 'return$_useNonce_address_uint192')
.withArgs(keyOffset(17n) + 1n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 2n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(keyOffset(0n) + 0n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(keyOffset(17n) + 2n);
});
});
@ -115,7 +115,7 @@ function shouldBehaveLikeNoncesKeyed() {
await this.mock.$_useCheckedNonce(sender, currentNonce);
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(currentNonce + 1n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(currentNonce + 1n);
});
it('use nonce at another key', async function () {
@ -123,7 +123,7 @@ function shouldBehaveLikeNoncesKeyed() {
await this.mock.$_useCheckedNonce(sender, currentNonce);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(currentNonce + 1n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(currentNonce + 1n);
});
it('reverts when nonce is not the expected', async function () {
@ -152,7 +152,7 @@ function shouldBehaveLikeNoncesKeyed() {
await this.mock.$_useCheckedNonce(sender, ethers.Typed.uint192(0n), currentNonce);
expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(currentNonce + 1n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(0n))).to.eventually.equal(currentNonce + 1n);
});
it('use nonce at another key', async function () {
@ -160,7 +160,7 @@ function shouldBehaveLikeNoncesKeyed() {
await this.mock.$_useCheckedNonce(sender, ethers.Typed.uint192(17n), currentNonce & MASK);
expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(currentNonce + 1n);
await expect(this.mock.nonces(sender, ethers.Typed.uint192(17n))).to.eventually.equal(currentNonce + 1n);
});
it('reverts when nonce is not the expected', async function () {

Loading…
Cancel
Save