1- import { describe , expect , it } from "vitest" ;
1+ import { beforeAll , describe , expect , it } from "vitest" ;
22import { ANVIL_CHAIN } from "~test/chains.js" ;
33import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js" ;
44import { TEST_CLIENT } from "~test/test-clients.js" ;
@@ -8,19 +8,23 @@ import {
88 TEST_ACCOUNT_C ,
99 TEST_ACCOUNT_D ,
1010} from "~test/test-wallets.js" ;
11- import { getContract } from "../../../contract/contract.js" ;
11+ import {
12+ type ThirdwebContract ,
13+ getContract ,
14+ } from "../../../contract/contract.js" ;
1215import { deployERC20Contract } from "../../../extensions/prebuilts/deploy-erc20.js" ;
1316import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js" ;
1417import { balanceOf } from "../__generated__/IERC20/read/balanceOf.js" ;
1518import { mintTo } from "./mintTo.js" ;
16- import { transferBatch } from "./transferBatch.js" ;
19+ import { optimizeTransferContent , transferBatch } from "./transferBatch.js" ;
1720
1821const chain = ANVIL_CHAIN ;
1922const client = TEST_CLIENT ;
2023const account = TEST_ACCOUNT_A ;
24+ let contract : ThirdwebContract ;
2125
2226describe . runIf ( process . env . TW_SECRET_KEY ) ( "erc20: transferBatch" , ( ) => {
23- it ( "should transfer tokens to multiple recipients" , async ( ) => {
27+ beforeAll ( async ( ) => {
2428 const address = await deployERC20Contract ( {
2529 type : "TokenERC20" ,
2630 account,
@@ -31,15 +35,16 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc20: transferBatch", () => {
3135 contractURI : TEST_CONTRACT_URI ,
3236 } ,
3337 } ) ;
34- const contract = getContract ( {
38+ contract = getContract ( {
3539 address,
3640 chain,
3741 client,
3842 } ) ;
39-
40- // Mint 100 tokens
43+ } , 60_000_000 ) ;
44+ it ( "should transfer tokens to multiple recipients" , async ( ) => {
45+ // Mint 200 tokens
4146 await sendAndConfirmTransaction ( {
42- transaction : mintTo ( { contract, to : account . address , amount : 100 } ) ,
47+ transaction : mintTo ( { contract, to : account . address , amount : 200 } ) ,
4348 account,
4449 } ) ;
4550
@@ -61,6 +66,14 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc20: transferBatch", () => {
6166 to : TEST_ACCOUNT_D . address ,
6267 amount : 25 ,
6368 } ,
69+ {
70+ to : TEST_ACCOUNT_B . address . toLowerCase ( ) ,
71+ amount : 25 ,
72+ } ,
73+ {
74+ to : TEST_ACCOUNT_B . address ,
75+ amountWei : 25n * 10n ** 18n ,
76+ } ,
6477 ] ,
6578 } ) ,
6679 } ) ;
@@ -73,9 +86,53 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc20: transferBatch", () => {
7386 balanceOf ( { contract, address : TEST_ACCOUNT_D . address } ) ,
7487 ] ) ;
7588
76- expect ( balanceA ) . toBe ( 25n * 10n ** 18n ) ;
77- expect ( balanceB ) . toBe ( 25n * 10n ** 18n ) ;
89+ expect ( balanceA ) . toBe ( 75n * 10n ** 18n ) ;
90+ expect ( balanceB ) . toBe ( 75n * 10n ** 18n ) ;
7891 expect ( balanceC ) . toBe ( 25n * 10n ** 18n ) ;
7992 expect ( balanceD ) . toBe ( 25n * 10n ** 18n ) ;
8093 } ) ;
94+
95+ it ( "should optimize the transfer content" , async ( ) => {
96+ const content = await optimizeTransferContent ( {
97+ contract,
98+ batch : [
99+ {
100+ to : TEST_ACCOUNT_B . address ,
101+ amount : 25 ,
102+ } ,
103+ {
104+ to : TEST_ACCOUNT_C . address ,
105+ amount : 25 ,
106+ } ,
107+ {
108+ to : TEST_ACCOUNT_D . address ,
109+ amount : 25 ,
110+ } ,
111+ {
112+ // Should work
113+ to : TEST_ACCOUNT_B . address . toLowerCase ( ) ,
114+ amount : 25 ,
115+ } ,
116+ {
117+ to : TEST_ACCOUNT_B . address ,
118+ amountWei : 25n * 10n ** 18n ,
119+ } ,
120+ ] ,
121+ } ) ;
122+
123+ expect ( content ) . toStrictEqual ( [
124+ {
125+ to : TEST_ACCOUNT_B . address ,
126+ amountWei : 75n * 10n ** 18n ,
127+ } ,
128+ {
129+ to : TEST_ACCOUNT_C . address ,
130+ amountWei : 25n * 10n ** 18n ,
131+ } ,
132+ {
133+ to : TEST_ACCOUNT_D . address ,
134+ amountWei : 25n * 10n ** 18n ,
135+ } ,
136+ ] ) ;
137+ } ) ;
81138} ) ;
0 commit comments