Skip to content

Commit

Permalink
test: fixed asset value for fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Sep 26, 2023
1 parent 718bd7c commit aed513e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 159 deletions.
139 changes: 0 additions & 139 deletions packages/marketplace/test/exchange/Exchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,143 +207,4 @@ describe('Exchange.sol', function () {
)
).to.be.equal(UINT256_MAX_VALUE);
});

it('should be able to match two orders', async function () {
const {
ExchangeContractAsUser,
OrderValidatorAsDeployer,
ERC20Contract,
ERC721Contract,
user,
user2,
} = await loadFixture(deployFixtures);
await ERC721Contract.mint(user.address, 1);
await ERC721Contract.connect(user).approve(
await ExchangeContractAsUser.getAddress(),
1
);
await ERC20Contract.mint(user2.address, 100);
await ERC20Contract.connect(user2).approve(
await ExchangeContractAsUser.getAddress(),
100
);

const makerAsset = await AssetERC721(ERC721Contract, 1);
const takerAsset = await AssetERC20(ERC20Contract, 100);

const leftOrder = await OrderDefault(
user,
makerAsset,
ZeroAddress,
takerAsset,
1,
0,
0
);
const rightOrder = await OrderDefault(
user2,
takerAsset,
ZeroAddress,
makerAsset,
1,
0,
0
);

const makerSig = await signOrder(leftOrder, user, OrderValidatorAsDeployer);
const takerSig = await signOrder(
rightOrder,
user2,
OrderValidatorAsDeployer
);

await ExchangeContractAsUser.matchOrders(
leftOrder,
makerSig,
rightOrder,
takerSig
);

// TODO: Check balances before and after, validate everything!!!
});

// TODO remove
// it('should be able to execute direct purchase', async function () {
// const {
// ExchangeContractAsDeployer,
// OrderValidatorAsDeployer,
// ERC20Contract,
// ERC721Contract,
// deployer,
// user1,
// user2,
// } = await loadFixture(deployFixtures);
// await OrderValidatorAsDeployer.connect(deployer).setSigningWallet(
// deployer.address
// );
// await ERC721Contract.mint(user1.address, 1);
// await ERC20Contract.mint(user2.address, 100);
// await ERC721Contract.connect(user1).approve(
// await ExchangeContractAsDeployer.getAddress(),
// 1
// );

// const makerAsset = await AssetERC721(ERC721Contract, 1);
// const takerAsset = await AssetERC20(ERC20Contract, 100);
// const order = await OrderBack(
// user2,
// user1,
// makerAsset,
// ZeroAddress,
// takerAsset,
// 1,
// 0,
// 0,
// DEFAULT_ORDER_TYPE,
// '0x'
// );
// // const hash = await ExchangeContractAsDeployer.getBEHashKey(order);
// // const signature = await deployer.signMessage(hash);
// // const signature = await signOrderBack(
// // order,
// // deployer,
// // ExchangeContractAsDeployer
// // );
// const signature = await signOrderBack(
// order,
// deployer,
// OrderValidatorAsDeployer
// );
// // const timestamp = await time.latest();
// // const sellOrderStart = timestamp - 100000;
// // const sellOrderEnd = timestamp + 100000;

// const purchase = {
// sellOrderMaker: user1.address,
// sellOrderNftAmount: 1,
// nftAssetClass: makerAsset.assetType.assetClass,
// nftData: makerAsset.assetType.data,
// sellOrderPaymentAmount: 100,
// paymentToken: await ERC20Contract.getAddress(),
// sellOrderSalt: 1,
// sellOrderStart: 0,
// sellOrderEnd: 0,
// sellOrderDataType: order.dataType,
// sellOrderData: order.data,
// sellOrderSignature: signature,
// buyOrderPaymentAmount: 100,
// buyOrderNftAmount: 1,
// buyOrderData: getBytes('0x'), // TODO pass buy data
// };

