@@ -18,16 +18,17 @@ package tracetest
18
18
19
19
import (
20
20
"bufio"
21
+ "bytes"
21
22
"encoding/json"
22
23
"fmt"
23
24
"math/big"
24
25
"os"
25
26
"path"
26
27
"path/filepath"
27
- "reflect"
28
28
"testing"
29
29
30
30
"github.com/ethereum/go-ethereum/common"
31
+ "github.com/ethereum/go-ethereum/common/hexutil"
31
32
"github.com/ethereum/go-ethereum/consensus/beacon"
32
33
"github.com/ethereum/go-ethereum/consensus/ethash"
33
34
"github.com/ethereum/go-ethereum/core"
@@ -43,10 +44,11 @@ import (
43
44
)
44
45
45
46
type supplyInfo struct {
46
- Delta * big.Int `json:"delta"`
47
- Reward * big.Int `json:"reward"`
48
- Withdrawals * big.Int `json:"withdrawals"`
49
- Burn * big.Int `json:"burn"`
47
+ Delta * hexutil.Big `json:"delta"`
48
+ DeltaSign string `json:"deltaSign"`
49
+ Reward * hexutil.Big `json:"reward"`
50
+ Withdrawals * hexutil.Big `json:"withdrawals"`
51
+ Burn * hexutil.Big `json:"burn"`
50
52
51
53
// Block info
52
54
Number uint64 `json:"blockNumber"`
@@ -76,10 +78,11 @@ func TestSupplyGenesisAlloc(t *testing.T) {
76
78
)
77
79
78
80
expected := supplyInfo {
79
- Delta : new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether )),
80
- Reward : common .Big0 ,
81
- Withdrawals : common .Big0 ,
82
- Burn : common .Big0 ,
81
+ Delta : (* hexutil .Big )(new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether ))),
82
+ DeltaSign : "+" ,
83
+ Reward : (* hexutil .Big )(common .Big0 ),
84
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
85
+ Burn : (* hexutil .Big )(common .Big0 ),
83
86
Number : 0 ,
84
87
Hash : common .HexToHash ("0xbcc9466e9fc6a8b56f4b29ca353a421ff8b51a0c1a58ca4743b427605b08f2ca" ),
85
88
ParentHash : common .HexToHash ("0x0000000000000000000000000000000000000000000000000000000000000000" ),
@@ -91,10 +94,7 @@ func TestSupplyGenesisAlloc(t *testing.T) {
91
94
}
92
95
93
96
actual := out [expected .Number ]
94
-
95
- if ! reflect .DeepEqual (actual , expected ) {
96
- t .Fatalf ("incorrect supply info: expected %+v, got %+v" , expected , actual )
97
- }
97
+ compareAsJSON (t , expected , actual )
98
98
}
99
99
100
100
func TestSupplyRewards (t * testing.T ) {
@@ -107,10 +107,11 @@ func TestSupplyRewards(t *testing.T) {
107
107
)
108
108
109
109
expected := supplyInfo {
110
- Delta : new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether )),
111
- Reward : new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether )),
112
- Withdrawals : common .Big0 ,
113
- Burn : common .Big0 ,
110
+ Delta : (* hexutil .Big )(new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether ))),
111
+ DeltaSign : "+" ,
112
+ Reward : (* hexutil .Big )(new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether ))),
113
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
114
+ Burn : (* hexutil .Big )(common .Big0 ),
114
115
Number : 1 ,
115
116
Hash : common .HexToHash ("0xcbb08370505be503dafedc4e96d139ea27aba3cbc580148568b8a307b3f51052" ),
116
117
ParentHash : common .HexToHash ("0xadeda0a83e337b6c073e3f0e9a17531a04009b397a9588c093b628f21b8bc5a3" ),
@@ -122,10 +123,7 @@ func TestSupplyRewards(t *testing.T) {
122
123
}
123
124
124
125
actual := out [expected .Number ]
125
-
126
- if ! reflect .DeepEqual (actual , expected ) {
127
- t .Fatalf ("incorrect supply info: expected %+v, got %+v" , expected , actual )
128
- }
126
+ compareAsJSON (t , expected , actual )
129
127
}
130
128
131
129
func TestSupplyEip1559Burn (t * testing.T ) {
@@ -174,20 +172,19 @@ func TestSupplyEip1559Burn(t *testing.T) {
174
172
reward = new (big.Int ).Mul (common .Big2 , big .NewInt (params .Ether ))
175
173
burn = new (big.Int ).Mul (big .NewInt (21000 ), head .BaseFee )
176
174
expected = supplyInfo {
177
- Delta : new (big.Int ).Sub (reward , burn ),
178
- Reward : reward ,
179
- Withdrawals : common .Big0 ,
180
- Burn : burn ,
175
+ Delta : (* hexutil .Big )(new (big.Int ).Sub (reward , burn )),
176
+ DeltaSign : "+" ,
177
+ Reward : (* hexutil .Big )(reward ),
178
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
179
+ Burn : (* hexutil .Big )(burn ),
181
180
Number : 1 ,
182
181
Hash : head .Hash (),
183
182
ParentHash : head .ParentHash ,
184
183
}
185
184
)
186
185
187
186
actual := out [expected .Number ]
188
- if ! reflect .DeepEqual (actual , expected ) {
189
- t .Fatalf ("incorrect supply info: expected %+v, got %+v" , expected , actual )
190
- }
187
+ compareAsJSON (t , expected , actual )
191
188
}
192
189
193
190
func TestSupplyWithdrawals (t * testing.T ) {
@@ -216,20 +213,18 @@ func TestSupplyWithdrawals(t *testing.T) {
216
213
var (
217
214
head = chain .CurrentBlock ()
218
215
expected = supplyInfo {
219
- Delta : big .NewInt (1337000000000 ),
220
- Reward : common .Big0 ,
221
- Withdrawals : big .NewInt (1337000000000 ),
222
- Burn : common .Big0 ,
216
+ Delta : (* hexutil .Big )(big .NewInt (1337000000000 )),
217
+ DeltaSign : "+" ,
218
+ Reward : (* hexutil .Big )(common .Big0 ),
219
+ Withdrawals : (* hexutil .Big )(big .NewInt (1337000000000 )),
220
+ Burn : (* hexutil .Big )(common .Big0 ),
223
221
Number : 1 ,
224
222
Hash : head .Hash (),
225
223
ParentHash : head .ParentHash ,
226
224
}
227
225
actual = out [expected .Number ]
228
226
)
229
-
230
- if ! reflect .DeepEqual (actual , expected ) {
231
- t .Fatalf ("incorrect supply info: expected %+v, got %+v" , expected , actual )
232
- }
227
+ compareAsJSON (t , expected , actual )
233
228
}
234
229
235
230
// Tests fund retrieval after contract's selfdestruct.
@@ -314,20 +309,18 @@ func TestSupplySelfdestruct(t *testing.T) {
314
309
head := preCancunChain .CurrentBlock ()
315
310
// Check live trace output
316
311
expected := supplyInfo {
317
- Delta : big .NewInt (- 55294500000000 ),
318
- Reward : common .Big0 ,
319
- Withdrawals : common .Big0 ,
320
- Burn : big .NewInt (55294500000000 ),
312
+ Delta : (* hexutil .Big )(big .NewInt (55294500000000 )),
313
+ DeltaSign : "-" ,
314
+ Reward : (* hexutil .Big )(common .Big0 ),
315
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
316
+ Burn : (* hexutil .Big )(big .NewInt (55294500000000 )),
321
317
Number : 1 ,
322
318
Hash : head .Hash (),
323
319
ParentHash : head .ParentHash ,
324
320
}
325
321
326
322
actual := preCancunOutput [expected .Number ]
327
-
328
- if ! reflect .DeepEqual (actual , expected ) {
329
- t .Fatalf ("Pre-cancun incorrect supply info: expected %+v, got %+v" , expected , actual )
330
- }
323
+ compareAsJSON (t , expected , actual )
331
324
332
325
// 2. Test post Cancun
333
326
cancunTime := uint64 (0 )
@@ -357,20 +350,18 @@ func TestSupplySelfdestruct(t *testing.T) {
357
350
// Check live trace output
358
351
head = postCancunChain .CurrentBlock ()
359
352
expected = supplyInfo {
360
- Delta : big .NewInt (- 55289500000000 ),
361
- Reward : common .Big0 ,
362
- Withdrawals : common .Big0 ,
363
- Burn : big .NewInt (55289500000000 ),
353
+ Delta : (* hexutil .Big )(big .NewInt (55289500000000 )),
354
+ DeltaSign : "-" ,
355
+ Reward : (* hexutil .Big )(common .Big0 ),
356
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
357
+ Burn : (* hexutil .Big )(big .NewInt (55289500000000 )),
364
358
Number : 1 ,
365
359
Hash : head .Hash (),
366
360
ParentHash : head .ParentHash ,
367
361
}
368
362
369
363
actual = postCancunOutput [expected .Number ]
370
-
371
- if ! reflect .DeepEqual (actual , expected ) {
372
- t .Fatalf ("Post-cancun incorrect supply info: expected %+v, got %+v" , expected , actual )
373
- }
364
+ compareAsJSON (t , expected , actual )
374
365
}
375
366
376
367
// Tests selfdestructing contract to send its balance to itself (burn).
@@ -507,20 +498,18 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
507
498
totalBurn := new (big.Int ).Add (blockBurn , eth5 ) // 5ETH burned from contract B
508
499
509
500
expected := supplyInfo {
510
- Delta : new (big.Int ).Neg (totalBurn ),
511
- Reward : common .Big0 ,
512
- Withdrawals : common .Big0 ,
513
- Burn : totalBurn ,
501
+ Delta : (* hexutil .Big )(totalBurn ),
502
+ DeltaSign : "-" ,
503
+ Reward : (* hexutil .Big )(common .Big0 ),
504
+ Withdrawals : (* hexutil .Big )(common .Big0 ),
505
+ Burn : (* hexutil .Big )(totalBurn ),
514
506
Number : 1 ,
515
507
Hash : block .Hash (),
516
508
ParentHash : block .ParentHash (),
517
509
}
518
510
519
511
actual := output [expected .Number ]
520
-
521
- if ! reflect .DeepEqual (actual , expected ) {
522
- t .Fatalf ("incorrect supply info: expected %+v, got %+v" , expected , actual )
523
- }
512
+ compareAsJSON (t , expected , actual )
524
513
}
525
514
526
515
func testSupplyTracer (t * testing.T , genesis * core.Genesis , gen func (* core.BlockGen )) ([]supplyInfo , * core.BlockChain , error ) {
@@ -575,3 +564,19 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
575
564
576
565
return output , chain , nil
577
566
}
567
+
568
+ func compareAsJSON (t * testing.T , expected interface {}, actual interface {}) {
569
+ want , err := json .Marshal (expected )
570
+ if err != nil {
571
+ t .Fatalf ("failed to marshal expected value to JSON: %v" , err )
572
+ }
573
+
574
+ have , err := json .Marshal (actual )
575
+ if err != nil {
576
+ t .Fatalf ("failed to marshal actual value to JSON: %v" , err )
577
+ }
578
+
579
+ if ! bytes .Equal (want , have ) {
580
+ t .Fatalf ("incorrect supply info: expected %s, got %s" , string (want ), string (have ))
581
+ }
582
+ }
0 commit comments