diff --git a/packages/marketplace/contracts/exchange/mocks/MockTrustedForwarder.sol b/packages/marketplace/contracts/exchange/mocks/MockTrustedForwarder.sol new file mode 100644 index 0000000000..9e1c0cf0e4 --- /dev/null +++ b/packages/marketplace/contracts/exchange/mocks/MockTrustedForwarder.sol @@ -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); + } +} diff --git a/packages/marketplace/test/exchange/AssetMatcher.test.ts b/packages/marketplace/test/exchange/AssetMatcher.test.ts index 8a9e9c9cbc..5374b7b1d9 100644 --- a/packages/marketplace/test/exchange/AssetMatcher.test.ts +++ b/packages/marketplace/test/exchange/AssetMatcher.test.ts @@ -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); @@ -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( @@ -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); + }); }); diff --git a/packages/marketplace/test/fixtures.ts b/packages/marketplace/test/fixtures.ts index 968e86ef36..22c9b44534 100644 --- a/packages/marketplace/test/fixtures.ts +++ b/packages/marketplace/test/fixtures.ts @@ -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);