Skip to content

Commit

Permalink
respond to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Nov 28, 2023
1 parent 1f940bd commit ebbe8ae
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ import { arrayify, hexConcat, parseEther } from "ethers/lib/utils";
import { BigNumber, BigNumberish, Contract, Signer } from "ethers";
import {
BundlerTestEnvironment,
EthSendUserOperationResult,
UserOperationSubmissionError,
} from "../environment/bundlerEnvironment";
import { getUserOpEvent } from "../../utils/testUtils";
import { getUserOpEvent, parseEvent } from "../../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

const MOCK_VALID_UNTIL = "0x00000000deadbeef";
const MOCK_VALID_AFTER = "0x0000000000001234";
const dynamicMarkup = 1200000; // or 0 or 1100000
Expand Down Expand Up @@ -83,7 +87,7 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
feeCollector = ethersSigner[3];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

const offchainSignerAddress = await offchainSigner.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -248,12 +252,21 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
console.log("userop VGL ", userOp.verificationGasLimit.toString());
console.log("userop PVG ", userOp.preVerificationGas.toString());

await environment.sendUserOperation(userOp, entryPoint.address);
const result: EthSendUserOperationResult =
await environment.sendUserOperation(userOp, entryPoint.address);

const receipt = (await environment.getUserOperationReceipt(result.result))
.result;

const ev = await getUserOpEvent(entryPoint);
const event = parseEvent(receipt.receipt, UserOperationEventTopic);

const eventLogs = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(ev.args.success).to.be.true;
expect(eventLogs.success).to.be.true;

