-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(SMA-675): Add optimism tests (#437)
* Resolved SMA-675 * fix unit tests * Fix all tests * typo
- Loading branch information
Showing
15 changed files
with
367 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: E2E Test workflow - with mainnet tests | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
e2e_test: | ||
name: E2E tests - with mainnet 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 | ||
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 }} | ||
E2E_BICO_PAYMASTER_KEY_BASE: ${{ secrets.E2E_BICO_PAYMASTER_KEY_BASE }} | ||
E2E_BICO_PAYMASTER_KEY_OP: ${{ secrets.E2E_BICO_PAYMASTER_KEY_OP }} | ||
WITH_MAINNET_TESTS: true | ||
run: yarn test:e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { TestData } from "../../../tests"; | ||
import { createSmartAccountClient, PaymasterMode } from "../src/index"; | ||
import { encodeFunctionData, parseAbi } from "viem"; | ||
import { checkBalance } from "../../../tests/utils"; | ||
|
||
const maybe = process.env.WITH_MAINNET_TESTS === "true" ? describe : describe.skip; | ||
|
||
maybe("Account Tests", () => { | ||
let optimism: TestData; | ||
let _: TestData; | ||
let __: TestData; | ||
|
||
beforeEach(() => { | ||
// @ts-ignore: Comes from setup-e2e-tests | ||
[_, __, optimism] = testDataPerChain; | ||
}); | ||
|
||
it("should send some native token to a recipient on optimism", async () => { | ||
const { | ||
whale: { viemWallet: signer, publicAddress: sender }, | ||
minnow: { publicAddress: recipient }, | ||
bundlerUrl, | ||
publicClient, | ||
} = optimism; | ||
|
||
const smartAccount = await createSmartAccountClient({ | ||
signer, | ||
bundlerUrl, | ||
}); | ||
|
||
const accountAddress = await smartAccount.getAddress(); | ||
|
||
const balanceOfRecipient = (await checkBalance(publicClient, recipient)) as bigint; | ||
const smartAccountBalance = (await checkBalance(publicClient, accountAddress)) as bigint; | ||
const { wait } = await smartAccount.sendTransaction( | ||
{ | ||
to: recipient, | ||
value: BigInt(1), | ||
}, | ||
{ | ||
simulationType: "validation_and_execution", | ||
}, | ||
); | ||
|
||
const result = await wait(); | ||
const newBalanceOfRecipient = (await checkBalance(publicClient, recipient)) as bigint; | ||
|
||
expect(result?.receipt?.transactionHash).toBeTruthy(); | ||
expect(result.success).toBe("true"); | ||
expect(newBalanceOfRecipient).toBeGreaterThan(balanceOfRecipient); | ||
}, 50000); | ||
|
||
it("Create a smart account with paymaster with an api key on optimism", async () => { | ||
const { | ||
whale: { viemWallet: signer }, | ||
bundlerUrl, | ||
biconomyPaymasterApiKey, | ||
} = optimism; | ||
|
||
const smartAccount = await createSmartAccountClient({ | ||
signer, | ||
biconomyPaymasterApiKey, | ||
bundlerUrl, | ||
}); | ||
|
||
const paymaster = smartAccount.paymaster; | ||
expect(paymaster).not.toBeNull(); | ||
expect(paymaster).not.toBeUndefined(); | ||
}); | ||
|
||
it("Should gaslessly mint an NFT on optimism", async () => { | ||
const { | ||
whale: { viemWallet: signer, publicAddress: recipient }, | ||
bundlerUrl, | ||
biconomyPaymasterApiKey, | ||
publicClient, | ||
nftAddress, | ||
} = optimism; | ||
|
||
const smartAccount = await createSmartAccountClient({ | ||
signer, | ||
bundlerUrl, | ||
biconomyPaymasterApiKey, | ||
}); | ||
|
||
const encodedCall = encodeFunctionData({ | ||
abi: parseAbi(["function safeMint(address to) public"]), | ||
functionName: "safeMint", | ||
args: [recipient], | ||
}); | ||
|
||
const transaction = { | ||
to: nftAddress, // NFT address | ||
data: encodedCall, | ||
}; | ||
|
||
const balance = (await checkBalance(publicClient, recipient, nftAddress)) as bigint; | ||
|
||
const maticBalanceBefore = await checkBalance(publicClient, await smartAccount.getAddress()); | ||
|
||
const response = await smartAccount.sendTransaction(transaction, { | ||
paymasterServiceData: { mode: PaymasterMode.SPONSORED }, | ||
simulationType: "validation_and_execution", | ||
}); | ||
|
||
const userOpReceipt = await response.wait(3); | ||
expect(userOpReceipt.userOpHash).toBeTruthy(); | ||
expect(userOpReceipt.success).toBe("true"); | ||
|
||
const maticBalanceAfter = await checkBalance(publicClient, await smartAccount.getAddress()); | ||
|
||
expect(maticBalanceAfter).toEqual(maticBalanceBefore); | ||
|
||
const newBalance = (await checkBalance(publicClient, recipient, nftAddress)) as bigint; | ||
|
||
expect(newBalance - balance).toBe(1n); | ||
}, 50000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.