Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(DEVX-410): E2E Tests #351

Merged
merged 9 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
E2E_PRIVATE_KEY_ONE=
E2E_PRIVATE_KEY_TWO=
E2E_BICO_PAYMASTER_KEY_MUMBAI=
2 changes: 1 addition & 1 deletion .github/workflows/check_branch_name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
if [[ ! $BRANCH_NAME =~ ^(features/|fixes/|releases/) ]]; then
echo "error: Branch names should follow GitFlow naming convention (features/, fixes/, releases/)."
exit 1
fi
fi
35 changes: 35 additions & 0 deletions .github/workflows/pull_request_approved.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: E2E Test workflow
on:
pull_request_review:
types: [submitted]
jobs:
e2e_test:
if: github.event.review.state == 'approved'
name: E2E tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]

steps:
- name: Checkout
uses: "actions/checkout@main"

- name: Set Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: yarn install --frozen-lockfile && yarn build

- name: Run tests
uses: nick-fields/retry@v2
env:
E2E_PRIVATE_KEY_ONE: ${{ secrets.E2E_PRIVATE_KEY_ONE }}
E2E_PRIVATE_KEY_TWO: ${{ secrets.E2E_PRIVATE_KEY_TWO }}
E2E_BICO_PAYMASTER_KEY_MUMBAI: ${{ secrets.E2E_BICO_PAYMASTER_KEY_MUMBAI }}
with:
timeout_minutes: 2
max_attempts: 3
command: yarn test:e2e
3 changes: 2 additions & 1 deletion .github/workflows/push_check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Test workflow
on: push
on: [push, workflow_dispatch]

jobs:
lint:
name: Lint sources
Expand Down
6 changes: 6 additions & 0 deletions jest.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import config from "./jest.config";
const e2eConfig = { ...config };
e2eConfig.testMatch = ["**/*.e2e.spec.ts"];
e2eConfig.setupFilesAfterEnv = ["<rootDir>/setup-e2e-tests.ts"];

