From 2876230771ea2a85443f1b456724859bca3359d2 Mon Sep 17 00:00:00 2001 From: Deepu Date: Thu, 18 Jan 2024 22:42:05 +0530 Subject: [PATCH] fixed #181 --- contracts/Swaplace.sol | 10 ++++------ contracts/interfaces/ISwaplace.sol | 2 +- test/TestSwaplace.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/Swaplace.sol b/contracts/Swaplace.sol index 8e99cf1..26beb71 100644 --- a/contracts/Swaplace.sol +++ b/contracts/Swaplace.sol @@ -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); } /** diff --git a/contracts/interfaces/ISwaplace.sol b/contracts/interfaces/ISwaplace.sol index 44cfaa0..1304bd0 100644 --- a/contracts/interfaces/ISwaplace.sol +++ b/contracts/interfaces/ISwaplace.sol @@ -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. diff --git a/test/TestSwaplace.test.ts b/test/TestSwaplace.test.ts index aefe987..d37f8e5 100644 --- a/test/TestSwaplace.test.ts +++ b/test/TestSwaplace.test.ts @@ -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 () {