Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeard002 committed Jan 26, 2024
1 parent 0115342 commit b8c1636
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 5 additions & 3 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {

_swaps[swapId] = swap;

emit SwapCreated(swapId);
(address allowed,) = parseData(swap.config);

emit SwapCreated(swapId, swap.owner, allowed);

return swapId;
}
Expand Down Expand Up @@ -90,7 +92,7 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
}
}

emit SwapAccepted(swapId, msg.sender);
emit SwapAccepted(swapId, swap.owner, allowed);

return true;
}
Expand All @@ -107,7 +109,7 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {

_swaps[swapId].config = 0;

emit SwapCanceled(swapId);
emit SwapCanceled(swapId, _swaps[swapId].owner);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions contracts/interfaces/ISwaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ interface ISwaplace {
/**
* @dev Emitted when a new Swap is created.
*/
event SwapCreated(
uint256 indexed swapId
);
event SwapCreated(uint256 indexed swapId, address indexed owner, address indexed allowed);

/**
* @dev Emitted when a Swap is accepted.
*/
event SwapAccepted(uint256 indexed swapId, address indexed acceptee);
event SwapAccepted(uint256 indexed swapId, address indexed owner, address indexed allowed);

/**
* @dev Emitted when a Swap is canceled.
*/
event SwapCanceled(uint256 indexed swapId);
event SwapCanceled(uint256 indexed swapId, address indexed owner);

/**
* @dev Allow users to create a Swap. Each new Swap self-increments its ID by one.
Expand Down
28 changes: 14 additions & 14 deletions test/TestSwaplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to create a 1-N swap with ERC20", async function () {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to create a N-N swap with ERC20", async function () {
Expand Down Expand Up @@ -137,7 +137,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to create a 1-1 swap with ERC721", async function () {
Expand All @@ -161,7 +161,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to create a 1-N swap with ERC721", async function () {
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to create a N-N swap with ERC721", async function () {
Expand Down Expand Up @@ -221,7 +221,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});
});

Expand Down Expand Up @@ -276,7 +276,7 @@ describe("Swaplace", async function () {
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);
});

it("Should be able to {acceptSwap} as N-N Swap", async function () {
Expand All @@ -302,7 +302,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,zeroAddress);

await expect(
await Swaplace.connect(acceptee).acceptSwap(
Expand All @@ -311,7 +311,7 @@ describe("Swaplace", async function () {
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(),owner.address, zeroAddress);
});

it("Should be able to {acceptSwap} as P2P Swap", async function () {
Expand All @@ -329,7 +329,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,allowed);

await expect(
await Swaplace.connect(acceptee).acceptSwap(
Expand All @@ -338,7 +338,7 @@ describe("Swaplace", async function () {
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(),owner.address, allowed);
});
});

Expand All @@ -353,7 +353,7 @@ describe("Swaplace", async function () {
),
)
.to.emit(Swaplace, "SwapAccepted")
.withArgs(await Swaplace.totalSwaps(), acceptee.address);
.withArgs(await Swaplace.totalSwaps(), owner.address,zeroAddress);

await expect(
Swaplace.connect(acceptee).acceptSwap(
Expand Down Expand Up @@ -410,7 +410,7 @@ describe("Swaplace", async function () {

await expect(await Swaplace.connect(owner).createSwap(swap))
.to.emit(Swaplace, "SwapCreated")
.withArgs(await Swaplace.totalSwaps());
.withArgs(await Swaplace.totalSwaps(),owner.address,allowed);

await expect(
Swaplace.connect(acceptee).acceptSwap(
Expand All @@ -436,7 +436,7 @@ describe("Swaplace", async function () {
const lastSwap = await Swaplace.totalSwaps();
await expect(await Swaplace.connect(owner).cancelSwap(lastSwap))
.to.emit(Swaplace, "SwapCanceled")
.withArgs(lastSwap);
.withArgs(lastSwap,owner.address);
});

it("Should not be able to {acceptSwap} a canceled a Swap", async function () {
Expand Down

0 comments on commit b8c1636

Please sign in to comment.