Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Created unit tests to build ERC1155 assets #218

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions contracts/echidna/TestSwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,4 @@ contract TestFactory is SwapFactory {
_asset
);
}

function echidna_revert_invalid_length() public view {
makeSwap(
address(0),
address(0),
uint32(block.timestamp + 100),
0,
0,
new Asset[](0),
new Asset[](0)
);
}
}
113 changes: 113 additions & 0 deletions test/TestSwapFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
composeSwap,
encodeConfig,
decodeConfig,
Swap,
} from "./utils/SwapFactory";
import { blocktimestamp, deploy } from "./utils/utils";

Expand All @@ -17,6 +18,7 @@ describe("Swaplace Factory", async function () {
let Swaplace: Contract;
let MockERC20: Contract;
let MockERC721: Contract;
let MockERC1155: Contract;

// The signers of the test
let deployer: SignerWithAddress;
Expand All @@ -30,6 +32,7 @@ describe("Swaplace Factory", async function () {
Swaplace = await deploy("Swaplace", deployer);
MockERC20 = await deploy("MockERC20", deployer);
MockERC721 = await deploy("MockERC721", deployer);
MockERC1155 = await deploy("MockERC1155", deployer);
});

it("Should be able to {makeAsset} for ERC20 and ERC721", async function () {
Expand Down Expand Up @@ -241,6 +244,116 @@ describe("Swaplace Factory", async function () {
expect(swap.asking[1]).to.be.equals(ERC721Asset);
});

it("Should be able to {makeSwap} with ERC1155 tokens", async function () {
const bidingAddr = [MockERC1155.address];
const tokenId = 1;
const amount = 3;
const amountAndId = await Swaplace.encodeAsset(tokenId, amount);
const bidingAmountOrId = [amountAndId];

const askingAddr = [MockERC721.address];
const askingAmountOrId = [50];

const ERC1155Asset: Asset = await makeAsset(
bidingAddr[0],
bidingAmountOrId[0],
);
const ERC721Asset: Asset = await makeAsset(
askingAddr[0],
askingAmountOrId[0],
);

const currentTimestamp = (await blocktimestamp()) + 1000000;
const config = await Swaplace.encodeConfig(
zeroAddress,
currentTimestamp,
0,
0,
);

const swap = await makeSwap(
owner.address,
config,
[ERC1155Asset],
[ERC721Asset],
);

const onChainSwap = await Swaplace.makeSwap(
owner.address,
zeroAddress,
currentTimestamp,
0,
0,
[ERC1155Asset],
[ERC721Asset],
);

const [allowed, expiry, recipient, value] = await Swaplace.decodeConfig(
swap.config,
);

const [onChainAllowed, onChainExpiry, onChainRecipient, onChainValue] =
await Swaplace.decodeConfig(onChainSwap.config);

expect(swap.owner).to.be.equals(onChainSwap.owner);
expect(expiry).to.be.equals(onChainExpiry);
expect(allowed).to.be.equals(onChainAllowed);
expect(recipient).to.be.equals(onChainRecipient);
expect(value).to.be.equals(onChainValue);
expect(swap.biding[0].addr).to.be.equals(onChainSwap.biding[0].addr);
expect(swap.biding[0].amountOrId).to.be.equals(
onChainSwap.biding[0].amountOrId,
);

expect(swap.asking[0].addr).to.be.equals(onChainSwap.asking[0].addr);
expect(swap.asking[0].amountOrId).to.be.equals(
onChainSwap.asking[0].amountOrId,
);
});

it("Should be able to {composeSwap} using ERC1155", async function () {
const bidingAddr = [MockERC1155.address];
const tokenId = 1;
const amount = 3;
const amountAndId = await Swaplace.encodeAsset(tokenId, amount);
const bidingAmountOrId = [amountAndId];

const askingAddr = [MockERC721.address];
const askingAmountOrId = [50];

const currentTimestamp = (await blocktimestamp()) + 1000000;
const config = await Swaplace.encodeConfig(
zeroAddress,
currentTimestamp,
0,
0,
);

const swap: Swap = await composeSwap(
owner.address,
config,
bidingAddr,
bidingAmountOrId,
askingAddr,
askingAmountOrId,
);

const [allowed, expiry, recipient, value] = await Swaplace.decodeConfig(
swap.config,
);

expect(swap.owner).to.be.equals(owner.address);
expect(allowed).to.be.equals(zeroAddress);
expect(expiry).to.be.equals(expiry);
expect(recipient).to.be.equals(0);
expect(value).to.be.equals(0);
expect(swap.biding[0].addr).to.be.equals(bidingAddr[0]);
expect(swap.biding[0].amountOrId).to.be.equals(bidingAmountOrId[0]);

expect(swap.asking[0].addr).to.be.equals(askingAddr[0]);
expect(swap.asking[0].amountOrId).to.be.equals(askingAmountOrId[0]);
});

it("Should be able to {composeSwap} using both ERC20, ERC721", async function () {
const currentTimestamp = (await blocktimestamp()) + 2000000;

Expand Down
Loading