await expect(
entryPoint.handleOps([userOp], await offchainSigner.getAddress())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ import {
} from "@biconomy-devx/account-contracts-v2/dist/types";
import { arrayify, parseEther } from "ethers/lib/utils";
import { BigNumber, BigNumberish, Signer } from "ethers";
import { BundlerTestEnvironment } from "../environment/bundlerEnvironment";
import { getUserOpEvent } from "../../utils/testUtils";
import {
BundlerTestEnvironment,
EthSendUserOperationResult,
} from "../environment/bundlerEnvironment";
import { parseEvent } from "../../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;

Expand All @@ -44,6 +47,9 @@ const DEFAULT_FEE_MARKUP = 1100000;

const MOCK_FX: BigNumberish = "977100"; // matic to usdc approx

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

export async function deployEntryPoint(
provider = ethers.provider
): Promise<EntryPoint> {
Expand Down Expand Up @@ -114,7 +120,7 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
entryPoint = EntryPoint__factory.connect(process.env.ENTRYPOINT!, deployer);

offchainSigner = ethersSigner[1];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -288,10 +294,20 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {

userOp.signature = signatureWithModuleAddress;

await environment.sendUserOperation(userOp, entryPoint.address);
const result: EthSendUserOperationResult =
await environment.sendUserOperation(userOp, entryPoint.address);

const receipt = (await environment.getUserOperationReceipt(result.result))
.result;

const event = parseEvent(receipt.receipt, UserOperationEventTopic);

const eventLogs = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// const ev = await getUserOpEvent(entryPoint);
// expect(ev.args.success).to.be.true;
expect(eventLogs.success).to.be.true;

const accountBalAfter = await token.balanceOf(walletAddress);
const feeReceiverBalAfter = await token.balanceOf(paymasterAddress);
Expand Down
27 changes: 18 additions & 9 deletions test/bundler-integration/token-paymaster/btpm-undeployed-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
} from "../../../lib/account-abstraction/typechain";
import { arrayify, hexConcat, parseEther } from "ethers/lib/utils";
import { BigNumber, BigNumberish, Contract, Signer } from "ethers";
import { BundlerTestEnvironment } from "../environment/bundlerEnvironment";
import { getUserOpEvent } from "../../utils/testUtils";
import { BundlerTestEnvironment, EthSendUserOperationResult } from "../environment/bundlerEnvironment";
import { getUserOpEvent, parseEvent } from "../../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;

Expand All @@ -44,6 +44,9 @@ const DEFAULT_FEE_MARKUP = 1100000;

const MOCK_FX: BigNumberish = "977100"; // matic to usdc approx

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

export async function deployEntryPoint(
provider = ethers.provider
): Promise<EntryPoint> {
Expand Down Expand Up @@ -116,7 +119,7 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
entryPoint = EntryPoint__factory.connect(process.env.ENTRYPOINT!, deployer);

offchainSigner = ethersSigner[1];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -302,14 +305,20 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {

userOp.signature = signatureWithModuleAddress;

const response = await environment.sendUserOperation(
userOp,
entryPoint.address
const result: EthSendUserOperationResult =
await environment.sendUserOperation(userOp, entryPoint.address);

const receipt = (await environment.getUserOperationReceipt(result.result))
.result;

const event = parseEvent(receipt.receipt, UserOperationEventTopic);

const eventLogs = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);
console.log("response", response);

// const ev = await getUserOpEvent(entryPoint);
// expect(ev.args.success).to.be.true;
expect(eventLogs.success).to.be.true;

const accountBalAfter = await token.balanceOf(walletAddress);
const feeReceiverBalAfter = await token.balanceOf(paymasterAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { arrayify, parseEther } from "ethers/lib/utils";
import { BigNumber, BigNumberish, Contract, Signer } from "ethers";
import { BundlerTestEnvironment } from "../environment/bundlerEnvironment";
import { getUserOpEvent } from "../../utils/testUtils";
import { getUserOpEvent, parseEvent } from "../../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;

Expand All @@ -47,6 +47,9 @@ const DEFAULT_FEE_MARKUP = 1100000;

const MOCK_FX: BigNumberish = "977100"; // matic to usdc approx

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

export const encodePaymasterData = (
feeToken = ethers.constants.AddressZero,
oracleAggregator = ethers.constants.AddressZero,
Expand Down Expand Up @@ -115,7 +118,7 @@ describe("Biconomy Token Paymaster (With Bundler)", function () {
entryPoint = EntryPoint__factory.connect(process.env.ENTRYPOINT!, deployer);

offchainSigner = ethersSigner[1];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -342,8 +345,15 @@ describe("Biconomy Token Paymaster (With Bundler)", function () {
transactionHash
);

const ev = await getUserOpEvent(entryPoint);
expect(ev.args.success).to.be.true;
const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.true;

const BiconomyTokenPaymaster = await ethers.getContractFactory(
"BiconomyTokenPaymaster"
Expand Down Expand Up @@ -465,8 +475,15 @@ describe("Biconomy Token Paymaster (With Bundler)", function () {
transactionHash
);

const ev = await getUserOpEvent(entryPoint);
expect(ev.args.success).to.be.true;
const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.true;

const BiconomyTokenPaymaster = await ethers.getContractFactory(
"BiconomyTokenPaymaster"
Expand Down Expand Up @@ -584,8 +601,15 @@ describe("Biconomy Token Paymaster (With Bundler)", function () {
transactionHash
);

const ev = await getUserOpEvent(entryPoint);
expect(ev.args.success).to.be.true;
const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.true;

const BiconomyTokenPaymaster = await ethers.getContractFactory(
"BiconomyTokenPaymaster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
deployer = ethersSigner[0];
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

const offchainSignerAddress = await offchainSigner.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("EntryPoint with VerifyingPaymaster Singleton", function () {
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
feeCollector = ethersSigner[3];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

const offchainSignerAddress = await offchainSigner.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down
36 changes: 28 additions & 8 deletions test/token-paymaster/biconomy-token-paymaster-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { arrayify, hexConcat, parseEther } from "ethers/lib/utils";
import { BigNumber, BigNumberish, Contract, Signer } from "ethers";
import { SignerWithAddress } from "hardhat-deploy-ethers/signers";
import { getUserOpEvent } from "../utils/testUtils";
import { getUserOpEvent, parseEvent } from "../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;

Expand All @@ -52,6 +52,9 @@ const DEFAULT_FEE_MARKUP = 1100000;

const MOCK_FX: BigNumberish = "977100"; // matic to usdc approx

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

export async function deployEntryPoint(
provider = ethers.provider
): Promise<EntryPoint> {
Expand Down Expand Up @@ -120,7 +123,7 @@ describe("Biconomy Token Paymaster", function () {
deployer = ethersSigner[0];
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -359,8 +362,15 @@ describe("Biconomy Token Paymaster", function () {

const postTokenBalanceForAccount = await token.balanceOf(walletAddress);

const ev = await getUserOpEvent(entryPoint);
expect(ev.args.success).to.be.true;
const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.true;

await expect(
entryPoint.handleOps([userOp], await offchainSigner.getAddress())
Expand Down Expand Up @@ -673,13 +683,23 @@ describe("Biconomy Token Paymaster", function () {

userOp.signature = signatureWithModuleAddress;

await entryPoint.handleOps([userOp], await offchainSigner.getAddress());
const tx = await entryPoint.handleOps(
[userOp],
await offchainSigner.getAddress()
);
const receipt = await tx.wait();

const postBalance = await token.balanceOf(paymasterAddress);

const ev = await getUserOpEvent(entryPoint);
// Review this because despite explicit revert bundler still pays gas
expect(ev.args.success).to.be.false;
const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.false;

await expect(
entryPoint.handleOps([userOp], await offchainSigner.getAddress())
Expand Down
2 changes: 1 addition & 1 deletion test/token-paymaster/btpm-coverage-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Biconomy Token Paymaster", function () {
deployer = ethersSigner[0];
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down
20 changes: 15 additions & 5 deletions test/token-paymaster/btpm-undeployed-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
EcdsaOwnershipRegistryModule,
EcdsaOwnershipRegistryModule__factory,
} from "@biconomy-devx/account-contracts-v2/dist/types";
import { getUserOpEvent } from "../utils/testUtils";
import { getUserOpEvent, parseEvent } from "../utils/testUtils";

export const AddressZero = ethers.constants.AddressZero;
const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
Expand All @@ -52,6 +52,9 @@ const DEFAULT_FEE_MARKUP = 1100000;

const MOCK_FX: BigNumberish = "977100"; // matic to usdc approx

const UserOperationEventTopic =
"0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f";

export async function deployEntryPoint(
provider = ethers.provider
): Promise<EntryPoint> {
Expand Down Expand Up @@ -120,7 +123,7 @@ describe("Biconomy Token Paymaster", function () {
deployer = ethersSigner[0];
offchainSigner = ethersSigner[1];
depositorSigner = ethersSigner[2];
walletOwner = deployer; // ethersSigner[3];
walletOwner = deployer; // ethersSigner[0];

// const offchainSignerAddress = await deployer.getAddress();
const walletOwnerAddress = await walletOwner.getAddress();
Expand Down Expand Up @@ -339,10 +342,17 @@ describe("Biconomy Token Paymaster", function () {
await offchainSigner.getAddress()
);

await tx.wait();
const receipt = await tx.wait();

const event = parseEvent(receipt, UserOperationEventTopic);

const eventLogsUserop = entryPoint.interface.decodeEventLog(
"UserOperationEvent",
event[0].data
);

const ev = await getUserOpEvent(entryPoint);
expect(ev.args.success).to.be.true;
// eslint-disable-next-line no-unused-expressions
expect(eventLogsUserop.success).to.be.true;

await expect(
entryPoint.handleOps([userOp], await offchainSigner.getAddress())
Expand Down
Loading

0 comments on commit ebbe8ae

Please sign in to comment.