Skip to content

Commit

Permalink
fixing 50 limit
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMSg committed Oct 9, 2023
1 parent 53a2cda commit 11a5b68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/marketplace/contracts/exchange/ExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions packages/marketplace/test/exchange/Exchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

1 comment on commit 11a5b68

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

86.99%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts/exchange
   Exchange.sol80.82%71.88%88.24%87.50%100, 182, 64, 80, 91, 91, 91, 91–92, 92, 92–93
   ExchangeCore.sol87.21%67.86%100%95.83%137–138, 138, 138, 141, 207, 209, 213, 234–235, 74
   OrderValidator.sol89.29%84.62%100%92%41, 71–72, 72, 72, 76
   WhiteList.sol97.62%93.75%100%100%64
packages/marketplace/contracts/exchange/libraries
   LibFill.sol60.87%33.33%75%69.23%32–33, 58, 68–69, 69, 69–70
   LibMath.sol27.50%18.75%50%30%100–103, 17–18, 33–34, 50, 50, 50–51, 72, 72, 72–73, 75, 88, 88, 88–89, 93, 93, 93, 93, 93, 97
packages/marketplace/contracts/interfaces
   IOrderValidator.sol100%100%100%100%
   IRoyaltiesProvider.sol100%100%100%100%
   IWhiteList.sol100%100%100%100%
packages/marketplace/contracts/lib-asset
   LibAsset.sol100%100%100%100%
packages/marketplace/contracts/lib-bp
   BpLibrary.sol100%100%100%100%
packages/marketplace/contracts/lib-order
   LibOrder.sol73.33%50%100%100%64, 64, 66, 66
packages/marketplace/contracts/lib-part
   LibPart.sol0%100%0%0%21
packages/marketplace/contracts/royalties
   IERC2981.sol100%100%100%100%
   LibRoyalties2981.sol78.57%50%100%88.89%19–20, 23
packages/marketplace/contracts/royalties-registry
   IMultiRoyaltyRecipients.sol100%100%100%100%
   RoyaltiesRegistry.sol90.40%85.29%100%90.79%158, 162, 208–209, 212–213, 247, 250, 256, 259, 276, 60
packages/marketplace/contracts/transfer-manager
   TransferExecutor.sol90.48%75%100%100%25, 31
   TransferManager.sol80.41%65.38%100%86.75%100–101, 174, 177, 180–181, 181, 181–182, 186, 194, 201–202, 226, 243, 247–249, 249, 249–251, 256–257, 280, 284–285, 293, 63
packages/marketplace/contracts/transfer-manager/interfaces
   IRoyaltyUGC.sol100%100%100%100%
   ITransferExecutor.sol100%100%100%100%
   ITransferManager.sol100%100%100%100%

Please sign in to comment.