// // TODO: WIP
// // TODO: We need to test orderValidator first, a call to setSigningWallet is needed ?
// // TODO: What is this backend signature stuff ?
// // const backendSignature = getBytes('0x');
// await ExchangeContractAsDeployer.directPurchase(
// user2.address,
// [purchase],
// [signature]
// );
// });
});
4 changes: 2 additions & 2 deletions packages/marketplace/test/exchange/OrderValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('OrderValidator.sol', function () {
user1,
} = await loadFixture(deployFixtures);

const makerAsset = await AssetERC721(ERC721Contract, 1);
const makerAsset = await AssetERC721(ERC721Contract, 1, 1);
const takerAsset = await AssetERC20(ERC20Contract, 100);
const order = await OrderBack(
user2,
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('OrderValidator.sol', function () {
user1,
} = await loadFixture(deployFixtures);

const makerAsset = await AssetERC721(ERC721Contract, 1);
const makerAsset = await AssetERC721(ERC721Contract, 1, 1);
const takerAsset = await AssetERC20(ERC20Contract, 100);
const order = await OrderBack(
user2,
Expand Down
37 changes: 19 additions & 18 deletions packages/marketplace/test/utils/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ export type AssetType = {

export type Asset = {
assetType: AssetType;
value: string;
value: number;
};

export const AssetETH = (amount: number): Asset => ({
export const AssetETH = (): Asset => ({
assetType: {
assetClass: ETH_ASSET_CLASS,
data: '0x',
},
value: amount.toString(),
value: 1,
});

export const AssetERC20 = async (
tokenContract: Contract,
amount: number
value: number
): Promise<Asset> => ({
assetType: {
assetClass: ERC20_ASSET_CLASS,
Expand All @@ -58,12 +58,13 @@ export const AssetERC20 = async (
[await tokenContract.getAddress()]
),
},
value: amount.toString(),
value: value,
});

export const AssetERC721 = async (
tokenContract: Contract,
tokenId: number
tokenId: number,
value: number
): Promise<Asset> => ({
assetType: {
assetClass: ERC721_ASSET_CLASS,
Expand All @@ -72,13 +73,13 @@ export const AssetERC721 = async (
[await tokenContract.getAddress(), tokenId]
),
},
value: '1',
value: value,
});

export const AssetERC1155 = async (
tokenContract: Contract,
tokenId: number,
amount: number
value: number
): Promise<Asset> => ({
assetType: {
assetClass: ERC1155_ASSET_CLASS,
Expand All @@ -87,35 +88,35 @@ export const AssetERC1155 = async (
[await tokenContract.getAddress(), tokenId]
),
},
value: amount.toString(),
value: value,
});

export const AssetBundle = async (
erc20: {tokenContract: Contract; amount: number}[],
erc721: {tokenContract: Contract; tokenId: number}[],
erc1155: {tokenContract: Contract; tokenId: number; amount: number}[]
erc20: {tokenContract: Contract; value: number}[],
erc721: {tokenContract: Contract; tokenId: number; value: number}[],
erc1155: {tokenContract: Contract; tokenId: number; value: number}[]
): Promise<Asset> => {
const erc20Details = [];
for (const x of erc20) {
erc20Details.push({
token: await x.tokenContract.getAddress(),
value: x.amount,
value: x.value,
});
}
const erc721Details = [];
const erc721Details: {token: string; id: number; value: number}[] = [];
for (const x of erc721) {
erc20Details.push({
token: await x.tokenContract.getAddress(),
id: x.tokenId,
value: '1',
value: x.value,
});
}
const erc1155Details = [];
const erc1155Details: {token: string; id: number; value: number}[] = [];
for (const x of erc1155) {
erc20Details.push({
token: await x.tokenContract.getAddress(),
id: x.tokenId,
value: x.amount,
value: x.value,
});
}
return {
Expand All @@ -130,7 +131,7 @@ export const AssetBundle = async (
[erc20Details, erc721Details, erc1155Details]
),
},
value: '1',
value: 1,
};
};

Expand Down

1 comment on commit aed513e

@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

11.70%

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.sol83.33%83.33%75%87.50%33, 56
   ExchangeCore.sol15.88%12.79%27.27%16%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, 73
   ExchangeMeta.sol0%0%0%0%33, 33–36, 42, 52, 56, 61, 61–62, 62, 62, 64
   OrderValidator.sol77.14%64.71%100%86.21%108–109, 114, 116, 116, 116, 116–117, 119, 37, 80, 87–88, 88, 88, 98
   WhiteList.sol97.62%93.75%100%100%50
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, 8–9
   RaribleTestHelper.sol0%100%0%0%11, 15, 19, 23, 33
   SimpleTransferManager.sol0%100%0%0%13–16
   TestAssetMatcher.sol0%0%0%0%12, 12, 12–15, 15, 15–16, 19
   TestERC1155WithRoyaltyV2981.sol100%100%100%100%
   TestERC1271.sol0%0%0%0%24, 28, 28, 28
   TestERC20.sol100%100%100%100%
   TestERC721.sol100%100%100%100%
   TestERC721WithRoyaltyV2981.sol100%100%100%100%
   TestERC721WithRoyaltyV2981Multi.sol100%100%100%100%
   TestMinimalForwarder.sol0%0%0%0%12–15, 15, 15–16
   TestRoyaltiesRegistry.sol0%0%0%0%21–23, 23, 23–24, 24, 24–26, 28, 28, 28–29, 33, 37–38, 38, 38–39, 41–42, 42, 42–44, 44–46, 50, 54, 62–65, 65, 65–66, 66, 66–68, 70, 70, 70–71
   TransferManagerTest.sol0%0%0%0%107, 110–111, 115–116, 119,

Please sign in to comment.