Skip to content
28 changes: 9 additions & 19 deletions test/metatx/ERC2771Context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function fixture() {
const context = await ethers.deployContract('ERC2771ContextMock', [forwarder]);
const domain = await getDomain(forwarder);
const types = { ForwardRequest };

return { sender, other, forwarder, forwarderAsSigner, context, domain, types };
}

Expand All @@ -42,7 +42,6 @@ describe('ERC2771Context', function () {
it('returns the relayed transaction original sender', async function () {
const nonce = await this.forwarder.nonces(this.sender);
const data = this.context.interface.encodeFunctionData('msgSender');

const req = {
from: await this.sender.getAddress(),
to: await this.context.getAddress(),
Expand All @@ -52,11 +51,9 @@ describe('ERC2771Context', function () {
nonce,
deadline: MAX_UINT48,
};

req.signature = await this.sender.signTypedData(this.domain, this.types, req);

expect(await this.forwarder.verify(req)).to.be.true;


await expect(this.forwarder.verify(req)).to.eventually.be.true;
await expect(this.forwarder.execute(req)).to.emit(this.context, 'Sender').withArgs(this.sender);
});

Expand All @@ -71,10 +68,8 @@ describe('ERC2771Context', function () {
describe('msgData', function () {
it('returns the relayed transaction original data', async function () {
const args = [42n, 'OpenZeppelin'];

const nonce = await this.forwarder.nonces(this.sender);
const data = this.context.interface.encodeFunctionData('msgData', args);

const req = {
from: await this.sender.getAddress(),
to: await this.context.getAddress(),
Expand All @@ -84,11 +79,9 @@ describe('ERC2771Context', function () {
nonce,
deadline: MAX_UINT48,
};

req.signature = this.sender.signTypedData(this.domain, this.types, req);

expect(await this.forwarder.verify(req)).to.be.true;

req.signature = await this.sender.signTypedData(this.domain, this.types, req);

await expect(this.forwarder.verify(req)).to.eventually.be.true;
await expect(this.forwarder.execute(req))
.to.emit(this.context, 'Data')
.withArgs(data, ...args);
Expand All @@ -99,7 +92,7 @@ describe('ERC2771Context', function () {
const data = this.context.interface.encodeFunctionData('msgDataShort');

// The forwarder doesn't produce calls with calldata length less than 20 bytes so `this.forwarderAsSigner` is used instead.
await expect(await this.context.connect(this.forwarderAsSigner).msgDataShort())
await expect(this.context.connect(this.forwarderAsSigner).msgDataShort())
.to.emit(this.context, 'DataShort')
.withArgs(data);
});
Expand All @@ -109,11 +102,10 @@ describe('ERC2771Context', function () {
const nonce = await this.forwarder.nonces(this.sender);
const data = this.context.interface.encodeFunctionData('multicall', [
[
// poisonned call to 'msgSender()'
// poisoned call to 'msgSender()'
ethers.concat([this.context.interface.encodeFunctionData('msgSender'), this.other.address]),
],
]);

const req = {
from: await this.sender.getAddress(),
to: await this.context.getAddress(),
Expand All @@ -123,11 +115,9 @@ describe('ERC2771Context', function () {
nonce,
deadline: MAX_UINT48,
};

req.signature = await this.sender.signTypedData(this.domain, this.types, req);

expect(await this.forwarder.verify(req)).to.be.true;

await expect(this.forwarder.verify(req)).to.eventually.be.true;
await expect(this.forwarder.execute(req)).to.emit(this.context, 'Sender').withArgs(this.sender);
});
});
Loading