From aed513e9100b0859d8ff927b5c0b97f474a26aa1 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Tue, 26 Sep 2023 15:56:16 +0530 Subject: [PATCH] test: fixed asset value for fixtures --- .../test/exchange/Exchange.test.ts | 139 ------------------ .../test/exchange/OrderValidator.test.ts | 4 +- packages/marketplace/test/utils/assets.ts | 37 ++--- 3 files changed, 21 insertions(+), 159 deletions(-) diff --git a/packages/marketplace/test/exchange/Exchange.test.ts b/packages/marketplace/test/exchange/Exchange.test.ts index 5c60bafdcc..520da350a5 100644 --- a/packages/marketplace/test/exchange/Exchange.test.ts +++ b/packages/marketplace/test/exchange/Exchange.test.ts @@ -207,143 +207,4 @@ describe('Exchange.sol', function () { ) ).to.be.equal(UINT256_MAX_VALUE); }); - - it('should be able to match two orders', async function () { - const { - ExchangeContractAsUser, - OrderValidatorAsDeployer, - ERC20Contract, - ERC721Contract, - user, - user2, - } = await loadFixture(deployFixtures); - await ERC721Contract.mint(user.address, 1); - await ERC721Contract.connect(user).approve( - await ExchangeContractAsUser.getAddress(), - 1 - ); - await ERC20Contract.mint(user2.address, 100); - await ERC20Contract.connect(user2).approve( - await ExchangeContractAsUser.getAddress(), - 100 - ); - - const makerAsset = await AssetERC721(ERC721Contract, 1); - const takerAsset = await AssetERC20(ERC20Contract, 100); - - const leftOrder = await OrderDefault( - user, - makerAsset, - ZeroAddress, - takerAsset, - 1, - 0, - 0 - ); - const rightOrder = await OrderDefault( - user2, - takerAsset, - ZeroAddress, - makerAsset, - 1, - 0, - 0 - ); - - const makerSig = await signOrder(leftOrder, user, OrderValidatorAsDeployer); - const takerSig = await signOrder( - rightOrder, - user2, - OrderValidatorAsDeployer - ); - - await ExchangeContractAsUser.matchOrders( - leftOrder, - makerSig, - rightOrder, - takerSig - ); - - // TODO: Check balances before and after, validate everything!!! - }); - - // TODO remove - // it('should be able to execute direct purchase', async function () { - // const { - // ExchangeContractAsDeployer, - // OrderValidatorAsDeployer, - // ERC20Contract, - // ERC721Contract, - // deployer, - // user1, - // user2, - // } = await loadFixture(deployFixtures); - // await OrderValidatorAsDeployer.connect(deployer).setSigningWallet( - // deployer.address - // ); - // await ERC721Contract.mint(user1.address, 1); - // await ERC20Contract.mint(user2.address, 100); - // await ERC721Contract.connect(user1).approve( - // await ExchangeContractAsDeployer.getAddress(), - // 1 - // ); - - // const makerAsset = await AssetERC721(ERC721Contract, 1); - // const takerAsset = await AssetERC20(ERC20Contract, 100); - // const order = await OrderBack( - // user2, - // user1, - // makerAsset, - // ZeroAddress, - // takerAsset, - // 1, - // 0, - // 0, - // DEFAULT_ORDER_TYPE, - // '0x' - // ); - // // const hash = await ExchangeContractAsDeployer.getBEHashKey(order); - // // const signature = await deployer.signMessage(hash); - // // const signature = await signOrderBack( - // // order, - // // deployer, - // // ExchangeContractAsDeployer - // // ); - // const signature = await signOrderBack( - // order, - // deployer, - // OrderValidatorAsDeployer - // ); - // // const timestamp = await time.latest(); - // // const sellOrderStart = timestamp - 100000; - // // const sellOrderEnd = timestamp + 100000; - - // const purchase = { - // sellOrderMaker: user1.address, - // sellOrderNftAmount: 1, - // nftAssetClass: makerAsset.assetType.assetClass, - // nftData: makerAsset.assetType.data, - // sellOrderPaymentAmount: 100, - // paymentToken: await ERC20Contract.getAddress(), - // sellOrderSalt: 1, - // sellOrderStart: 0, - // sellOrderEnd: 0, - // sellOrderDataType: order.dataType, - // sellOrderData: order.data, - // sellOrderSignature: signature, - // buyOrderPaymentAmount: 100, - // buyOrderNftAmount: 1, - // buyOrderData: getBytes('0x'), // TODO pass buy data - // }; - - // // TODO: WIP - // // TODO: We need to test orderValidator first, a call to setSigningWallet is needed ? - // // TODO: What is this backend signature stuff ? - // // const backendSignature = getBytes('0x'); - // await ExchangeContractAsDeployer.directPurchase( - // user2.address, - // [purchase], - // [signature] - // ); - // }); }); diff --git a/packages/marketplace/test/exchange/OrderValidator.test.ts b/packages/marketplace/test/exchange/OrderValidator.test.ts index 898a3446fc..2a7ebd7620 100644 --- a/packages/marketplace/test/exchange/OrderValidator.test.ts +++ b/packages/marketplace/test/exchange/OrderValidator.test.ts @@ -71,7 +71,7 @@ describe('OrderValidator.sol', function () { user1, } = await loadFixture(deployFixtures); - const makerAsset = await AssetERC721(ERC721Contract, 1); + const makerAsset = await AssetERC721(ERC721Contract, 1, 1); const takerAsset = await AssetERC20(ERC20Contract, 100); const order = await OrderBack( user2, @@ -106,7 +106,7 @@ describe('OrderValidator.sol', function () { user1, } = await loadFixture(deployFixtures); - const makerAsset = await AssetERC721(ERC721Contract, 1); + const makerAsset = await AssetERC721(ERC721Contract, 1, 1); const takerAsset = await AssetERC20(ERC20Contract, 100); const order = await OrderBack( user2, diff --git a/packages/marketplace/test/utils/assets.ts b/packages/marketplace/test/utils/assets.ts index 78fa484ad6..8bcc474049 100644 --- a/packages/marketplace/test/utils/assets.ts +++ b/packages/marketplace/test/utils/assets.ts @@ -36,20 +36,20 @@ export type AssetType = { export type Asset = { assetType: AssetType; - value: string; + value: number; }; -export const AssetETH = (amount: number): Asset => ({ +export const AssetETH = (): Asset => ({ assetType: { assetClass: ETH_ASSET_CLASS, data: '0x', }, - value: amount.toString(), + value: 1, }); export const AssetERC20 = async ( tokenContract: Contract, - amount: number + value: number ): Promise => ({ assetType: { assetClass: ERC20_ASSET_CLASS, @@ -58,12 +58,13 @@ export const AssetERC20 = async ( [await tokenContract.getAddress()] ), }, - value: amount.toString(), + value: value, }); export const AssetERC721 = async ( tokenContract: Contract, - tokenId: number + tokenId: number, + value: number ): Promise => ({ assetType: { assetClass: ERC721_ASSET_CLASS, @@ -72,13 +73,13 @@ export const AssetERC721 = async ( [await tokenContract.getAddress(), tokenId] ), }, - value: '1', + value: value, }); export const AssetERC1155 = async ( tokenContract: Contract, tokenId: number, - amount: number + value: number ): Promise => ({ assetType: { assetClass: ERC1155_ASSET_CLASS, @@ -87,35 +88,35 @@ export const AssetERC1155 = async ( [await tokenContract.getAddress(), tokenId] ), }, - value: amount.toString(), + value: value, }); export const AssetBundle = async ( - erc20: {tokenContract: Contract; amount: number}[], - erc721: {tokenContract: Contract; tokenId: number}[], - erc1155: {tokenContract: Contract; tokenId: number; amount: number}[] + erc20: {tokenContract: Contract; value: number}[], + erc721: {tokenContract: Contract; tokenId: number; value: number}[], + erc1155: {tokenContract: Contract; tokenId: number; value: number}[] ): Promise => { const erc20Details = []; for (const x of erc20) { erc20Details.push({ token: await x.tokenContract.getAddress(), - value: x.amount, + value: x.value, }); } - const erc721Details = []; + const erc721Details: {token: string; id: number; value: number}[] = []; for (const x of erc721) { erc20Details.push({ token: await x.tokenContract.getAddress(), id: x.tokenId, - value: '1', + value: x.value, }); } - const erc1155Details = []; + const erc1155Details: {token: string; id: number; value: number}[] = []; for (const x of erc1155) { erc20Details.push({ token: await x.tokenContract.getAddress(), id: x.tokenId, - value: x.amount, + value: x.value, }); } return { @@ -130,7 +131,7 @@ export const AssetBundle = async ( [erc20Details, erc721Details, erc1155Details] ), }, - value: '1', + value: 1, }; };