Skip to content

Commit 1a9e5ce

Browse files
authored
Merge pull request #124 from gnosis/issue-123
Emit event when master copy changes
2 parents 37c46f5 + a2ce121 commit 1a9e5ce

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

contracts/common/MasterCopy.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import "./SelfAuthorized.sol";
66
/// This contract is tightly coupled to our proxy contract (see `proxies/Proxy.sol`)
77
/// @author Richard Meissner - <richard@gnosis.io>
88
contract MasterCopy is SelfAuthorized {
9+
10+
event ChangedMasterCopy(address masterCopy);
11+
912
// masterCopy always needs to be first declared variable, to ensure that it is at the same location as in the Proxy contract.
1013
// It should also always be ensured that the address is stored alone (uses a full word)
1114
address masterCopy;
@@ -19,5 +22,6 @@ contract MasterCopy is SelfAuthorized {
1922
// Master copy address cannot be null.
2023
require(_masterCopy != address(0), "Invalid master copy address provided");
2124
masterCopy = _masterCopy;
25+
emit ChangedMasterCopy(_masterCopy);
2226
}
2327
}

test/gnosisSafeManagement.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const utils = require('./utils/general')
22
const safeUtils = require('./utils/execution')
3-
const BigNumber = require('bignumber.js');
3+
const BigNumber = require('bignumber.js')
44

55
const GnosisSafe = artifacts.require("./GnosisSafe.sol")
66
const ProxyFactory = artifacts.require("./ProxyFactory.sol")
7-
const MockContract = artifacts.require('./MockContract.sol');
8-
const MockToken = artifacts.require('./Token.sol');
7+
const MockContract = artifacts.require('./MockContract.sol')
8+
const MockToken = artifacts.require('./Token.sol')
99

1010
contract('GnosisSafe', function(accounts) {
1111

1212
let gnosisSafe
13+
let gnosisSafeMasterCopy
1314
let lw
1415
let executor = accounts[8]
1516

@@ -21,7 +22,7 @@ contract('GnosisSafe', function(accounts) {
2122
lw = await utils.createLightwallet()
2223
// Create Master Copies
2324
let proxyFactory = await ProxyFactory.new()
24-
let gnosisSafeMasterCopy = await utils.deployContract("deploying Gnosis Safe Mastercopy", GnosisSafe)
25+
gnosisSafeMasterCopy = await utils.deployContract("deploying Gnosis Safe Mastercopy", GnosisSafe)
2526
gnosisSafeMasterCopy.setup([lw.accounts[0], lw.accounts[1], lw.accounts[2]], 2, 0, "0x", 0, 0, 0, 0)
2627
// Create Gnosis Safe
2728
let gnosisSafeData = await gnosisSafeMasterCopy.contract.setup.getData([lw.accounts[0], lw.accounts[1], lw.accounts[2]], 2, 0, "0x", 0, 0, 0, 0)
@@ -65,6 +66,24 @@ contract('GnosisSafe', function(accounts) {
6566
assert.ok(executorDiff > 0)
6667
})
6768

69+
it('should update the master copy and emit events', async () => {
70+
// Fund account for execution
71+
await web3.eth.sendTransaction({from: accounts[0], to: gnosisSafe.address, value: web3.toWei(0.1, 'ether')})
72+
73+
let executorBalance = await web3.eth.getBalance(executor).toNumber()
74+
// Check that the current address is pointing to the master copy
75+
assert.equal(await web3.eth.getStorageAt(gnosisSafe.address, 0), gnosisSafeMasterCopy.address)
76+
77+
// We deploy a new master copy
78+
let newMasterCopy = await utils.deployContract("deploying Gnosis Safe Mastercopy", GnosisSafe)
79+
80+
let data = await gnosisSafe.contract.changeMasterCopy.getData(newMasterCopy.address)
81+
let updateTx = await safeUtils.executeTransaction(lw, gnosisSafe, 'update master copy', [lw.accounts[0], lw.accounts[1]], gnosisSafe.address, 0, data, CALL, executor)
82+
assert.equal(utils.checkTxEvent(updateTx, 'ChangedMasterCopy', gnosisSafe.address, true).args.masterCopy, newMasterCopy.address)
83+
assert.equal(await web3.eth.getStorageAt(gnosisSafe.address, 0), newMasterCopy.address)
84+
})
85+
86+
6887
it('should not be able to add/remove/replace invalid owners', async () => {
6988
let zeroAcc = "0x0000000000000000000000000000000000000000"
7089
let sentinel = "0x0000000000000000000000000000000000000001"
@@ -116,7 +135,7 @@ contract('GnosisSafe', function(accounts) {
116135
let zeroAcc = "0x0000000000000000000000000000000000000000"
117136
let sentinel = "0x0000000000000000000000000000000000000001"
118137

119-
// Fund account for execution
138+
// Fund account for execution
120139
await web3.eth.sendTransaction({from: accounts[0], to: gnosisSafe.address, value: web3.toWei(0.1, 'ether')})
121140

122141
let executorBalance = await web3.eth.getBalance(executor).toNumber()
@@ -142,7 +161,7 @@ contract('GnosisSafe', function(accounts) {
142161

143162
data = await gnosisSafe.contract.disableModule.getData(randomModule, sentinel)
144163
await safeUtils.executeTransaction(lw, gnosisSafe, 'remove sentinel', [lw.accounts[0], lw.accounts[1]], gnosisSafe.address, 0, data, CALL, executor, { fails: true})
145-
164+
146165
data = await gnosisSafe.contract.disableModule.getData(accounts[1], zeroAcc)
147166
await safeUtils.executeTransaction(lw, gnosisSafe, 'remove with zero account', [lw.accounts[0], lw.accounts[1]], gnosisSafe.address, 0, data, CALL, executor, { fails: true})
148167

@@ -157,7 +176,7 @@ contract('GnosisSafe', function(accounts) {
157176
it('should emit events for modules', async () => {
158177
let sentinel = "0x0000000000000000000000000000000000000001"
159178

160-
// Fund account for execution
179+
// Fund account for execution
161180
await web3.eth.sendTransaction({from: accounts[0], to: gnosisSafe.address, value: web3.toWei(0.1, 'ether')})
162181

163182
let executorBalance = await web3.eth.getBalance(executor).toNumber()
@@ -184,7 +203,7 @@ contract('GnosisSafe', function(accounts) {
184203
})
185204

186205
it('sentinels should not be owners or modules', async () => {
187-
206+
188207
assert.equal(await gnosisSafe.isOwner("0x1"), false)
189208

190209
let sig = "0x" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000000" + "01"
@@ -197,5 +216,5 @@ contract('GnosisSafe', function(accounts) {
197216
gnosisSafe.execTransactionFromModule.estimateGas("0x1", 0, "0x", 0, { from: "0x0000000000000000000000000000000000000001"} ),
198217
"Should not be able to execute transaction from sentinel as module"
199218
)
200-
});
219+
})
201220
})

0 commit comments

Comments
 (0)