Skip to content

Commit 4831c5f

Browse files
authored
Closes #209: Add event for incoming eth (#278)
1 parent bace2da commit 4831c5f

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

contracts/common/EtherPaymentFallback.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ pragma solidity >=0.7.0 <0.9.0;
66
/// @author Richard Meissner - <richard@gnosis.pm>
77
contract EtherPaymentFallback {
88

9+
event SafeReceived(address indexed sender, uint256 value);
10+
911
/// @dev Fallback function accepts Ether transactions.
1012
receive()
1113
external
1214
payable
1315
{
14-
16+
emit SafeReceived(msg.sender, msg.value);
1517
}
1618
}

test/core/GnosisSafe.Execution.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("GnosisSafe", async () => {
108108
it('should emit payment in success event', async () => {
109109
const { safe } = await setupTests()
110110
const tx = buildSafeTransaction({
111-
to: safe.address, nonce: await safe.nonce(), operation: 0, gasPrice: 1, safeTxGas: 100000, refundReceiver: user2.address
111+
to: user1.address, nonce: await safe.nonce(), operation: 0, gasPrice: 1, safeTxGas: 100000, refundReceiver: user2.address
112112
})
113113

114114
await user1.sendTransaction({ to: safe.address, value: parseEther("1") })
@@ -120,6 +120,7 @@ describe("GnosisSafe", async () => {
120120
executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]).then((tx) => { executedTx = tx; return tx })
121121
).to.emit(safe, "ExecutionSuccess")
122122
const receipt = await hre.ethers.provider.getTransactionReceipt(executedTx!!.hash)
123+
console.log(receipt.logs)
123124
const successEvent = safe.interface.decodeEventLog("ExecutionSuccess", receipt.logs[0].data, receipt.logs[0].topics)
124125
expect(successEvent.txHash).to.be.eq(calculateSafeTransactionHash(safe, tx, await chainId()))
125126
// Gas costs are around 3000, so even if we specified a safeTxGas from 100000 we should not use more

test/core/GnosisSafe.Incoming.spec.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ describe("GnosisSafe", async () => {
1818
function sendEth(address payable safe) public payable returns (bool success) {
1919
require(safe.send(msg.value));
2020
}
21+
function callEth(address payable safe) public payable returns (bool success) {
22+
(bool success,) = safe.call{ value: msg.value }("");
23+
require(success);
24+
}
2125
}`
2226
return {
2327
safe: await getSafeWithOwners([user1.address]),
@@ -30,23 +34,45 @@ describe("GnosisSafe", async () => {
3034
it('should be able to receive ETH via transfer', async () => {
3135
const { safe, caller } = await setupTests()
3236
// Notes: It is not possible to load storage + a call + emit event with 2300 gas
33-
// Test Validator
34-
await caller.transferEth(safe.address, { value: parseEther("1") })
35-
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
37+
await expect(
38+
caller.transferEth(safe.address, { value: parseEther("1") })
39+
).to.be.reverted
3640
})
3741

3842
it('should be able to receive ETH via send', async () => {
3943
const { safe, caller } = await setupTests()
4044
// Notes: It is not possible to load storage + a call + emit event with 2300 gas
41-
// Test Validator
42-
await caller.sendEth(safe.address, { value: parseEther("1") })
45+
await expect(
46+
caller.sendEth(safe.address, { value: parseEther("1") })
47+
).to.be.reverted
48+
})
49+
50+
it('should be able to receive ETH via call', async () => {
51+
const { safe, caller } = await setupTests()
52+
await expect(
53+
caller.callEth(safe.address, {
54+
value: parseEther("1")
55+
})
56+
).to.emit(safe, "SafeReceived").withArgs(caller.address, parseEther("1"))
57+
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
58+
})
59+
60+
61+
it('should be able to receive ETH via transaction', async () => {
62+
const { safe } = await setupTests()
63+
await expect(
64+
user1.sendTransaction({
65+
to: safe.address,
66+
value: parseEther("1")
67+
})
68+
).to.emit(safe, "SafeReceived").withArgs(user1.address, parseEther("1"))
4369
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
4470
})
4571

4672
it('should throw for incoming eth with data', async () => {
4773
const { safe } = await setupTests()
4874
await expect(
49-
user1.sendTransaction({to: safe.address, value: 23, data: "0xbaddad"})
75+
user1.sendTransaction({ to: safe.address, value: 23, data: "0xbaddad" })
5076
).to.be.revertedWith("fallback function is not payable and was called with value 23")
5177
})
5278
})

0 commit comments

Comments
 (0)