From 11a5b682ba66f188d6e22c2de8bf5911776eb38c Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 9 Oct 2023 17:29:11 +0200 Subject: [PATCH] fixing 50 limit --- .../contracts/exchange/ExchangeCore.sol | 2 +- .../test/exchange/Exchange.test.ts | 34 +++++++++---------- packages/marketplace/test/fixtures.ts | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/marketplace/contracts/exchange/ExchangeCore.sol b/packages/marketplace/contracts/exchange/ExchangeCore.sol index 6d50fb8492..f892d05b51 100644 --- a/packages/marketplace/contracts/exchange/ExchangeCore.sol +++ b/packages/marketplace/contracts/exchange/ExchangeCore.sol @@ -110,7 +110,7 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana /// @dev validate orders through validateOrders before matchAndTransfer function _matchOrders(address sender, ExchangeMatch[] calldata matchedOrders) internal { uint256 len = matchedOrders.length; - require(len > 0 && len < matchOrdersLimit, "invalid exchange match quantities"); + require(len > 0 && len <= matchOrdersLimit, "invalid exchange match quantities"); for (uint256 i; i < len; i++) { ExchangeMatch calldata m = matchedOrders[i]; _validateOrders(sender, m.orderLeft, m.signatureLeft, m.orderRight, m.signatureRight); diff --git a/packages/marketplace/test/exchange/Exchange.test.ts b/packages/marketplace/test/exchange/Exchange.test.ts index 3ed2645fea..78410fbcf0 100644 --- a/packages/marketplace/test/exchange/Exchange.test.ts +++ b/packages/marketplace/test/exchange/Exchange.test.ts @@ -1880,7 +1880,7 @@ describe('Exchange.sol', function () { } }); - it('should be able to buy 100 tokens from different orders in one txs', async function () { + it('should be able to buy 50 tokens from different orders in one txs', async function () { const { ExchangeContractAsUser, OrderValidatorAsAdmin, @@ -1889,14 +1889,14 @@ describe('Exchange.sol', function () { user: taker, user2: maker, } = await loadFixture(deployFixtures); - const totalPayment = 10000; + const totalPayment = 5000; await ERC20Contract.mint(taker.address, totalPayment); await ERC20Contract.connect(taker).approve( await ExchangeContractAsUser.getAddress(), totalPayment ); - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 50; i++) { await ERC721Contract.mint(maker.address, i); await ERC721Contract.connect(maker).approve( await ExchangeContractAsUser.getAddress(), @@ -1907,14 +1907,14 @@ describe('Exchange.sol', function () { expect(await ERC20Contract.balanceOf(taker)).to.be.equal(totalPayment); expect(await ERC20Contract.balanceOf(maker)).to.be.equal(0); - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 50; i++) { expect(await ERC721Contract.ownerOf(i)).to.be.equal(maker.address); } - const takerAsset = await AssetERC20(ERC20Contract, totalPayment / 100); + const takerAsset = await AssetERC20(ERC20Contract, totalPayment / 50); const leftOrders = []; - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 50; i++) { const leftorder = await OrderDefault( maker, await AssetERC721(ERC721Contract, i), @@ -1928,7 +1928,7 @@ describe('Exchange.sol', function () { } const rightOrders = []; - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 50; i++) { const rightorder = { orderLeft: leftOrders[i], signatureLeft: await signOrder( @@ -1945,19 +1945,19 @@ describe('Exchange.sol', function () { const tx = await ExchangeContractAsUser.matchOrders(rightOrders); const receipt = await tx.wait(); - console.log('Gas used for 100 tokens: ' + receipt.gasUsed); + console.log('Gas used for 50 tokens: ' + receipt.gasUsed); expect(await ERC20Contract.balanceOf(taker)).to.be.equal(0); expect(await ERC20Contract.balanceOf(maker)).to.be.equal( - totalPayment - 2 * 100 + totalPayment - 2 * 50 ); - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 50; i++) { expect(await ERC721Contract.ownerOf(i)).to.be.equal(taker.address); } }); - it('should not be able to buy 150 tokens from different orders in one txs, max transfers = 150', async function () { + it('should not be able to buy 51 tokens from different orders in one txs, max transfers = 150', async function () { const { ExchangeContractAsUser, OrderValidatorAsAdmin, @@ -1966,14 +1966,14 @@ describe('Exchange.sol', function () { user: taker, user2: maker, } = await loadFixture(deployFixtures); - const totalPayment = 15000; + const totalPayment = 5100; await ERC20Contract.mint(taker.address, totalPayment); await ERC20Contract.connect(taker).approve( await ExchangeContractAsUser.getAddress(), totalPayment ); - for (let i = 0; i < 150; i++) { + for (let i = 0; i < 51; i++) { await ERC721Contract.mint(maker.address, i); await ERC721Contract.connect(maker).approve( await ExchangeContractAsUser.getAddress(), @@ -1984,14 +1984,14 @@ describe('Exchange.sol', function () { expect(await ERC20Contract.balanceOf(taker)).to.be.equal(totalPayment); expect(await ERC20Contract.balanceOf(maker)).to.be.equal(0); - for (let i = 0; i < 150; i++) { + for (let i = 0; i < 51; i++) { expect(await ERC721Contract.ownerOf(i)).to.be.equal(maker.address); } - const takerAsset = await AssetERC20(ERC20Contract, totalPayment / 150); + const takerAsset = await AssetERC20(ERC20Contract, totalPayment / 51); const leftOrders = []; - for (let i = 0; i < 150; i++) { + for (let i = 0; i < 51; i++) { const leftorder = await OrderDefault( maker, await AssetERC721(ERC721Contract, i), @@ -2005,7 +2005,7 @@ describe('Exchange.sol', function () { } const rightOrders = []; - for (let i = 0; i < 150; i++) { + for (let i = 0; i < 51; i++) { const rightorder = { orderLeft: leftOrders[i], signatureLeft: await signOrder( diff --git a/packages/marketplace/test/fixtures.ts b/packages/marketplace/test/fixtures.ts index 3746135c00..ffd016d3b8 100644 --- a/packages/marketplace/test/fixtures.ts +++ b/packages/marketplace/test/fixtures.ts @@ -38,7 +38,7 @@ async function deploy() { const OrderValidatorAsAdmin = await OrderValidatorAsDeployer.connect(admin); const protocolFeePrimary = 123; const protocolFeeSecondary = 250; - const matchOrdersLimit = 150; + const matchOrdersLimit = 50; const ExchangeFactory = await ethers.getContractFactory('Exchange'); const ExchangeContractAsDeployer = await upgrades.deployProxy( ExchangeFactory,