Skip to content

Commit

Permalink
test: [ISSUE-119] Change acceptSwap to support receiver parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjoaovpsantos committed Dec 19, 2023
1 parent 0960009 commit 3bc87fd
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions test/TestSwaplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Swaplace", async function () {
let deployer: SignerWithAddress;
let owner: SignerWithAddress;
let acceptee: SignerWithAddress;
let receiver: SignerWithAddress;

// Solidity address(0)
const zeroAddress = ethers.constants.AddressZero;
Expand Down Expand Up @@ -45,7 +46,7 @@ describe("Swaplace", async function () {
}

before(async () => {
[deployer, owner, acceptee] = await ethers.getSigners();
[deployer, owner, acceptee, receiver] = await ethers.getSigners();
Swaplace = await deploy("Swaplace", deployer);
MockERC20 = await deploy("MockERC20", deployer);
MockERC721 = await deploy("MockERC721", deployer);
Expand Down Expand Up @@ -275,10 +276,11 @@ describe("Swaplace", async function () {
await expect(
await Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(), receiver.address);
});

it("Should be able to {acceptSwap} as N-N Swap", async function () {
Expand Down Expand Up @@ -307,10 +309,11 @@ describe("Swaplace", async function () {
await expect(
await Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(), receiver.address);
});

it("Should be able to {acceptSwap} as P2P Swap", async function () {
Expand All @@ -330,10 +333,11 @@ describe("Swaplace", async function () {
await expect(
await Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(), receiver.address);
});
});

Expand All @@ -344,13 +348,17 @@ describe("Swaplace", async function () {
await expect(
await Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(), receiver.address);

await expect(
Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps()),
Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.be.revertedWithCustomError(Swaplace, `InvalidExpiry`)
.withArgs(0);
Expand All @@ -362,7 +370,10 @@ describe("Swaplace", async function () {
await network.provider.send("evm_increaseTime", [swap.expiry * 2]);

await expect(
Swaplace.connect(owner).acceptSwap(await Swaplace.totalSwaps()),
Swaplace.connect(owner).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.be.revertedWithCustomError(Swaplace, `InvalidExpiry`)
.withArgs(swap.expiry);
Expand All @@ -374,7 +385,10 @@ describe("Swaplace", async function () {
await Swaplace.connect(owner).createSwap(swap);

await expect(
Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps()),
Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
).to.be.revertedWith(`ERC721: caller is not token owner or approved`);
});

Expand All @@ -393,7 +407,10 @@ describe("Swaplace", async function () {
.withArgs(await Swaplace.totalSwaps(), owner.address, swap.expiry);

await expect(
Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps()),
Swaplace.connect(acceptee).acceptSwap(
await Swaplace.totalSwaps(),
receiver.address,
),
)
.to.be.revertedWithCustomError(Swaplace, "InvalidAddress")
.withArgs(acceptee.address);
Expand All @@ -418,7 +435,9 @@ describe("Swaplace", async function () {

it("Should not be able to {acceptSwap} a canceled a Swap", async function () {
const lastSwap = await Swaplace.totalSwaps();
await expect(Swaplace.connect(owner).acceptSwap(lastSwap))
await expect(
Swaplace.connect(owner).acceptSwap(lastSwap, receiver.address),
)
.to.be.revertedWithCustomError(Swaplace, `InvalidExpiry`)
.withArgs(0);
});
Expand Down

0 comments on commit 3bc87fd

Please sign in to comment.