|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { ANVIL_CHAIN } from "~test/chains.js"; |
| 3 | +import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; |
| 4 | +import { TEST_CLIENT } from "~test/test-clients.js"; |
| 5 | +import { |
| 6 | + TEST_ACCOUNT_A, |
| 7 | + TEST_ACCOUNT_B, |
| 8 | + TEST_ACCOUNT_C, |
| 9 | + TEST_ACCOUNT_D, |
| 10 | +} from "~test/test-wallets.js"; |
| 11 | +import { getContract } from "../../../contract/contract.js"; |
| 12 | +import { deployERC20Contract } from "../../../extensions/prebuilts/deploy-erc20.js"; |
| 13 | +import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js"; |
| 14 | +import { balanceOf } from "../__generated__/IERC20/read/balanceOf.js"; |
| 15 | +import { mintTo } from "./mintTo.js"; |
| 16 | +import { transferBatch } from "./transferBatch.js"; |
| 17 | + |
| 18 | +const chain = ANVIL_CHAIN; |
| 19 | +const client = TEST_CLIENT; |
| 20 | +const account = TEST_ACCOUNT_A; |
| 21 | + |
| 22 | +describe("erc20: transferBatch", () => { |
| 23 | + it("should transfer tokens to multiple recipients", async () => { |
| 24 | + const address = await deployERC20Contract({ |
| 25 | + type: "TokenERC20", |
| 26 | + account, |
| 27 | + chain, |
| 28 | + client, |
| 29 | + params: { |
| 30 | + name: "", |
| 31 | + contractURI: TEST_CONTRACT_URI, |
| 32 | + }, |
| 33 | + }); |
| 34 | + const contract = getContract({ |
| 35 | + address, |
| 36 | + chain, |
| 37 | + client, |
| 38 | + }); |
| 39 | + |
| 40 | + // Mint 100 tokens |
| 41 | + await sendAndConfirmTransaction({ |
| 42 | + transaction: mintTo({ contract, to: account.address, amount: 100 }), |
| 43 | + account, |
| 44 | + }); |
| 45 | + |
| 46 | + // Send 25 tokens to each account B, C and D |
| 47 | + await sendAndConfirmTransaction({ |
| 48 | + account, |
| 49 | + transaction: transferBatch({ |
| 50 | + contract, |
| 51 | + batch: [ |
| 52 | + { |
| 53 | + to: TEST_ACCOUNT_B.address, |
| 54 | + amount: 25, |
| 55 | + }, |
| 56 | + { |
| 57 | + to: TEST_ACCOUNT_C.address, |
| 58 | + amount: 25, |
| 59 | + }, |
| 60 | + { |
| 61 | + to: TEST_ACCOUNT_D.address, |
| 62 | + amount: 25, |
| 63 | + }, |
| 64 | + ], |
| 65 | + }), |
| 66 | + }); |
| 67 | + |
| 68 | + // After that, each address A, B, C and D should have 25 tokens |
| 69 | + const [balanceA, balanceB, balanceC, balanceD] = await Promise.all([ |
| 70 | + balanceOf({ contract, address: TEST_ACCOUNT_A.address }), |
| 71 | + balanceOf({ contract, address: TEST_ACCOUNT_B.address }), |
| 72 | + balanceOf({ contract, address: TEST_ACCOUNT_C.address }), |
| 73 | + balanceOf({ contract, address: TEST_ACCOUNT_D.address }), |
| 74 | + ]); |
| 75 | + |
| 76 | + expect(balanceA).toBe(25n * 10n ** 18n); |
| 77 | + expect(balanceB).toBe(25n * 10n ** 18n); |
| 78 | + expect(balanceC).toBe(25n * 10n ** 18n); |
| 79 | + expect(balanceD).toBe(25n * 10n ** 18n); |
| 80 | + }); |
| 81 | +}); |
0 commit comments