From 22d32bb383aa22169c813eb32f0e824d90828cd4 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Wed, 4 Oct 2023 13:00:02 +0530 Subject: [PATCH] test: transfer complete royalty to royaltyReceiver for type 3 --- .../test/exchange/Exchange.test.ts | 116 +++++++++++++++++- packages/marketplace/test/fixtures.ts | 13 ++ 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/packages/marketplace/test/exchange/Exchange.test.ts b/packages/marketplace/test/exchange/Exchange.test.ts index 5ba7ef4548..cb32e48449 100644 --- a/packages/marketplace/test/exchange/Exchange.test.ts +++ b/packages/marketplace/test/exchange/Exchange.test.ts @@ -684,7 +684,121 @@ describe('Exchange.sol', function () { ); }); - it('should execute a complete match order with royalties 2981(type 3)', async function () { + it('should execute a complete match order with royalties 2981(type 3) transferred to royaltyReceiver', async function () { + const { + ExchangeContractAsUser, + OrderValidatorAsDeployer, + ERC20Contract, + ERC721WithRoyalty, + defaultFeeReceiver, + deployer: royaltyReceiver, + user1: maker, + user2: taker, + admin: receiver1, + user: receiver2, + } = await loadFixture(deployFixtures); + + // set royalty + await ERC721WithRoyalty.setRoyalties(5000); + + const fees = [ + {account: receiver1.address, value: 4000}, + {account: receiver2.address, value: 5000}, + ]; + await ERC721WithRoyalty.mint(maker.address, 1, fees); + + await ERC721WithRoyalty.connect(maker).approve( + await ExchangeContractAsUser.getAddress(), + 1 + ); + + // set up receiver + await ERC721WithRoyalty.setRoyaltiesReceiver(1, royaltyReceiver.address); + + await ERC20Contract.mint(taker.address, 100000000000); + await ERC20Contract.connect(taker).approve( + await ExchangeContractAsUser.getAddress(), + 100000000000 + ); + + expect(await ERC721WithRoyalty.ownerOf(1)).to.be.equal(maker.address); + expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal( + 100000000000 + ); + const makerAsset = await AssetERC721(ERC721WithRoyalty, 1); + const takerAsset = await AssetERC20(ERC20Contract, 100000000000); + const orderLeft = await OrderDefault( + maker, + makerAsset, + ZeroAddress, + takerAsset, + 1, + 0, + 0 + ); + const orderRight = await OrderDefault( + taker, + takerAsset, + ZeroAddress, + makerAsset, + 1, + 0, + 0 + ); + const makerSig = await signOrder( + orderLeft, + maker, + OrderValidatorAsDeployer + ); + const takerSig = await signOrder( + orderRight, + taker, + OrderValidatorAsDeployer + ); + + expect(await ExchangeContractAsUser.fills(hashKey(orderLeft))).to.be.equal( + 0 + ); + expect(await ExchangeContractAsUser.fills(hashKey(orderRight))).to.be.equal( + 0 + ); + + await ExchangeContractAsUser.matchOrders([ + { + orderLeft, + signatureLeft: makerSig, + orderRight, + signatureRight: takerSig, + }, + ]); + + expect(await ExchangeContractAsUser.fills(hashKey(orderLeft))).to.be.equal( + 100000000000 + ); + expect(await ExchangeContractAsUser.fills(hashKey(orderRight))).to.be.equal( + 1 + ); + expect(await ERC721WithRoyalty.ownerOf(1)).to.be.equal(taker.address); + + // check primary market protocol fee + expect( + await ERC20Contract.balanceOf(defaultFeeReceiver.address) + ).to.be.equal(2500000000); // 250 * 100000000000 / 10000 = 2500000000 + + expect(await ERC20Contract.balanceOf(receiver1.address)).to.be.equal(0); + + expect(await ERC20Contract.balanceOf(receiver2.address)).to.be.equal(0); + + expect(await ERC20Contract.balanceOf(royaltyReceiver.address)).to.be.equal( + 50000000000 // 5000 * 100000000000 / 10000 = 50000000000 + ); + + expect(await ERC20Contract.balanceOf(maker.address)).to.be.equal( + 47500000000 // 100000000000 - royalty - protocolFee + ); + }); + + it('should execute a complete match order with royalties 2981(type 3) transferred to fee recipients', async function () { const { ExchangeContractAsUser, OrderValidatorAsAdmin, diff --git a/packages/marketplace/test/fixtures.ts b/packages/marketplace/test/fixtures.ts index 286cf7f52a..58c540e6ac 100644 --- a/packages/marketplace/test/fixtures.ts +++ b/packages/marketplace/test/fixtures.ts @@ -77,6 +77,18 @@ async function deploy() { ); await ERC721WithRoyaltyV2981.waitForDeployment(); + const TestERC721WithRoyaltyFactory = await ethers.getContractFactory( + 'TestERC721WithRoyaltyV2981' + ); + const ERC721WithRoyalty = await upgrades.deployProxy( + TestERC721WithRoyaltyFactory, + [], + { + initializer: 'initialize', + } + ); + await ERC721WithRoyalty.waitForDeployment(); + const ERC20ContractFactory = await ethers.getContractFactory('TestERC20'); const ERC20Contract = await ERC20ContractFactory.deploy(); await ERC20Contract.waitForDeployment(); @@ -123,6 +135,7 @@ async function deploy() { RoyaltiesRegistryAsDeployer, RoyaltiesRegistryAsUser, ERC721WithRoyaltyV2981, + ERC721WithRoyalty, RoyaltiesProvider, deployer, admin,