|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { arbitrumSepolia } from "thirdweb/chains"; |
| 3 | +import { pollTransactionStatus } from "../../utils/transactions"; |
| 4 | +import { setup } from "../setup"; |
| 5 | + |
| 6 | +const chain = arbitrumSepolia; |
| 7 | +const chainId = chain.id.toString(); |
| 8 | + |
| 9 | +describe("smart local wallet (test succesfull deploy with SDKv4)", () => { |
| 10 | + let smartWalletAddress: string | undefined; |
| 11 | + |
| 12 | + const getSmartWalletAddress = () => { |
| 13 | + if (!smartWalletAddress) { |
| 14 | + throw new Error("Smart wallet address not set"); |
| 15 | + } |
| 16 | + return smartWalletAddress; |
| 17 | + }; |
| 18 | + |
| 19 | + test("Create a local smart backend wallet", async () => { |
| 20 | + const { engine } = await setup(); |
| 21 | + |
| 22 | + const res = await engine.backendWallet.create({ |
| 23 | + type: "smart:local", |
| 24 | + label: "test", |
| 25 | + }); |
| 26 | + |
| 27 | + expect(res.result.status).toEqual("success"); |
| 28 | + expect(res.result.type).toEqual("smart:local"); |
| 29 | + expect(res.result.walletAddress).toBeDefined(); |
| 30 | + |
| 31 | + smartWalletAddress = res.result.walletAddress; |
| 32 | + }); |
| 33 | + |
| 34 | + test("Send a SDK v4 Transaction (deploy ERC20)", async () => { |
| 35 | + const { engine } = await setup(); |
| 36 | + |
| 37 | + const deployRes = await engine.deploy.deployToken( |
| 38 | + chainId, |
| 39 | + getSmartWalletAddress(), |
| 40 | + { |
| 41 | + contractMetadata: { |
| 42 | + name: "Test", |
| 43 | + symbol: "TST", |
| 44 | + platform_fee_basis_points: 0, |
| 45 | + platform_fee_recipient: getSmartWalletAddress(), |
| 46 | + trusted_forwarders: [], |
| 47 | + }, |
| 48 | + }, |
| 49 | + ); |
| 50 | + |
| 51 | + const { queueId: deployQueueId, deployedAddress } = deployRes.result; |
| 52 | + |
| 53 | + if (!deployedAddress || !deployQueueId) { |
| 54 | + throw new Error("Deploy failed"); |
| 55 | + } |
| 56 | + |
| 57 | + await pollTransactionStatus(engine, deployQueueId); |
| 58 | + |
| 59 | + const mintRes = await engine.erc20.mintTo( |
| 60 | + chainId, |
| 61 | + deployedAddress, |
| 62 | + getSmartWalletAddress(), |
| 63 | + { |
| 64 | + amount: "1000", |
| 65 | + toAddress: getSmartWalletAddress(), |
| 66 | + }, |
| 67 | + ); |
| 68 | + |
| 69 | + await pollTransactionStatus(engine, mintRes.result.queueId); |
| 70 | + const status = await engine.transaction.status(mintRes.result.queueId); |
| 71 | + expect(status.result.accountAddress).toEqual(getSmartWalletAddress()); |
| 72 | + |
| 73 | + const balance = await engine.erc20.balanceOf( |
| 74 | + getSmartWalletAddress(), |
| 75 | + chainId, |
| 76 | + deployedAddress, |
| 77 | + ); |
| 78 | + |
| 79 | + expect(Number(balance.result.displayValue)).toEqual(1000); |
| 80 | + }); |
| 81 | + |
| 82 | + test("Delete local smart backend wallet", async () => { |
| 83 | + const { engine } = await setup(); |
| 84 | + |
| 85 | + const res = await engine.backendWallet.removeBackendWallet( |
| 86 | + getSmartWalletAddress(), |
| 87 | + ); |
| 88 | + expect(res.result.status).toEqual("success"); |
| 89 | + }); |
| 90 | +}); |
0 commit comments