difftreelog
feat add Put and Buy tests for market contract
in: master
1 file changed
tests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {readFile} from 'fs/promises';18import {readFile} from 'fs/promises';19import {itEth, usingEthPlaygrounds} from '../util';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';20import {makeNames} from '../../util';20import {makeNames} from '../../util';21import {expect} from 'chai';212222const {dirname} = makeNames(import.meta.url);23const {dirname} = makeNames(import.meta.url);232430 });31 });31 });32 });323333 itEth('Deploy', async ({helper}) => {34 async function deployMarket(helper: EthUniqueHelper, marketOwner: string) {34 const matcherOwner = await helper.eth.createAccountWithBalance(donor, 600n);3536 await helper.ethContract.deployByCode(35 return await helper.ethContract.deployByCode(37 matcherOwner,36 marketOwner,38 'Market',37 'Market',39 (await readFile(`${dirname}/Market.sol`)).toString(),38 (await readFile(`${dirname}/Market.sol`)).toString(),40 [39 [74 15000000,73 15000000,75 [1, 0],74 [1, 0],76 );75 );77 });76 }7778 itEth('Deploy', async ({helper}) => {79 const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);8081 await deployMarket(helper, marketOwner);82 });8384 itEth('Put + Buy', async ({helper}) => {85 const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);86 const sellerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);87 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');88 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);89 const result = await contract.methods.mint(sellerCross.eth).send();90 const tokenId = result.events.Transfer.returnValues.tokenId;9192 const market = await deployMarket(helper, marketOwner);9394 await contract.methods.approve(market.options.address, tokenId).send({from: sellerCross.eth});95 const putResult = await market.methods.put(collectionId, tokenId, 1, 1, sellerCross).send({from: sellerCross.eth});96 expect(putResult.events.TokenIsUpForSale).is.not.undefined;9798 const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);99 const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: 1});100 expect(buyResult.events.TokenIsPurchased).is.not.undefined;101 });78});102});79103