Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Fix gas estimations for value transfers at the limit
Browse files Browse the repository at this point in the history
  • Loading branch information
hazim-j committed Apr 18, 2024
1 parent f2c7f27 commit 6500b8b
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions e2e/test/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,55 @@ describe("During the execution phase", () => {
expect(event?.args.success).toBe(true);
});

describe("With transfer amounts more than sender balance", () => {
test("Sender cannot create a UserOperation by default", async () => {
expect.assertions(1);
try {
const balance = await provider.getBalance(acc.getSender());
const response = await client.sendUserOperation(
acc.execute(acc.getSender(), balance.mul(2), "0x")
);
await response.wait();
} catch (error: any) {
expect(error?.error.code).toBe(errorCodes.executionReverted);
}
describe("With transfer amounts at the limit of sender balance", () => {
describe("Equal to sender balance", () => {
describe("No EntryPoint deposits", () => {
test("Sender cannot create a UserOperation by default", async () => {
expect.assertions(1);
try {
// TODO: ensure no deposits for this sender in EP.
const balance = await provider.getBalance(acc.getSender());
const response = await client.sendUserOperation(
acc.execute(acc.getSender(), balance, "0x")
);
await response.wait();
} catch (error: any) {
expect(error?.error.code).toBe(errorCodes.executionReverted);
}
});
});
});

test("Sender can cause a failed UserOperation with state overrides", async () => {
const balance = await provider.getBalance(acc.getSender());
const response = await client.sendUserOperation(
acc.execute(acc.getSender(), balance.mul(2), "0x"),
{
stateOverrides: {
[acc.getSender()]: {
balance: balance.mul(3).toHexString(),
},
},
describe("More than sender balance", () => {
test("Sender cannot create a UserOperation by default", async () => {
expect.assertions(1);
try {
const balance = await provider.getBalance(acc.getSender());
const response = await client.sendUserOperation(
acc.execute(acc.getSender(), balance.mul(2), "0x")
);
await response.wait();
} catch (error: any) {
expect(error?.error.code).toBe(errorCodes.executionReverted);
}
);
const event = await response.wait();
});

test("Sender can cause a failed UserOperation with state overrides", async () => {
const balance = await provider.getBalance(acc.getSender());
const response = await client.sendUserOperation(
acc.execute(acc.getSender(), balance.mul(2), "0x"),
{
stateOverrides: {
[acc.getSender()]: {
balance: balance.mul(3).toHexString(),
},
},
}
);
const event = await response.wait();

expect(event?.args.success).toBe(false);
expect(event?.args.success).toBe(false);
});
});
});

Expand Down

0 comments on commit 6500b8b

Please sign in to comment.