git.delta.rocks / unique-network / refs/commits / 1bda5f2dfb25

difftreelog

feat add Put and Buy tests for market contract

Grigoriy Simonov2023-05-31parent: #870f451.patch.diff
in: master

1 file changed

modifiedtests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth
1616
17import {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';
2122
22const {dirname} = makeNames(import.meta.url);23const {dirname} = makeNames(import.meta.url);
2324
30 });31 });
31 });32 });
3233
33 itEth('Deploy', async ({helper}) => {34 async function deployMarket(helper: EthUniqueHelper, marketOwner: string) {
34 const matcherOwner = await helper.eth.createAccountWithBalance(donor, 600n);
35
36 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 }
77
78 itEth('Deploy', async ({helper}) => {
79 const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);
80
81 await deployMarket(helper, marketOwner);
82 });
83
84 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;
91
92 const market = await deployMarket(helper, marketOwner);
93
94 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;
97
98 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