1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { expect } from "chai";
import hre, { deployments, ethers, waffle } from "hardhat";
import "@nomiclabs/hardhat-ethers";
import { getMock, getSafeWithOwners } from "../utils/setup";
import { safeApproveHash, buildSafeTransaction, buildSignatureBytes, executeTx, executeContractCallWithSigners } from "../../src/utils/execution";
import { parseEther } from "@ethersproject/units";
import { safeContractUnderTest } from "../utils/config";
describe("GnosisSafeL2", async () => {
before(function () {
if (safeContractUnderTest() != "GnosisSafeL2") {
this.skip()
}
});
const [user1, user2] = waffle.provider.getWallets();
const setupTests = deployments.createFixture(async ({ deployments }) => {
await deployments.fixture();
const mock = await getMock()
return {
safe: await getSafeWithOwners([user1.address]),
mock
}
})
describe("execTransactions", async () => {
it('should emit SafeMultiSigTransaction event', async () => {
const { safe } = await setupTests()
const tx = buildSafeTransaction({
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") })
await expect(await hre.ethers.provider.getBalance(safe.address)).to.be.deep.eq(parseEther("1"))
const additionalInfo = ethers.utils.defaultAbiCoder.encode(['uint256', 'address', 'uint256'], [tx.nonce, user1.address, 1])
const signatures = [await safeApproveHash(user1, safe, tx, true)]
const signatureBytes = buildSignatureBytes(signatures).toLowerCase()
let executedTx: any;
await expect(
executeTx(safe, tx, signatures).then((tx) => { executedTx = tx; return tx })
)
.to.emit(safe, "ExecutionSuccess")
.to.emit(safe, "SafeMultiSigTransaction")
.withArgs(
tx.to,
tx.value,
tx.data,
tx.operation,
tx.safeTxGas,
tx.baseGas,
tx.gasPrice,
tx.gasToken,
tx.refundReceiver,
signatureBytes,
additionalInfo
)
})
it('should emit SafeModuleTransaction event', async () => {
const { safe, mock } = await setupTests()
const user2Safe = safe.connect(user2)
await executeContractCallWithSigners(safe, safe, "enableModule", [user2.address], [user1])
await expect(
user2Safe.execTransactionFromModule(mock.address, 0, "0xbaddad", 0)
)
.to.emit(safe, "SafeModuleTransaction").withArgs(user2.address, mock.address, 0, "0xbaddad", 0)
.to.emit(safe, "ExecutionFromModuleSuccess").withArgs(user2.address)
})
})
})