Skip to content

Commit 031d4ff

Browse files
committed
fix: clone tx data in test handler
1 parent f7ff38d commit 031d4ff

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

core/vm/preprocess.libevm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestChargePreprocessingGas(t *testing.T) {
125125
tx := types.MustSignNewTx(key, signer, &types.LegacyTx{
126126
// Although nonces aren't strictly necessary, they guarantee a
127127
// different tx hash for each one.
128-
Nonce: uint64(i), //nolint:gosec // Known to not overflow
128+
Nonce: uint64(i),
129129
To: tt.to,
130130
GasPrice: big.NewInt(1),
131131
Gas: tt.txGas,

libevm/precompiles/parallel/parallel_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (r *reverser) Gas(tx *types.Transaction) (uint64, bool) {
6565
}
6666

6767
func reverserOutput(data, extra []byte) []byte {
68-
out := append(data, extra...)
68+
out := append(slices.Clone(data), extra...)
6969
slices.Reverse(out)
7070
return out
7171
}
@@ -222,7 +222,7 @@ func TestIntegration(t *testing.T) {
222222
if !ok {
223223
t.Errorf("no result for tx[%d] %v", txi, txh)
224224
}
225-
env.StateDB().AddLog(&types.Log{
225+
sdb.AddLog(&types.Log{
226226
Data: got[:],
227227
})
228228
return nil, nil
@@ -231,13 +231,13 @@ func TestIntegration(t *testing.T) {
231231
}
232232
stub.Register(t)
233233

234-
state, evm := ethtest.NewZeroEVM(t)
235-
236234
key, err := crypto.GenerateKey()
237235
require.NoErrorf(t, err, "crypto.GenerateKey()")
238236
eoa := crypto.PubkeyToAddress(key.PublicKey)
237+
238+
state, evm := ethtest.NewZeroEVM(t)
239239
state.CreateAccount(eoa)
240-
state.AddBalance(eoa, uint256.NewInt(10*params.Ether))
240+
state.SetBalance(eoa, new(uint256.Int).SetAllOne())
241241

242242
var (
243243
txs types.Transactions
@@ -251,17 +251,21 @@ func TestIntegration(t *testing.T) {
251251
cmpopts.IgnoreFields(types.Log{}, "BlockHash"),
252252
}
253253

254-
signer := types.LatestSigner(evm.ChainConfig())
254+
header := &types.Header{
255+
Number: big.NewInt(0),
256+
BaseFee: big.NewInt(0),
257+
}
258+
config := evm.ChainConfig()
259+
rules := config.Rules(header.Number, true, header.Time)
260+
signer := types.MakeSigner(config, header.Number, header.Time)
261+
255262
for i, addr := range []common.Address{
256263
{'o', 't', 'h', 'e', 'r'},
257264
handler.addr,
258265
} {
259266
ui := uint(i)
260267
data := []byte("hello, world")
261268

262-
// Having all arguments `false` is equivalent to what
263-
// [core.ApplyTransaction] will do.
264-
rules := evm.ChainConfig().Rules(big.NewInt(0), false, 0)
265269
gas, err := intrinsicGas(data, types.AccessList{}, &addr, &rules)
266270
require.NoError(t, err, "core.IntrinsicGas(%#x, nil, false, false, false, false)", data)
267271
if addr == handler.addr {
@@ -293,8 +297,7 @@ func TestIntegration(t *testing.T) {
293297
want = append(want, wantR)
294298
}
295299

296-
block := types.NewBlock(&types.Header{}, txs, nil, nil, trie.NewStackTrie(nil))
297-
rules := evm.ChainConfig().Rules(block.Number(), true, block.Time())
300+
block := types.NewBlock(header, txs, nil, nil, trie.NewStackTrie(nil))
298301
require.NoError(t, sut.StartBlock(block, rules), "StartBlock()")
299302
defer sut.FinishBlock(block)
300303

0 commit comments

Comments
 (0)