Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #209: Add event for incoming eth #278

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contracts/common/EtherPaymentFallback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ pragma solidity >=0.7.0 <0.9.0;
/// @author Richard Meissner - <[email protected]>
contract EtherPaymentFallback {

event Received(address indexed sender, uint256 value);
rmeissner marked this conversation as resolved.
Show resolved Hide resolved

/// @dev Fallback function accepts Ether transactions.
receive()
external
payable
{

emit Received(msg.sender, msg.value);
}
}
3 changes: 2 additions & 1 deletion test/core/GnosisSafe.Execution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("GnosisSafe", async () => {
it('should emit payment in success event', async () => {
const { safe } = await setupTests()
const tx = buildSafeTransaction({
to: safe.address, nonce: await safe.nonce(), operation: 0, gasPrice: 1, safeTxGas: 100000, refundReceiver: user2.address
to: user1.address, nonce: await safe.nonce(), operation: 0, gasPrice: 1, safeTxGas: 100000, refundReceiver: user2.address
})

await user1.sendTransaction({ to: safe.address, value: parseEther("1") })
Expand All @@ -120,6 +120,7 @@ describe("GnosisSafe", async () => {
executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]).then((tx) => { executedTx = tx; return tx })
).to.emit(safe, "ExecutionSuccess")
const receipt = await hre.ethers.provider.getTransactionReceipt(executedTx!!.hash)
console.log(receipt.logs)
const successEvent = safe.interface.decodeEventLog("ExecutionSuccess", receipt.logs[0].data, receipt.logs[0].topics)
expect(successEvent.txHash).to.be.eq(calculateSafeTransactionHash(safe, tx, await chainId()))
// Gas costs are around 3000, so even if we specified a safeTxGas from 100000 we should not use more
Expand Down
38 changes: 32 additions & 6 deletions test/core/GnosisSafe.Incoming.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe("GnosisSafe", async () => {
function sendEth(address payable safe) public payable returns (bool success) {
require(safe.send(msg.value));
}
function callEth(address payable safe) public payable returns (bool success) {
(bool success,) = safe.call{ value: msg.value }("");
require(success);
}
}`
return {
safe: await getSafeWithOwners([user1.address]),
Expand All @@ -30,23 +34,45 @@ describe("GnosisSafe", async () => {
it('should be able to receive ETH via transfer', async () => {
const { safe, caller } = await setupTests()
// Notes: It is not possible to load storage + a call + emit event with 2300 gas
// Test Validator
await caller.transferEth(safe.address, { value: parseEther("1") })
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
await expect(
caller.transferEth(safe.address, { value: parseEther("1") })
).to.be.reverted
})

it('should be able to receive ETH via send', async () => {
const { safe, caller } = await setupTests()
// Notes: It is not possible to load storage + a call + emit event with 2300 gas
// Test Validator
await caller.sendEth(safe.address, { value: parseEther("1") })
await expect(
caller.sendEth(safe.address, { value: parseEther("1") })
).to.be.reverted
})

it('should be able to receive ETH via call', async () => {
const { safe, caller } = await setupTests()
await expect(
caller.callEth(safe.address, {
value: parseEther("1")
})
).to.emit(safe, "Received").withArgs(caller.address, parseEther("1"))
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
})


it('should be able to receive ETH via transaction', async () => {
const { safe } = await setupTests()
await expect(
user1.sendTransaction({
to: safe.address,
value: parseEther("1")
})
).to.emit(safe, "Received").withArgs(user1.address, parseEther("1"))
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
})

it('should throw for incoming eth with data', async () => {
const { safe } = await setupTests()
await expect(
user1.sendTransaction({to: safe.address, value: 23, data: "0xbaddad"})
user1.sendTransaction({ to: safe.address, value: 23, data: "0xbaddad" })
).to.be.revertedWith("fallback function is not payable and was called with value 23")
})
})
Expand Down