1+ import { type Abi , toFunctionSelector } from "viem" ;
12import { describe , expect , it } from "vitest" ;
23import { ANVIL_CHAIN } from "~test/chains.js" ;
34import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js" ;
45import { TEST_CLIENT } from "~test/test-clients.js" ;
56import { TEST_ACCOUNT_C } from "~test/test-wallets.js" ;
7+ import { resolveContractAbi } from "../../../contract/actions/resolve-abi.js" ;
68import { getContract } from "../../../contract/contract.js" ;
79import { deployERC1155Contract } from "../../../extensions/prebuilts/deploy-erc1155.js" ;
810import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js" ;
911import { getNFTs } from "../read/getNFTs.js" ;
10- import { mintAdditionalSupplyToBatch } from "./mintAdditionalSupplyToBatch.js" ;
12+ import { isMintAdditionalSupplyToSupported } from "./mintAdditionalSupplyTo.js" ;
13+ import {
14+ mintAdditionalSupplyToBatch ,
15+ optimizeMintBatchContent ,
16+ } from "./mintAdditionalSupplyToBatch.js" ;
1117import { mintToBatch } from "./mintToBatch.js" ;
1218
1319const chain = ANVIL_CHAIN ;
@@ -17,6 +23,19 @@ const account = TEST_ACCOUNT_C;
1723describe . runIf ( process . env . TW_SECRET_KEY ) (
1824 "ERC1155 Edition: mintToBatch" ,
1925 ( ) => {
26+ it ( "should optimize the mint content" , ( ) => {
27+ expect (
28+ optimizeMintBatchContent ( [
29+ { tokenId : 0n , supply : 99n , to : account . address } ,
30+ { tokenId : 1n , supply : 49n , to : account . address } ,
31+ { tokenId : 1n , supply : 51n , to : account . address } ,
32+ ] ) ,
33+ ) . toStrictEqual ( [
34+ { tokenId : 0n , supply : 99n , to : account . address } ,
35+ { tokenId : 1n , supply : 100n , to : account . address } ,
36+ ] ) ;
37+ } ) ;
38+
2039 it ( "should mint multiple tokens in one tx" , async ( ) => {
2140 const contract = getContract ( {
2241 chain,
@@ -33,6 +52,13 @@ describe.runIf(process.env.TW_SECRET_KEY)(
3352 } ) ,
3453 } ) ;
3554
55+ // `isMintAdditionalSupplyToSupported` should work with our Edition contracts
56+ const abi = await resolveContractAbi < Abi > ( contract ) ;
57+ const selectors = abi
58+ . filter ( ( f ) => f . type === "function" )
59+ . map ( ( f ) => toFunctionSelector ( f ) ) ;
60+ expect ( isMintAdditionalSupplyToSupported ( selectors ) ) . toBe ( true ) ;
61+
3662 await sendAndConfirmTransaction ( {
3763 account,
3864 transaction : mintToBatch ( {
@@ -52,8 +78,9 @@ describe.runIf(process.env.TW_SECRET_KEY)(
5278 contract,
5379 nfts : [
5480 { tokenId : 0n , supply : 99n , to : account . address } ,
55- { tokenId : 1n , supply : 98n , to : account . address } ,
81+ { tokenId : 1n , supply : 94n , to : account . address } ,
5682 { tokenId : 2n , supply : 97n , to : account . address } ,
83+ { tokenId : 1n , supply : 4n , to : account . address } ,
5784 ] ,
5885 } ) ,
5986 } ) ;
0 commit comments