Skip to content

Commit

Permalink
test: Rework tests (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShisui authored Apr 3, 2023
1 parent d147eda commit 72497ca
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 265 deletions.
38 changes: 21 additions & 17 deletions src/__tests__/looksrare/createMakerAsk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { SupportedChainId, CollectionType, StrategyType, QuoteType, CreateMakerI
describe("Create maker ask", () => {
let mocks: SetupMocks;
let signers: Signers;
let lrUser1: LooksRare;
let baseMakerAskInput: CreateMakerInput;

beforeEach(async () => {
mocks = await setUpContracts();
signers = await getSigners();

lrUser1 = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);

baseMakerAskInput = {
collection: mocks.contracts.collectionERC721.address,
collectionType: CollectionType.ERC721,
Expand All @@ -26,22 +30,22 @@ describe("Create maker ask", () => {
itemIds: [1],
};
});
it("create maker ask with wrong time format", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
await expect(
looksrare.createMakerAsk({ ...baseMakerAskInput, startTime: Date.now() })
).to.eventually.be.rejectedWith(ErrorTimestamp);
await expect(looksrare.createMakerAsk({ ...baseMakerAskInput, endTime: Date.now() })).to.eventually.be.rejectedWith(

it("throws an error when creating maker ask with wrong time format", async () => {
await expect(lrUser1.createMakerAsk({ ...baseMakerAskInput, startTime: Date.now() })).to.eventually.be.rejectedWith(
ErrorTimestamp
);
await expect(lrUser1.createMakerAsk({ ...baseMakerAskInput, endTime: Date.now() })).to.eventually.be.rejectedWith(
ErrorTimestamp
);
});

it("approvals checks are false if no approval was made", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const { isCollectionApproved, isTransferManagerApproved } = await looksrare.createMakerAsk(baseMakerAskInput);
const { isCollectionApproved, isTransferManagerApproved } = await lrUser1.createMakerAsk(baseMakerAskInput);
expect(isCollectionApproved).to.be.false;
expect(isTransferManagerApproved).to.be.false;

const tx = await looksrare.approveAllCollectionItems(baseMakerAskInput.collection);
const tx = await lrUser1.approveAllCollectionItems(baseMakerAskInput.collection);
await tx.wait();
const isApproved = await isApprovedForAll(
ethers.provider,
Expand All @@ -51,20 +55,20 @@ describe("Create maker ask", () => {
);
expect(isApproved).to.be.true;
});

it("approval checks are true if approval were made", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
let tx = await looksrare.approveAllCollectionItems(baseMakerAskInput.collection);
let tx = await lrUser1.approveAllCollectionItems(baseMakerAskInput.collection);
await tx.wait();
tx = await looksrare.grantTransferManagerApproval().call();
tx = await lrUser1.grantTransferManagerApproval().call();
await tx.wait();

const { isCollectionApproved, isTransferManagerApproved } = await looksrare.createMakerAsk(baseMakerAskInput);
const { isCollectionApproved, isTransferManagerApproved } = await lrUser1.createMakerAsk(baseMakerAskInput);
expect(isCollectionApproved).to.be.true;
expect(isTransferManagerApproved).to.be.true;
});

it("create a simple maker ask with default values", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const output = await looksrare.createMakerAsk(baseMakerAskInput);
const output = await lrUser1.createMakerAsk(baseMakerAskInput);
const makerOrder: Maker = {
quoteType: QuoteType.Ask,
globalNonce: constants.Zero,
Expand All @@ -84,8 +88,8 @@ describe("Create maker ask", () => {
};
expect(output.maker).to.eql(makerOrder);
});

it("create a simple maker ask with non default values", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const input = {
...baseMakerAskInput,
amounts: [1],
Expand All @@ -94,7 +98,7 @@ describe("Create maker ask", () => {
recipient: signers.user2.address,
additionalParameters: [],
};
const output = await looksrare.createMakerAsk(input);
const output = await lrUser1.createMakerAsk(input);
const makerOrder: Maker = {
quoteType: QuoteType.Ask,
globalNonce: constants.Zero,
Expand Down
36 changes: 20 additions & 16 deletions src/__tests__/looksrare/createMakerBid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import { SupportedChainId, CollectionType, StrategyType, QuoteType, CreateMakerI
describe("Create maker bid", () => {
let mocks: SetupMocks;
let signers: Signers;
let lrUser1: LooksRare;
let baseMakerInput: CreateMakerInput;

beforeEach(async () => {
mocks = await setUpContracts();
signers = await getSigners();

lrUser1 = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);

baseMakerInput = {
collection: mocks.contracts.collectionERC721.address,
collectionType: CollectionType.ERC721,
Expand All @@ -25,22 +30,21 @@ describe("Create maker bid", () => {
itemIds: [1],
};
});
it("create maker bid with wrong time format", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
await expect(looksrare.createMakerBid({ ...baseMakerInput, startTime: Date.now() })).to.eventually.be.rejectedWith(

it("throws an error when creating maker bid with wrong time format", async () => {
await expect(lrUser1.createMakerBid({ ...baseMakerInput, startTime: Date.now() })).to.eventually.be.rejectedWith(
ErrorTimestamp
);
await expect(looksrare.createMakerBid({ ...baseMakerInput, endTime: Date.now() })).to.eventually.be.rejectedWith(
await expect(lrUser1.createMakerBid({ ...baseMakerInput, endTime: Date.now() })).to.eventually.be.rejectedWith(
ErrorTimestamp
);
});
it("approvals checks are false if no approval was made", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const { isCurrencyApproved } = await looksrare.createMakerBid(baseMakerInput);

it("approvals checks are false if no approval was made", async () => {
const { isCurrencyApproved } = await lrUser1.createMakerBid(baseMakerInput);
expect(isCurrencyApproved).to.be.false;

await looksrare.approveErc20(looksrare.addresses.WETH);
await lrUser1.approveErc20(mocks.addresses.WETH);
const valueApproved = await allowance(
ethers.provider,
mocks.addresses.WETH,
Expand All @@ -49,16 +53,16 @@ describe("Create maker bid", () => {
);
expect(valueApproved.eq(constants.MaxUint256)).to.be.true;
});

it("approval checks are true if approval were made", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const tx = await looksrare.approveErc20(looksrare.addresses.WETH);
const tx = await lrUser1.approveErc20(mocks.addresses.WETH);
await tx.wait();
const { isCurrencyApproved } = await looksrare.createMakerBid(baseMakerInput);
const { isCurrencyApproved } = await lrUser1.createMakerBid(baseMakerInput);
expect(isCurrencyApproved).to.be.true;
});

it("create a simple maker bid with default values", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const output = await looksrare.createMakerBid(baseMakerInput);
const output = await lrUser1.createMakerBid(baseMakerInput);
const makerOrder: Maker = {
quoteType: QuoteType.Bid,
globalNonce: constants.Zero,
Expand All @@ -69,7 +73,7 @@ describe("Create maker bid", () => {
collection: baseMakerInput.collection,
currency: mocks.addresses.WETH,
signer: signers.user1.address,
startTime: output.maker.startTime, // Can't really test the Date.now( executed inside the function)
startTime: output.maker.startTime, // Can't really test the Date.now (executed inside the function)
endTime: baseMakerInput.endTime,
price: baseMakerInput.price,
itemIds: baseMakerInput.itemIds,
Expand All @@ -78,8 +82,8 @@ describe("Create maker bid", () => {
};
expect(output.maker).to.eql(makerOrder);
});

it("create a simple maker bid with non default values", async () => {
const looksrare = new LooksRare(SupportedChainId.HARDHAT, ethers.provider, signers.user1, mocks.addresses);
const input = {
...baseMakerInput,
amounts: [1],
Expand All @@ -88,7 +92,7 @@ describe("Create maker bid", () => {
recipient: signers.user2.address,
additionalParameters: [],
};
const output = await looksrare.createMakerBid(input);
const output = await lrUser1.createMakerBid(input);
const makerOrder: Maker = {
quoteType: QuoteType.Bid,
globalNonce: constants.Zero,
Expand Down
Loading

0 comments on commit 72497ca

Please sign in to comment.