export default e2eConfig;
10 changes: 7 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const config: Config = {
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
setupFilesAfterEnv: ["<rootDir>/setup-unit-tests.ts"],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,
Expand All @@ -141,7 +141,7 @@ const config: Config = {
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
testMatch: ["**/*.spec.ts"],
testMatch: ["**/*.spec.ts", "!**/*.e2e.spec.ts"],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
Expand Down Expand Up @@ -179,6 +179,10 @@ const config: Config = {

// Whether to use watchman for file crawling
// watchman: true,

globals: {
testDataPerChain: []
}
};

export default config;
export default config;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"start:ganache": "ganache -m 'direct buyer cliff train rice spirit census refuse glare expire innocent quote'",
"test:ci": "FORCE_COLOR=1 lerna run test:ci --stream --npm-client=yarn",
"test:coverage": "concurrently -k --success first 'yarn start:ganache' 'yarn jest --runInBand --coverage'",
"test:e2e": "yarn test:run --config=jest.config.e2e.ts",
"diff": "lerna diff",
"release": "lerna version patch --no-git-tag-version --no-push --conventional-commits --yes"
},
Expand Down Expand Up @@ -71,7 +72,7 @@
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-security": "^1.7.1",
"ganache": "^7.9.1",
"ganache": "^7.9.2",
"hardhat": "^2.17.3",
"jest": "^29.7.0",
"lerna": "^7.2.0",
Expand Down
57 changes: 15 additions & 42 deletions packages/account/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ yarn add @biconomy/account

### Account

Integrating and deploying Smart Accounts, building and sending user operations is a key offering of any toolkit designed for ERC4337. This package seamlessly integrates the essential features associated with ERC-4337 and simplifies the development of your Dapp's account and transaction rails with added usability features.
Integrating and deploying Smart Accounts, building and sending user operations is a key offering of any toolkit designed for ERC4337. This package seamlessly integrates the essential features associated with ERC-4337 and simplifies the development of your Dapp's account and transaction rails with added usability features.

The account package achieves this by providing a comprehensive set of methods that enable developers to effortlessly create UserOperations. Combined with the sophisticated, developer friendly and scalable infrastructure of Biconomy, it ensures efficient and reliable transmission of these operations across multiple EVM chains.

Expand All @@ -36,50 +36,23 @@ The account package achieves this by providing a comprehensive set of methods th
## Example Usage

```typescript
// This is how you create BiconomySmartAccount instance in your dapp's
// This is how you create a smartWallet in your dapp
import { Bundler, createSmartWalletClient } from "@biconomy/account";

import { BiconomySmartAccount, BiconomySmartAccountConfig } from "@biconomy/account";
const smartWallet = await createSmartWalletClient({
chainId: 1,
signer, // viem's WalletClientSigner
bundlerUrl,
});

// Note that paymaster and bundler are optional. You can choose to create new instances of this later and make account API use
const biconomySmartAccountConfig: BiconomySmartAccountConfig = {
signer: wallet.getSigner(),
chainId: ChainId.POLYGON_MAINNET,
rpcUrl: "",
// paymaster: paymaster, // check the README.md section of Paymaster package
// bundler: bundler, // check the README.md section of Bundler package
};

const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig);
const biconomySmartAccount = await biconomyAccount.init();

// native token transfer
// you can create any sort of transaction following same structure
const transaction = {
// Send some ETH
const { wait } = await smartWallet.sendTransaction({
to: "0x85B51B068bF0fefFEFD817882a14f6F5BDF7fF2E",
value: 1,
data: "0x",
value: ethers.utils.parseEther("0.1"),
};

// building partialUserOp
const partialUserOp = await biconomySmartAccount.buildUserOp([transaction]);

// using the paymaster package one can populate paymasterAndData to partial userOp. by default it is '0x'
```

```typescript
const userOpResponse = await smartAccount.sendUserOp(partialUserOp);
const transactionDetails = await userOpResponse.wait();
console.log("transaction details below");
console.log(transactionDetails);
```

Finally we send the userOp and save the value to a variable named userOpResponse and get the transactionDetails after calling `typescript userOpResponse.wait()`
});

```typescript
const transactionDetails = await userOpResponse.wait();
console.log("transaction details below");
console.log(transactionDetails);
const {
receipt: { transactionHash },
} = await wait();
```

#### BiconomySmartAccount (V2 Smart Account aka Modular Smart Account)

3 changes: 1 addition & 2 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"access": "public"
},
"devDependencies": {
"nock": "^13.2.9",
"viem": "^1.19.11"
"nock": "^13.2.9"
},
"dependencies": {
"@alchemy/aa-core": "^1.2.2",
Expand Down
10 changes: 10 additions & 0 deletions packages/account/src/BiconomySmartAccountV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
];
this.validateUserOp(userOp, requiredFields);
if (!this.bundler) throw new Error("Bundler is not provided");
console.info("userOp being sent to the bundler", userOp);

Check warning on line 458 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
const bundlerResponse = await this.bundler.sendUserOp(userOp);
return bundlerResponse;
}
Expand Down Expand Up @@ -528,7 +528,7 @@
}
} catch (error) {
// Not throwing this error as nonce would be 0 if this.getNonce() throw exception, which is expected flow for undeployed account
console.info("Error while getting nonce for the account. This is expected for undeployed accounts set nonce to 0");

Check warning on line 531 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
}
return nonce;
}
Expand All @@ -550,11 +550,21 @@
return gasFeeValues;
} catch (error: any) {
// TODO: should throw error here?
console.error("Error while getting gasFeeValues from bundler. Provided bundler might not have getGasFeeValues endpoint", error);

Check warning on line 553 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
return gasFeeValues;
}
}

