Replace revert strings with custom errors (#4261)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Ernesto García
2023-06-12 17:41:52 -06:00
committed by GitHub
parent 08fd777f6d
commit b425a72240
138 changed files with 3220 additions and 1287 deletions

View File

@ -1,4 +1,5 @@
const expectEvent = require('@openzeppelin/test-helpers/src/expectEvent');
const { expectRevertCustomError } = require('../helpers/customError');
require('@openzeppelin/test-helpers');
@ -15,22 +16,57 @@ contract('Nonces', function (accounts) {
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
});
it('increment a nonce', async function () {
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
describe('_useNonce', function () {
it('increments a nonce', async function () {
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
const { receipt } = await this.nonces.$_useNonce(sender);
expectEvent(receipt, 'return$_useNonce', ['0']);
const { receipt } = await this.nonces.$_useNonce(sender);
expectEvent(receipt, 'return$_useNonce', ['0']);
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
});
it("increments only sender's nonce", async function () {
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
await this.nonces.$_useNonce(sender);
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
});
});
it('nonce is specific to address argument', async function () {
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('0');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
describe('_useCheckedNonce', function () {
it('increments a nonce', async function () {
const currentNonce = await this.nonces.nonces(sender);
expect(currentNonce).to.be.bignumber.equal('0');
await this.nonces.$_useNonce(sender);
const { receipt } = await this.nonces.$_useCheckedNonce(sender, currentNonce);
expectEvent(receipt, 'return$_useCheckedNonce', [currentNonce]);
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
});
it("increments only sender's nonce", async function () {
const currentNonce = await this.nonces.nonces(sender);
expect(currentNonce).to.be.bignumber.equal('0');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
await this.nonces.$_useCheckedNonce(sender, currentNonce);
expect(await this.nonces.nonces(sender)).to.be.bignumber.equal('1');
expect(await this.nonces.nonces(other)).to.be.bignumber.equal('0');
});
it('reverts when nonce is not the expected', async function () {
const currentNonce = await this.nonces.nonces(sender);
await expectRevertCustomError(
this.nonces.$_useCheckedNonce(sender, currentNonce.addn(1)),
'InvalidAccountNonce',
[sender, currentNonce],
);
});
});
});