Skip to content

Commit

Permalink
fixed #181
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeard002 committed Jan 18, 2024
1 parent 41d7563 commit 2876230
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
* @dev See {ISwaplace-cancelSwap}.
*/
function cancelSwap(uint256 swapId) public {
Swap memory swap = _swaps[swapId];
if (_swaps[swapId].owner != msg.sender) revert InvalidAddress(msg.sender);

if (swap.owner != msg.sender) revert InvalidAddress(msg.sender);

(address allowed, uint256 expiry) = parseData(swap.config);
(, uint256 expiry) = parseData(_swaps[swapId].config);

if (expiry < block.timestamp) revert InvalidExpiry(expiry);

_swaps[swapId].config = packData(allowed, 0);
_swaps[swapId].config = 0;

emit SwapCanceled(swapId, msg.sender);
emit SwapCanceled(swapId);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ISwaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ISwaplace {
/**
* @dev Emitted when a Swap is canceled.
*/
event SwapCanceled(uint256 indexed swapId, address indexed owner);
event SwapCanceled(uint256 indexed swapId);

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

it("Should be able to {cancelSwap} a Swap", async function () {
const lastSwap = await Swaplace.totalSwaps();
expect(await Swaplace.connect(owner).cancelSwap(lastSwap))
await expect(await Swaplace.connect(owner).cancelSwap(lastSwap))
.to.emit(Swaplace, "SwapCanceled")
.withArgs(lastSwap, swap.owner);
.withArgs(lastSwap);
});

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

0 comments on commit 2876230

Please sign in to comment.