@@ -9,8 +9,10 @@ import {
99} from "../../../../test/src/test-wallets.js" ;
1010import { getContract } from "../../../contract/contract.js" ;
1111import { parseEventLogs } from "../../../event/actions/parse-logs.js" ;
12+ import { getApprovalForTransaction } from "../../../extensions/erc20/write/getApprovalForTransaction.js" ;
1213import { setApprovalForAll as setApprovalForAll721 } from "../../../extensions/erc721/__generated__/IERC721A/write/setApprovalForAll.js" ;
1314import { mintTo as mintToErc1155 } from "../../../extensions/erc1155/write/mintTo.js" ;
15+ import { deployERC20Contract } from "../../../extensions/prebuilts/deploy-erc20.js" ;
1416import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js" ;
1517import { balanceOf as balanceOfErc721 } from "../../erc721/__generated__/IERC721A/read/balanceOf.js" ;
1618import { mintTo as mintToErc721 } from "../../erc721/write/mintTo.js" ;
@@ -384,5 +386,59 @@ describe.runIf(process.env.TW_SECRET_KEY)("Marketplace Direct Listings", () => {
384386 expect ( nft1155BalanceOfAccountAAfterPurchase ) . toBe ( 1n ) ;
385387 // expect the seller to have one less 1155 token
386388 expect ( nft1155BalanceOfAccountCAfterPurchase ) . toBe ( 99n ) ;
389+
390+ /**
391+ * buyFromListing transaction (for listing with ERC20 currency) should have proper erc20 value
392+ * so that getApprovalForTransaction can work properly
393+ */
394+ const erc20Address = await deployERC20Contract ( {
395+ chain,
396+ client,
397+ account : TEST_ACCOUNT_C ,
398+ type : "TokenERC20" ,
399+ params : {
400+ name : "MyToken" ,
401+ contractURI : TEST_CONTRACT_URI ,
402+ } ,
403+ } ) ;
404+ // await sendAndConfirmTransaction({
405+ // transaction: approve({
406+ // contract: getContract({ address: erc20Address, chain, client }),
407+ // spender: marketplaceAddress,
408+ // amount: "10000000",
409+ // }),
410+ // account: TEST_ACCOUNT_B,
411+ // });
412+ await sendAndConfirmTransaction ( {
413+ transaction : createListing ( {
414+ contract : marketplaceContract ,
415+ assetContractAddress : erc1155Contract . address ,
416+ tokenId : 0n ,
417+ pricePerToken : "0.01" ,
418+ quantity : 1n ,
419+ currencyContractAddress : erc20Address ,
420+ } ) ,
421+ account : TEST_ACCOUNT_C ,
422+ } ) ;
423+ // get the last listing id
424+ const _allListings = await getAllListings ( {
425+ contract : marketplaceContract ,
426+ } ) ;
427+ const latestListing = _allListings . at ( - 1 ) ;
428+ expect ( latestListing ) . toBeDefined ( ) ;
429+ if ( ! latestListing ) {
430+ throw new Error ( "Cannot get listings" ) ;
431+ }
432+ const buyListingTx = buyFromListing ( {
433+ contract : marketplaceContract ,
434+ listingId : latestListing . id ,
435+ quantity : 1n ,
436+ recipient : TEST_ACCOUNT_C . address ,
437+ } ) ;
438+ const approveTx = await getApprovalForTransaction ( {
439+ transaction : buyListingTx ,
440+ account : TEST_ACCOUNT_A ,
441+ } ) ;
442+ expect ( approveTx ) . not . toBe ( null ) ;
387443 } ) ;
388444} ) ;
0 commit comments