/**
* @param manyOrOneTransactions list of transactions, or single transaction for execution
* @param buildUseropDto options for building the userOp
* @returns Promise<UserOpResponse>
*/
async sendTransaction(manyOrOneTransactions: Transaction | Transaction[], buildUseropDto?: BuildUserOpOptions) {

Check warning on line 563 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Missing return type on function
const userOp = await this.buildUserOp(Array.isArray(manyOrOneTransactions) ? manyOrOneTransactions : [manyOrOneTransactions], buildUseropDto);
return this.sendUserOp(userOp);
}

async buildUserOp(transactions: Transaction[], buildUseropDto?: BuildUserOpOptions): Promise<Partial<UserOperationStruct>> {
const to = transactions.map((element: Transaction) => element.to as Hex);
const data = transactions.map((element: Transaction) => (element.data as Hex) ?? "0x");
Expand Down Expand Up @@ -593,7 +603,7 @@
// Note: Can change the default behaviour of calling estimations using bundler/local
userOp = await this.estimateUserOpGas(userOp);
userOp.paymasterAndData = userOp.paymasterAndData ?? "0x";
console.log("UserOp after estimation ", userOp);

Check warning on line 606 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

return userOp;
}
Expand All @@ -604,14 +614,14 @@
}

const feeTokenAddress = tokenPaymasterRequest?.feeQuote?.tokenAddress;
console.info("Requested fee token is ", feeTokenAddress);

Check warning on line 617 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (!feeTokenAddress || feeTokenAddress === ADDRESS_ZERO) {
throw new Error("Invalid or missing token address. Token address must be part of the feeQuote in tokenPaymasterRequest");
}

const spender = tokenPaymasterRequest?.spender;
console.info("Spender address is ", spender);

Check warning on line 624 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (!spender || spender === ADDRESS_ZERO) {
throw new Error("Invalid or missing spender address. Sepnder address must be part of tokenPaymasterRequest");
Expand All @@ -638,7 +648,7 @@
let batchData: Array<Hex> = [];

let newCallData = userOp.callData;
console.info("Received information about fee token address and quote ", tokenPaymasterRequest);

Check warning on line 651 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (this.paymaster && this.paymaster instanceof BiconomyPaymaster) {
// Make a call to paymaster.buildTokenApprovalTransaction() with necessary details
Expand All @@ -647,7 +657,7 @@
const approvalRequest: Transaction = await (this.paymaster as IHybridPaymaster<SponsorUserOperationDto>).buildTokenApprovalTransaction(
tokenPaymasterRequest,
);
console.info("ApprovalRequest is for erc20 token ", approvalRequest.to);

Check warning on line 660 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement

if (approvalRequest.data === "0x" || approvalRequest.to === ADDRESS_ZERO) {
return userOp;
Expand All @@ -668,7 +678,7 @@

const smartAccountExecFunctionName = decodedSmartAccountData.functionName;

console.info(`Originally an ${smartAccountExecFunctionName} method call for Biconomy Account V2`);

Check warning on line 681 in packages/account/src/BiconomySmartAccountV2.ts

View workflow job for this annotation

GitHub Actions / Lint sources (18.x)

Unexpected console statement
if (smartAccountExecFunctionName === "execute" || smartAccountExecFunctionName === "execute_ncC") {
const methodArgsSmartWalletExecuteCall = decodedSmartAccountData.args;
const toOriginal = methodArgsSmartWalletExecuteCall[0];
Expand Down
9 changes: 9 additions & 0 deletions packages/account/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { BiconomySmartAccountV2 } from "./BiconomySmartAccountV2";
import { BiconomySmartAccountV2Config } from "./utils/Types";

export * from "./utils/Types";
export * from "./utils/Constants";
export * from "./BiconomySmartAccountV2";
export * from "./provider";

export { WalletClientSigner } from "@alchemy/aa-core";
export { BiconomyPaymaster as Paymaster, IPaymaster } from "@biconomy/paymaster";
export { Bundler, IBundler } from "@biconomy/bundler";
export const createSmartWalletClient = BiconomySmartAccountV2.create;
export type SmartWalletConfig = BiconomySmartAccountV2Config;

This file was deleted.

This file was deleted.

Loading
Loading