difftreelog
feat add Put and Buy tests for market contract
in: master
1 file changed
tests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {readFile} from 'fs/promises';19import {itEth, usingEthPlaygrounds} from '../util';20import {makeNames} from '../../util';2122const {dirname} = makeNames(import.meta.url);2324describe('Market V2 Contract', () => {25 let donor: IKeyringPair;2627 before(async () => {28 await usingEthPlaygrounds(async (_helper, privateKey) => {29 donor = await privateKey({url: import.meta.url});30 });31 });3233 itEth('Deploy', async ({helper}) => {34 const matcherOwner = await helper.eth.createAccountWithBalance(donor, 600n);3536 await helper.ethContract.deployByCode(37 matcherOwner,38 'Market',39 (await readFile(`${dirname}/Market.sol`)).toString(),40 [41 {42 solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',43 fsPath: `${dirname}/../api/UniqueNFT.sol`,44 },45 {46 solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',47 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,48 },49 {50 solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',51 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,52 },53 {54 solPath: '@openzeppelin/contracts/token/ERC721/IERC721.sol',55 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol`,56 },57 {58 solPath: '@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol',59 fsPath: `${dirname}/../api/CollectionHelpers.sol`,60 },61 {62 solPath: 'royalty/UniqueRoyaltyHelper.sol',63 fsPath: `${dirname}/royalty/UniqueRoyaltyHelper.sol`,64 },65 {66 solPath: 'royalty/UniqueRoyalty.sol',67 fsPath: `${dirname}/royalty/UniqueRoyalty.sol`,68 },69 {70 solPath: 'royalty/LibPart.sol',71 fsPath: `${dirname}/royalty/LibPart.sol`,72 },73 ],74 15000000,75 [1, 0],76 );77 });78});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {readFile} from 'fs/promises';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';20import {makeNames} from '../../util';21import {expect} from 'chai';2223const {dirname} = makeNames(import.meta.url);2425describe('Market V2 Contract', () => {26 let donor: IKeyringPair;2728 before(async () => {29 await usingEthPlaygrounds(async (_helper, privateKey) => {30 donor = await privateKey({url: import.meta.url});31 });32 });3334 async function deployMarket(helper: EthUniqueHelper, marketOwner: string) {35 return await helper.ethContract.deployByCode(36 marketOwner,37 'Market',38 (await readFile(`${dirname}/Market.sol`)).toString(),39 [40 {41 solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',42 fsPath: `${dirname}/../api/UniqueNFT.sol`,43 },44 {45 solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',46 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,47 },48 {49 solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',50 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,51 },52 {53 solPath: '@openzeppelin/contracts/token/ERC721/IERC721.sol',54 fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol`,55 },56 {57 solPath: '@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol',58 fsPath: `${dirname}/../api/CollectionHelpers.sol`,59 },60 {61 solPath: 'royalty/UniqueRoyaltyHelper.sol',62 fsPath: `${dirname}/royalty/UniqueRoyaltyHelper.sol`,63 },64 {65 solPath: 'royalty/UniqueRoyalty.sol',66 fsPath: `${dirname}/royalty/UniqueRoyalty.sol`,67 },68 {69 solPath: 'royalty/LibPart.sol',70 fsPath: `${dirname}/royalty/LibPart.sol`,71 },72 ],73 15000000,74 [1, 0],75 );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 });102});