Skip to content

Commit

Permalink
improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Feb 6, 2025
1 parent 011b770 commit df061e7
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions test/account/paymaster/PaymasterERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,19 @@ describe('PaymasterERC20', function () {
.withArgs(this.account, 0n);

const { logs } = await txPromise.then(tx => tx.wait());
const actualAmount = this.paymaster.interface.parseLog(logs.find(ev => ev.address == this.paymaster.target))
.args[3];
const { tokenAmount } = this.paymaster.interface.parseLog(
logs.find(ev => ev.address == this.paymaster.target),
).args;
const { actualGasCost } = logs.find(ev => ev.fragment?.name == 'UserOperationEvent').args;
await expect(txPromise).to.changeTokenBalances(
this.token,
[this.account, this.paymaster],
[-actualAmount, actualAmount],
[-tokenAmount, tokenAmount],
);
// amount of ether transferred from entrypoint to receiver (deducted from paymaster's deposit) is approximately `actualAmount / 2`
await expect(txPromise).to.changeEtherBalances([entrypoint, this.receiver], [-actualGasCost, actualGasCost]);
expect(tokenAmount)
.to.be.greaterThan(actualGasCost * 2n)
.to.be.lessThan((actualGasCost * 2n * 110n) / 100n); // covers costs with no more than 10% overcost
});

it('from account, with guarantor refund', async function () {
Expand Down Expand Up @@ -190,14 +195,19 @@ describe('PaymasterERC20', function () {
.withArgs(this.account, 0n);

const { logs } = await txPromise.then(tx => tx.wait());
const actualAmount = this.paymaster.interface.parseLog(logs.find(ev => ev.address == this.paymaster.target))
.args[3];
const { tokenAmount } = this.paymaster.interface.parseLog(
logs.find(ev => ev.address == this.paymaster.target),
).args;
const { actualGasCost } = logs.find(ev => ev.fragment?.name == 'UserOperationEvent').args;
await expect(txPromise).to.changeTokenBalances(
this.token,
[this.account, this.guarantor, this.paymaster],
[value - actualAmount, 0n, actualAmount],
[value - tokenAmount, 0n, tokenAmount],
);
// amount of ether transferred from entrypoint to receiver (deducted from paymaster's deposit) is approximately `actualAmount / 2`
await expect(txPromise).to.changeEtherBalances([entrypoint, this.receiver], [-actualGasCost, actualGasCost]);
expect(tokenAmount)
.to.be.greaterThan(actualGasCost * 2n)
.to.be.lessThan((actualGasCost * 2n * 110n) / 100n); // covers costs with no more than 10% overcost
});

it('from guarantor, when account fails to pay', async function () {
Expand Down Expand Up @@ -236,14 +246,19 @@ describe('PaymasterERC20', function () {
.withArgs(this.account, 0n);

const { logs } = await txPromise.then(tx => tx.wait());
const actualAmount = this.paymaster.interface.parseLog(logs.find(ev => ev.address == this.paymaster.target))
.args[3];
const { tokenAmount } = this.paymaster.interface.parseLog(
logs.find(ev => ev.address == this.paymaster.target),
).args;
const { actualGasCost } = logs.find(ev => ev.fragment?.name == 'UserOperationEvent').args;
await expect(txPromise).to.changeTokenBalances(
this.token,
[this.account, this.guarantor, this.paymaster],
[0n, -actualAmount, actualAmount],
[0n, -tokenAmount, tokenAmount],
);
// amount of ether transferred from entrypoint to receiver (deducted from paymaster's deposit) is approximately `actualAmount / 2`
await expect(txPromise).to.changeEtherBalances([entrypoint, this.receiver], [-actualGasCost, actualGasCost]);
expect(tokenAmount)
.to.be.greaterThan(actualGasCost * 2n)
.to.be.lessThan((actualGasCost * 2n * 110n) / 100n); // covers costs with no more than 10% overcost
});
});

Expand Down

0 comments on commit df061e7

Please sign in to comment.