Skip to content

Commit

Permalink
fix: ensure no ETH sent for non-ETH transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebrugel committed Dec 21, 2021
1 parent 7439b8d commit e04b783
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/NestedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato
weth.deposit{ value: msg.value }();
_inputToken = IERC20(address(weth));
} else {
require(msg.value == 0, "NF: UNSUPPORTED_ETH_TRANSFER");
_inputToken.safeTransferFrom(_msgSender(), address(this), _inputTokenAmount);
}
tokenUsed = _inputToken;
Expand Down
18 changes: 18 additions & 0 deletions test/unit/NestedFactory.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ describe("NestedFactory", () => {
).to.be.reverted;
});

it("reverts if ETH sent for non-ETH transfer", async () => {
// All the amounts for this test
const uniBought = appendDecimals(6);
const kncBought = appendDecimals(4);
const totalToBought = uniBought.add(kncBought);
const expectedFee = getExpectedFees(totalToBought);
const totalToSpend = totalToBought.add(expectedFee);

// Orders for UNI and KNC
let orders: OrderStruct[] = getUniAndKncWithDaiOrders(uniBought, kncBought);

await expect(
context.nestedFactory
.connect(context.user1)
.create(0, context.mockDAI.address, totalToSpend, orders, {value: 1}),
).to.be.revertedWith("NF: UNSUPPORTED_ETH_TRANSFER");
});

it("Creates NFT from DAI with KNI and UNI inside (ZeroExOperator) with right amounts", async () => {
// All the amounts for this test
const uniBought = appendDecimals(6);
Expand Down

0 comments on commit e04b783

Please sign in to comment.