11const utils = require ( './utils/general' )
22const safeUtils = require ( './utils/execution' )
3- const BigNumber = require ( 'bignumber.js' ) ;
3+ const BigNumber = require ( 'bignumber.js' )
44
55const GnosisSafe = artifacts . require ( "./GnosisSafe.sol" )
66const 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
1010contract ( '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