Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMSg authored and mvanmeerbeck committed Oct 4, 2023
1 parent 9cb0c51 commit 06b79b6
Showing 1 changed file with 308 additions and 0 deletions.
308 changes: 308 additions & 0 deletions packages/marketplace/test/exchange/Exchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,314 @@ describe('Exchange.sol', function () {
])
).to.be.revertedWith('not allowed');
});

it('should allow ERC721 tokens exchange if tsbOnly is activated and token is whitelisted', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsAdmin,
ERC20Contract,
ERC721WithRoyaltyV2981,
deployer: maker, // making deployer the maker to sell in primary market
user2: taker,
} = await loadFixture(deployFixtures);

await ERC721WithRoyaltyV2981.mint(maker.address, 1, [
await FeeRecipientsData(maker.address, 10000),
]);

await ERC721WithRoyaltyV2981.connect(maker).approve(
await ExchangeContractAsUser.getAddress(),
1
);
await ERC20Contract.mint(taker.address, 100000000000);
await ERC20Contract.connect(taker).approve(
await ExchangeContractAsUser.getAddress(),
100000000000
);

expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal(
maker.address
);
expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal(
100000000000
);
const makerAsset = await AssetERC721(ERC721WithRoyaltyV2981, 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, OrderValidatorAsAdmin);
const takerSig = await signOrder(
orderRight,
taker,
OrderValidatorAsAdmin
);

expect(
await ExchangeContractAsUser.fills(hashKey(orderLeft))
).to.be.equal(0);
expect(
await ExchangeContractAsUser.fills(hashKey(orderRight))
).to.be.equal(0);

await OrderValidatorAsAdmin.setPermissions(true, false, false, false);
await OrderValidatorAsAdmin.addTSB(ERC721WithRoyaltyV2981);

await ExchangeContractAsUser.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
]);
});

it('should NOT allow ERC721 tokens exchange if partners is activated and token is not whitelisted', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsAdmin,
ERC20Contract,
ERC721WithRoyaltyV2981,
deployer: maker, // making deployer the maker to sell in primary market
user2: taker,
} = await loadFixture(deployFixtures);

await ERC721WithRoyaltyV2981.mint(maker.address, 1, [
await FeeRecipientsData(maker.address, 10000),
]);

await ERC721WithRoyaltyV2981.connect(maker).approve(
await ExchangeContractAsUser.getAddress(),
1
);
await ERC20Contract.mint(taker.address, 100000000000);
await ERC20Contract.connect(taker).approve(
await ExchangeContractAsUser.getAddress(),
100000000000
);

expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal(
maker.address
);
expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal(
100000000000
);
const makerAsset = await AssetERC721(ERC721WithRoyaltyV2981, 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, OrderValidatorAsAdmin);
const takerSig = await signOrder(
orderRight,
taker,
OrderValidatorAsAdmin
);

expect(
await ExchangeContractAsUser.fills(hashKey(orderLeft))
).to.be.equal(0);
expect(
await ExchangeContractAsUser.fills(hashKey(orderRight))
).to.be.equal(0);

await OrderValidatorAsAdmin.setPermissions(false, true, false, false);

await expect(
ExchangeContractAsUser.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
])
).to.be.revertedWith('not allowed');
});

it('should allow ERC721 tokens exchange if partners is activated and token is whitelisted', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsAdmin,
ERC20Contract,
ERC721WithRoyaltyV2981,
deployer: maker, // making deployer the maker to sell in primary market
user2: taker,
} = await loadFixture(deployFixtures);

await ERC721WithRoyaltyV2981.mint(maker.address, 1, [
await FeeRecipientsData(maker.address, 10000),
]);

await ERC721WithRoyaltyV2981.connect(maker).approve(
await ExchangeContractAsUser.getAddress(),
1
);
await ERC20Contract.mint(taker.address, 100000000000);
await ERC20Contract.connect(taker).approve(
await ExchangeContractAsUser.getAddress(),
100000000000
);

expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal(
maker.address
);
expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal(
100000000000
);
const makerAsset = await AssetERC721(ERC721WithRoyaltyV2981, 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, OrderValidatorAsAdmin);
const takerSig = await signOrder(
orderRight,
taker,
OrderValidatorAsAdmin
);

expect(
await ExchangeContractAsUser.fills(hashKey(orderLeft))
).to.be.equal(0);
expect(
await ExchangeContractAsUser.fills(hashKey(orderRight))
).to.be.equal(0);

await OrderValidatorAsAdmin.setPermissions(false, true, false, false);
await OrderValidatorAsAdmin.addPartner(ERC721WithRoyaltyV2981);

await ExchangeContractAsUser.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
]);
});

it('should allow ERC721 tokens exchange if tsbOnly and partners are activated but so is open', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsAdmin,
ERC20Contract,
ERC721WithRoyaltyV2981,
deployer: maker, // making deployer the maker to sell in primary market
user2: taker,
} = await loadFixture(deployFixtures);

await ERC721WithRoyaltyV2981.mint(maker.address, 1, [
await FeeRecipientsData(maker.address, 10000),
]);

await ERC721WithRoyaltyV2981.connect(maker).approve(
await ExchangeContractAsUser.getAddress(),
1
);
await ERC20Contract.mint(taker.address, 100000000000);
await ERC20Contract.connect(taker).approve(
await ExchangeContractAsUser.getAddress(),
100000000000
);

expect(await ERC721WithRoyaltyV2981.ownerOf(1)).to.be.equal(
maker.address
);
expect(await ERC20Contract.balanceOf(taker.address)).to.be.equal(
100000000000
);
const makerAsset = await AssetERC721(ERC721WithRoyaltyV2981, 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, OrderValidatorAsAdmin);
const takerSig = await signOrder(
orderRight,
taker,
OrderValidatorAsAdmin
);

expect(
await ExchangeContractAsUser.fills(hashKey(orderLeft))
).to.be.equal(0);
expect(
await ExchangeContractAsUser.fills(hashKey(orderRight))
).to.be.equal(0);

await OrderValidatorAsAdmin.setPermissions(true, true, true, false);

await ExchangeContractAsUser.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
]);
});
});
// TODO
// describe("test match from", function () {});
Expand Down

1 comment on commit 06b79b6

@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

87.07%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts/exchange
   Exchange.sol79.71%70%87.50%86.96%171, 63, 79, 89, 89, 89, 89–90, 90, 90–91, 98
   ExchangeCore.sol84.81%61.54%100%95.45%118–119, 119, 119, 122, 188, 190, 194, 215–216, 64, 94
   OrderValidator.sol89.29%84.62%100%92%41, 71–72, 72, 72, 76
   WhiteList.sol97.67%93.75%100%100%63
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
   IAssetMatcher.sol100%100%100%100%
   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%166–167, 170–171, 212, 216, 247, 250, 256, 259, 276, 60
packages/marketplace/contracts/transfer-manager
   TransferExecutor.sol90.48%75%100%100%24, 30
   TransferManager.sol81.65%68.97%100%87.50%137, 190, 199, 206–207, 207, 207–208, 212, 220, 227–228, 252, 269, 273–275, 275, 275–277, 282–283, 306, 310–311, 62, 82–83
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.