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 6116935 commit b6dae89
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 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 @@ -273,10 +274,10 @@ describe("Swaplace", async function () {
it("Should be able to {acceptSwap} as 1-1 Swap", async function () {
await Swaplace.connect(owner).createSwap(swap);
await expect(
await Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps())
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 All @@ -303,10 +304,10 @@ describe("Swaplace", async function () {
.withArgs(await Swaplace.totalSwaps(), owner.address, swap.expiry);

await expect(
await Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps())
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 @@ -324,10 +325,10 @@ describe("Swaplace", async function () {
.withArgs(await Swaplace.totalSwaps(), owner.address, swap.expiry);

await expect(
await Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps())
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 @@ -336,13 +337,13 @@ describe("Swaplace", async function () {
await Swaplace.connect(owner).createSwap(swap);

await expect(
await Swaplace.connect(acceptee).acceptSwap(await Swaplace.totalSwaps())
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 @@ -354,7 +355,7 @@ 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 @@ -366,7 +367,7 @@ 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 @@ -385,7 +386,7 @@ 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 @@ -410,7 +411,7 @@ 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 b6dae89

Please sign in to comment.