@@ -21,10 +21,10 @@ import (
21
21
22
22
"github.com/ethereum/go-ethereum/common"
23
23
"github.com/ethereum/go-ethereum/common/hexutil"
24
+ "github.com/ethereum/go-ethereum/common/math"
24
25
"github.com/ethereum/go-ethereum/core"
25
26
"github.com/ethereum/go-ethereum/core/types"
26
27
"github.com/ethereum/go-ethereum/params"
27
- "github.com/ethereum/go-ethereum/rlp"
28
28
)
29
29
30
30
// TransactionTest checks RLP decoding and sender derivation of transactions.
@@ -34,80 +34,157 @@ type TransactionTest struct {
34
34
}
35
35
36
36
type ttResult struct {
37
- Byzantium ttFork
38
- Constantinople ttFork
39
- Istanbul ttFork
40
- EIP150 ttFork
41
- EIP158 ttFork
42
- Frontier ttFork
43
- Homestead ttFork
37
+ Prague * ttFork
38
+ Cancun * ttFork
39
+ Shanghai * ttFork
40
+ Paris * ttFork
41
+ London * ttFork
42
+ Berlin * ttFork
43
+ Byzantium * ttFork
44
+ Constantinople * ttFork
45
+ Istanbul * ttFork
46
+ EIP150 * ttFork
47
+ EIP158 * ttFork
48
+ Frontier * ttFork
49
+ Homestead * ttFork
44
50
}
45
51
46
52
type ttFork struct {
47
- Sender common.UnprefixedAddress `json:"sender"`
48
- Hash common.UnprefixedHash `json:"hash"`
53
+ Sender * common.UnprefixedAddress `json:"sender"`
54
+ Hash * common.UnprefixedHash `json:"hash"`
55
+ Exception * string `json:"exception"`
56
+ IntrinsicGas math.HexOrDecimal64 `json:"intrinsicGas"`
57
+ }
58
+
59
+ func (tt * TransactionTest ) validate () error {
60
+ if tt .Txbytes == nil {
61
+ return fmt .Errorf ("missing txbytes" )
62
+ }
63
+ if err := tt .validateFork (tt .Result .Prague ); err != nil {
64
+ return fmt .Errorf ("invalid Prague: %v" , err )
65
+ }
66
+ if err := tt .validateFork (tt .Result .Cancun ); err != nil {
67
+ return fmt .Errorf ("invalid Cancun: %v" , err )
68
+ }
69
+ if err := tt .validateFork (tt .Result .Shanghai ); err != nil {
70
+ return fmt .Errorf ("invalid Shanghai: %v" , err )
71
+ }
72
+ if err := tt .validateFork (tt .Result .Paris ); err != nil {
73
+ return fmt .Errorf ("invalid Paris: %v" , err )
74
+ }
75
+ if err := tt .validateFork (tt .Result .London ); err != nil {
76
+ return fmt .Errorf ("invalid London: %v" , err )
77
+ }
78
+ if err := tt .validateFork (tt .Result .Berlin ); err != nil {
79
+ return fmt .Errorf ("invalid Berlin: %v" , err )
80
+ }
81
+ if err := tt .validateFork (tt .Result .Byzantium ); err != nil {
82
+ return fmt .Errorf ("invalid Byzantium: %v" , err )
83
+ }
84
+ if err := tt .validateFork (tt .Result .Constantinople ); err != nil {
85
+ return fmt .Errorf ("invalid Constantinople: %v" , err )
86
+ }
87
+ if err := tt .validateFork (tt .Result .Istanbul ); err != nil {
88
+ return fmt .Errorf ("invalid Istanbul: %v" , err )
89
+ }
90
+ if err := tt .validateFork (tt .Result .EIP150 ); err != nil {
91
+ return fmt .Errorf ("invalid EIP150: %v" , err )
92
+ }
93
+ if err := tt .validateFork (tt .Result .EIP158 ); err != nil {
94
+ return fmt .Errorf ("invalid EIP158: %v" , err )
95
+ }
96
+ if err := tt .validateFork (tt .Result .Frontier ); err != nil {
97
+ return fmt .Errorf ("invalid Frontier: %v" , err )
98
+ }
99
+ if err := tt .validateFork (tt .Result .Homestead ); err != nil {
100
+ return fmt .Errorf ("invalid Homestead: %v" , err )
101
+ }
102
+ return nil
103
+ }
104
+
105
+ func (tt * TransactionTest ) validateFork (fork * ttFork ) error {
106
+ if fork == nil {
107
+ return nil
108
+ }
109
+ if fork .Hash == nil && fork .Exception == nil {
110
+ return fmt .Errorf ("missing hash and exception" )
111
+ }
112
+ if fork .Hash != nil && fork .Sender == nil {
113
+ return fmt .Errorf ("missing sender" )
114
+ }
115
+ return nil
49
116
}
50
117
51
118
func (tt * TransactionTest ) Run (config * params.ChainConfig ) error {
52
- validateTx := func (rlpData hexutil.Bytes , signer types.Signer , isHomestead bool , isIstanbul bool ) (* common.Address , * common.Hash , error ) {
119
+ if err := tt .validate (); err != nil {
120
+ return err
121
+ }
122
+ validateTx := func (rlpData hexutil.Bytes , signer types.Signer , isHomestead , isIstanbul , isShanghai bool ) (sender common.Address , hash common.Hash , requiredGas uint64 , err error ) {
53
123
tx := new (types.Transaction )
54
- if err := rlp . DecodeBytes (rlpData , tx ); err != nil {
55
- return nil , nil , err
124
+ if err = tx . UnmarshalBinary (rlpData ); err != nil {
125
+ return
56
126
}
57
- sender , err : = types .Sender (signer , tx )
127
+ sender , err = types .Sender (signer , tx )
58
128
if err != nil {
59
- return nil , nil , err
129
+ return
60
130
}
61
131
// Intrinsic gas
62
- requiredGas , err : = core .IntrinsicGas (tx .Data (), tx .AccessList (), tx .SetCodeAuthorizations (), tx .To () == nil , isHomestead , isIstanbul , false )
132
+ requiredGas , err = core .IntrinsicGas (tx .Data (), tx .AccessList (), tx .SetCodeAuthorizations (), tx .To () == nil , isHomestead , isIstanbul , isShanghai )
63
133
if err != nil {
64
- return nil , nil , err
134
+ return
65
135
}
66
136
if requiredGas > tx .Gas () {
67
- return nil , nil , fmt .Errorf ("insufficient gas ( %d < %d )" , tx .Gas (), requiredGas )
137
+ return sender , hash , 0 , fmt .Errorf ("insufficient gas ( %d < %d )" , tx .Gas (), requiredGas )
68
138
}
69
- h : = tx .Hash ()
70
- return & sender , & h , nil
139
+ hash = tx .Hash ()
140
+ return sender , hash , requiredGas , nil
71
141
}
72
-
73
142
for _ , testcase := range []struct {
74
143
name string
75
144
signer types.Signer
76
- fork ttFork
145
+ fork * ttFork
77
146
isHomestead bool
78
147
isIstanbul bool
148
+ isShanghai bool
79
149
}{
80
- {"Frontier" , types.FrontierSigner {}, tt .Result .Frontier , false , false },
81
- {"Homestead" , types.HomesteadSigner {}, tt .Result .Homestead , true , false },
82
- {"EIP150" , types.HomesteadSigner {}, tt .Result .EIP150 , true , false },
83
- {"EIP158" , types .NewEIP155Signer (config .ChainID ), tt .Result .EIP158 , true , false },
84
- {"Byzantium" , types .NewEIP155Signer (config .ChainID ), tt .Result .Byzantium , true , false },
85
- {"Constantinople" , types .NewEIP155Signer (config .ChainID ), tt .Result .Constantinople , true , false },
86
- {"Istanbul" , types .NewEIP155Signer (config .ChainID ), tt .Result .Istanbul , true , true },
150
+ {"Frontier" , types.FrontierSigner {}, tt .Result .Frontier , false , false , false },
151
+ {"Homestead" , types.HomesteadSigner {}, tt .Result .Homestead , true , false , false },
152
+ {"EIP150" , types.HomesteadSigner {}, tt .Result .EIP150 , true , false , false },
153
+ {"EIP158" , types .NewEIP155Signer (config .ChainID ), tt .Result .EIP158 , true , false , false },
154
+ {"Byzantium" , types .NewEIP155Signer (config .ChainID ), tt .Result .Byzantium , true , false , false },
155
+ {"Constantinople" , types .NewEIP155Signer (config .ChainID ), tt .Result .Constantinople , true , false , false },
156
+ {"Istanbul" , types .NewEIP155Signer (config .ChainID ), tt .Result .Istanbul , true , true , false },
157
+ {"Berlin" , types .NewEIP2930Signer (config .ChainID ), tt .Result .Berlin , true , true , false },
158
+ {"London" , types .NewLondonSigner (config .ChainID ), tt .Result .London , true , true , false },
159
+ {"Paris" , types .NewLondonSigner (config .ChainID ), tt .Result .Paris , true , true , false },
160
+ {"Shanghai" , types .NewLondonSigner (config .ChainID ), tt .Result .Shanghai , true , true , true },
161
+ {"Cancun" , types .NewCancunSigner (config .ChainID ), tt .Result .Cancun , true , true , true },
162
+ {"Prague" , types .NewPragueSigner (config .ChainID ), tt .Result .Prague , true , true , true },
87
163
} {
88
- sender , txhash , err := validateTx (tt .Txbytes , testcase .signer , testcase .isHomestead , testcase .isIstanbul )
89
-
90
- if testcase .fork .Sender == (common.UnprefixedAddress {}) {
91
- if err == nil {
92
- return fmt .Errorf ("expected error, got none (address %v)[%v]" , sender .String (), testcase .name )
93
- }
164
+ if testcase .fork == nil {
94
165
continue
95
166
}
96
- // Should resolve the right address
167
+ sender , hash , gas , err := validateTx ( tt . Txbytes , testcase . signer , testcase . isHomestead , testcase . isIstanbul , testcase . isShanghai )
97
168
if err != nil {
98
- return fmt .Errorf ("got error, expected none: %v" , err )
169
+ if testcase .fork .Hash != nil {
170
+ return fmt .Errorf ("unexpected error: %v" , err )
171
+ }
172
+ continue
173
+ }
174
+ if testcase .fork .Exception != nil {
175
+ return fmt .Errorf ("expected error %v, got none (%v)" , * testcase .fork .Exception , err )
99
176
}
100
- if sender == nil {
101
- return fmt .Errorf ("sender was nil, should be %x" , common .Address ( testcase .fork .Sender ))
177
+ if common . Hash ( * testcase . fork . Hash ) != hash {
178
+ return fmt .Errorf ("hash mismatch: got %x, want %x" , hash , common .Hash ( * testcase .fork .Hash ))
102
179
}
103
- if * sender != common .Address (testcase .fork .Sender ) {
180
+ if common .Address (* testcase .fork .Sender ) != sender {
104
181
return fmt .Errorf ("sender mismatch: got %x, want %x" , sender , testcase .fork .Sender )
105
182
}
106
- if txhash == nil {
107
- return fmt .Errorf ("txhash was nil, should be %x" , common . Hash ( testcase .fork .Hash ) )
183
+ if hash != common . Hash ( * testcase . fork . Hash ) {
184
+ return fmt .Errorf ("hash mismatch: got %x, want %x" , hash , testcase .fork .Hash )
108
185
}
109
- if * txhash != common . Hash (testcase .fork .Hash ) {
110
- return fmt .Errorf ("hash mismatch: got %x , want %x " , * txhash , testcase .fork .Hash )
186
+ if uint64 (testcase .fork .IntrinsicGas ) != gas {
187
+ return fmt .Errorf ("intrinsic gas mismatch: got %d , want %d " , gas , uint64 ( testcase .fork .IntrinsicGas ) )
111
188
}
112
189
}
113
190
return nil
0 commit comments