@@ -122,6 +122,47 @@ func TestHooks(t *testing.T) {
122122 sdb .AddLog (& types.Log {
123123 Address : common.Address {0xbb },
124124 })
125+
126+ if len (result ) != len (wants ) {
127+ t .Fatalf ("number of tracing events wrong, have %d want %d" , len (result ), len (wants ))
128+ }
129+
130+ for i , want := range wants {
131+ if have := result [i ]; have != want {
132+ t .Fatalf ("error event %d, have\n %v\n want%v\n " , i , have , want )
133+ }
134+ }
135+ }
136+
137+ func TestHooks_OnCodeChangeV2 (t * testing.T ) {
138+ inner , _ := New (types .EmptyRootHash , NewDatabaseForTesting ())
139+
140+ var result []string
141+ var wants = []string {
142+ "0xaa00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) ContractCreation" ,
143+ "0xaa00000000000000000000000000000000000000.code: 0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct" ,
144+ "0xbb00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) ContractCreation" ,
145+ "0xbb00000000000000000000000000000000000000.code: 0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct" ,
146+ }
147+ emitF := func (format string , a ... any ) {
148+ result = append (result , fmt .Sprintf (format , a ... ))
149+ }
150+ sdb := NewHookedState (inner , & tracing.Hooks {
151+ OnCodeChangeV2 : func (addr common.Address , prevCodeHash common.Hash , prevCode []byte , codeHash common.Hash , code []byte , reason tracing.CodeChangeReason ) {
152+ emitF ("%v.code: %#x (%v) ->%#x (%v) %s" , addr , prevCode , prevCodeHash , code , codeHash , reason )
153+ },
154+ })
155+ sdb .SetCode (common.Address {0xaa }, []byte {0x13 , 37 }, tracing .CodeChangeContractCreation )
156+ sdb .SelfDestruct (common.Address {0xaa })
157+
158+ sdb .SetCode (common.Address {0xbb }, []byte {0x13 , 38 }, tracing .CodeChangeContractCreation )
159+ sdb .CreateContract (common.Address {0xbb })
160+ sdb .SelfDestruct6780 (common.Address {0xbb })
161+
162+ if len (result ) != len (wants ) {
163+ t .Fatalf ("number of tracing events wrong, have %d want %d" , len (result ), len (wants ))
164+ }
165+
125166 for i , want := range wants {
126167 if have := result [i ]; have != want {
127168 t .Fatalf ("error event %d, have\n %v\n want%v\n " , i , have , want )
0 commit comments