Skip to content

Commit

Permalink
test: Asset Matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Sep 21, 2023
1 parent 8f00ef8 commit 44f4775
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

contract MockTrustedForwarder {
struct ForwardRequest {
address from;
address to;
uint256 value;
uint256 gasLimit;
bytes data;
}

function execute(ForwardRequest calldata req) public payable returns (bool, bytes memory) {
(bool success, bytes memory returndata) = req.to.call{gas: req.gasLimit, value: req.value}(
abi.encodePacked(req.data, req.from)
);
assert(gasleft() > req.gasLimit / 63);
require(success, "Call execution failed");
return (success, returndata);
}
}
44 changes: 42 additions & 2 deletions packages/marketplace/test/exchange/AssetMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {expect} from 'chai';

const MOCK_ADDRESS_1 = '0x0000000000000000000000000000000000000001';

describe('AssetMatcher.sol', function () {
describe('AssetMatcher contract', function () {
it('setAssetMatcher should revert if msg sender is not owner', async function () {
const {assetMatcherAsUser} = await loadFixture(deployAssetMatcher);

Expand All @@ -13,7 +13,7 @@ describe('AssetMatcher.sol', function () {
).to.revertedWith('Ownable: caller is not the owner');
});

it('setAssetMatcher works', async function () {
it('setAssetMatcher should be able to set matcher address', async function () {
const {assetMatcherAsDeployer} = await loadFixture(deployAssetMatcher);

await expect(
Expand All @@ -22,4 +22,44 @@ describe('AssetMatcher.sol', function () {
.to.emit(assetMatcherAsDeployer, 'MatcherChange')
.withArgs('0x00000001', MOCK_ADDRESS_1);
});

it('matchAsset should revert if asset class do not match', async function () {
const {assetMatcherAsUser} = await loadFixture(deployAssetMatcher);

const leftAssetType = {assetClass: '0x00000001', data: '0x1234'};

const rightAssetType = {assetClass: '0x00000002', data: '0x1234'};
await expect(
assetMatcherAsUser.matchAssets(leftAssetType, rightAssetType)
).to.be.revertedWith('not found IAssetMatcher');
});

it('matchAsset should return the expected AssetType', async function () {
const {assetMatcherAsUser} = await loadFixture(deployAssetMatcher);

const leftAssetType = {assetClass: '0x00000001', data: '0x1234'};

const rightAssetType = {assetClass: '0x00000001', data: '0x1234'};
const result = await assetMatcherAsUser.matchAssets(
leftAssetType,
rightAssetType
);
expect(result[0]).to.be.equal(leftAssetType.assetClass);
expect(result[1]).to.be.equal(leftAssetType.data);
});

it('matchAsset should return null when data does not match', async function () {
const {assetMatcherAsUser} = await loadFixture(deployAssetMatcher);

const leftAssetType = {assetClass: '0x00000001', data: '0x1234'};

const rightAssetType = {assetClass: '0x00000001', data: '0x1254'};
const nullAsetType = {assetClass: '0x00000000', data: '0x'};
const result = await assetMatcherAsUser.matchAssets(
leftAssetType,
rightAssetType
);
expect(result[0]).to.be.equal(nullAsetType.assetClass);
expect(result[1]).to.be.equal(nullAsetType.data);
});
});
1 change: 0 additions & 1 deletion packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {ethers} from 'hardhat';

export async function deployAssetMatcher() {
const [deployer, user] = await ethers.getSigners();

const AssetMatcher = await ethers.getContractFactory('AssetMatcher');
const assetMatcherAsDeployer = await AssetMatcher.deploy();
const assetMatcherAsUser = await assetMatcherAsDeployer.connect(user);
Expand Down

1 comment on commit 44f4775

@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

2.62%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts/exchange
   AssetMatcher.sol56.16%46.67%100%58.97%49–50, 50, 50–51, 53, 55–56, 56, 56–57, 59, 61–62, 62, 62–63, 65, 67–68, 68, 68–69, 71, 73–74, 74, 74–75, 77, 80–81
   Exchange.sol0%0%0%0%33, 33–36, 42, 52, 56, 61, 61–62, 62, 62, 64
   ExchangeCore.sol0%0%0%0%101, 101–103, 105, 112, 112, 112–113, 113, 113–115, 115, 115–117, 129–132, 144, 146, 159, 159, 159, 161, 173, 184–186, 192, 194, 206, 218–219, 234–235, 249–251, 251, 251–252, 252, 252, 252, 252, 254, 254, 254–255, 255, 255, 255, 255, 263, 265, 271, 294–295, 297, 297, 297, 297, 297–298, 298, 298–299, 299, 299, 301, 301, 301–302, 302, 302–303, 303, 303–304, 304, 304–305, 307, 307–308, 308, 308–309, 309, 309–310, 332–333, 335–336, 336, 336–337, 339, 339, 339–340, 343–344, 346, 372–373, 396, 396, 396, 402, 405–407, 407, 407–409, 409, 409–410, 410–412, 412, 412, 414, 416, 416, 416, 418, 429, 432–433, 437–438, 441, 458–460, 469, 469, 469, 471, 471, 471–472, 472, 472–473, 475, 479, 479, 479–480, 480, 480–481, 483, 487, 489, 496, 496, 496–497, 499, 511–512, 512, 512–514, 514, 514, 523–524, 530–531, 531, 531–532, 534–535, 537, 544, 544, 544–545, 547, 547, 547–548, 550, 65–68, 73, 73–75, 77, 82, 82–84, 86, 94
   ExchangeMeta.sol0%0%0%0%33, 33–36, 42, 52, 56, 61, 61–62, 62, 62, 64
   OrderValidator.sol0%0%0%0%108, 108, 108–109, 114, 114, 114–116, 116, 116, 116–117, 119, 37, 37–39, 44, 44–45, 45, 45–46, 46, 46–47, 49, 55, 63–64, 66, 74, 74, 74–76, 79, 79, 79–80, 80, 80–81, 81, 81, 84, 84, 84–85, 87, 87, 87–88, 88, 88, 95, 95, 95–96, 98, 98, 98
   WhiteList.sol0%0%0%0%100, 100–101, 106, 106–107, 50, 50–57, 65, 65–69, 71, 76, 76–77, 82, 82–83, 88, 88–89, 94, 94–95
packages/marketplace/contracts/exchange/libraries
   LibDirectTransfer.sol100%100%100%100%
   LibFill.sol0%0%0%0%37, 42, 48, 48, 48–49, 51, 60–61, 61, 61–62, 71–72, 72, 72–73
   LibOrderDataGeneric.sol0%0%0%0%18, 18, 18–24, 24–28, 30, 30–31, 33, 33, 33–34, 39–42, 46, 48, 48, 48–49, 51–52, 55, 55, 55–56, 58, 61, 61, 61–62, 64, 67, 71, 73, 73, 73–75, 78, 87, 87, 87–89
packages/marketplace/contracts/exchange/mocks
   ERC1155LazyMintTest.sol100%100%100%100%
   ERC721LazyMintTest.sol100%100%100%100%
   ExchangeSimple.sol0%0%0%0%15, 15–17, 27, 31
   ExchangeSimple1.sol0%100%0%0%9
   ExchangeTestImports.sol100%100%100%100%
   LibFillTest.sol0%100%0%0%17
   LibOrderTest.sol0%100%0%0%13, 17, 21, 25, 35, 47
   MockTrustedForwarder.sol0%0%0%0%14, 17–18, 18, 18–19
   OrderValidatorTest.sol0%0%0%0%13, 8,

Please sign in to comment.