Skip to content

Commit

Permalink
closes #227
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeard002 committed Jun 5, 2024
1 parent 718b4ca commit e84906a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {
swap.config
);

if (value > 0 && recipient == 0) {
if (value * 1e12 != msg.value) revert InvalidValue();
if (msg.value > 0) {
if (recipient == 0) {
if (value * 1e12 != msg.value) revert InvalidValue();
}
else revert InvalidSender();
}

emit SwapCreated(swapId, msg.sender, allowed);
Expand Down
5 changes: 5 additions & 0 deletions contracts/interfaces/IErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ interface IErrors {
* @dev Displayed when a low level call failed to execute.
*/
error InvalidCall();

/**
* @dev Displayed when the wrong caller sends ethers.
*/
error InvalidSender();
}
34 changes: 34 additions & 0 deletions test/TestSwaplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,40 @@ describe("Swaplace", async function () {
Swaplace.connect(owner).createSwap(swap, { value: 69 }),
).to.be.revertedWithCustomError(Swaplace, `InvalidValue`);
});

it("Should revert when the {owner} sends ethers while not being set as the {recipient}", async function () {
const bidingAddr = [MockERC20.address];
const bidingAmountOrId = [50];

const askingAddr = [
MockERC20.address,
MockERC20.address,
MockERC20.address,
];
const askingAmountOrId = [50, 100, 150];

const valueToSend: BigNumber = ethers.utils.parseEther("0.5");

const currentTimestamp = (await blocktimestamp()) + 1000000;
const config = await Swaplace.encodeConfig(
zeroAddress,
currentTimestamp,
1,
valueToSend.div(1e12),
);

const swap: Swap = await composeSwap(
owner.address,
config,
bidingAddr,
bidingAmountOrId,
askingAddr,
askingAmountOrId,
);
await expect(
Swaplace.connect(owner).createSwap(swap, { value: valueToSend }),
).to.be.revertedWithCustomError(Swaplace, `InvalidSender`);
});
});
});

Expand Down

0 comments on commit e84906a

Please sign in to comment.