Skip to content

Commit 53c7c7b

Browse files
palangoEela Nagaraj
authored and
Eela Nagaraj
committed
Fix tests
Make linter happy
1 parent efbc25a commit 53c7c7b

File tree

3 files changed

+30
-159
lines changed

3 files changed

+30
-159
lines changed

eth/state_accessor.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ import (
3737
// base layer statedb can be passed then it's regarded as the statedb of the
3838
// parent block.
3939
// Parameters:
40-
// - block: The block for which we want the state (== state at the stateRoot of the parent)
41-
// - reexec: The maximum number of blocks to reprocess trying to obtain the desired state
42-
// - base: If the caller is tracing multiple blocks, the caller can provide the parent state
43-
// continuously from the callsite.
44-
// - checklive: if true, then the live 'blockchain' state database is used. If the caller want to
45-
// perform Commit or other 'save-to-disk' changes, this should be set to false to avoid
46-
// storing trash persistently
47-
// - preferDisk: this arg can be used by the caller to signal that even though the 'base' is provided,
48-
// it would be preferrable to start from a fresh state, if we have it on disk.
40+
// - block: The block for which we want the state (== state at the stateRoot of the parent)
41+
// - reexec: The maximum number of blocks to reprocess trying to obtain the desired state
42+
// - base: If the caller is tracing multiple blocks, the caller can provide the parent state
43+
// continuously from the callsite.
44+
// - checklive: if true, then the live 'blockchain' state database is used. If the caller want to
45+
// perform Commit or other 'save-to-disk' changes, this should be set to false to avoid
46+
// storing trash persistently
47+
// - preferDisk: this arg can be used by the caller to signal that even though the 'base' is provided,
48+
// it would be preferrable to start from a fresh state, if we have it on disk.
4949
func (eth *Ethereum) stateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, checkLive bool, preferDisk bool) (statedb *state.StateDB, err error) {
5050
var (
5151
current *types.Block

eth/tracers/api_test.go

+16-147
Original file line numberDiff line numberDiff line change
@@ -321,150 +321,6 @@ func TestTraceCall(t *testing.T) {
321321
}
322322
}
323323

324-
<<<<<<< HEAD
325-
func TestOverriddenTraceCall(t *testing.T) {
326-
t.Parallel()
327-
328-
// Initialize test accounts
329-
accounts := newAccounts(3)
330-
genesis := &core.Genesis{Alloc: core.GenesisAlloc{
331-
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
332-
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
333-
accounts[2].addr: {Balance: big.NewInt(params.Ether)},
334-
}}
335-
genBlocks := 10
336-
signer := types.HomesteadSigner{}
337-
api := NewAPI(newTestBackend(t, genBlocks, genesis, func(i int, b *core.BlockGen) {
338-
// Transfer from account[0] to account[1]
339-
// value: 1000 wei
340-
// fee: 0 wei
341-
tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), params.TxGas, nil, nil, nil, nil, nil), signer, accounts[0].key)
342-
b.AddTx(tx)
343-
}))
344-
randomAccounts, tracer := newAccounts(3), "callTracerJs"
345-
346-
var testSuite = []struct {
347-
blockNumber rpc.BlockNumber
348-
call ethapi.TransactionArgs
349-
config *TraceCallConfig
350-
expectErr error
351-
expect *callTrace
352-
}{
353-
// Succcessful call with state overriding
354-
{
355-
blockNumber: rpc.PendingBlockNumber,
356-
call: ethapi.TransactionArgs{
357-
From: &randomAccounts[0].addr,
358-
To: &randomAccounts[1].addr,
359-
Value: (*hexutil.Big)(big.NewInt(1000)),
360-
},
361-
config: &TraceCallConfig{
362-
Tracer: &tracer,
363-
StateOverrides: &ethapi.StateOverride{
364-
randomAccounts[0].addr: ethapi.OverrideAccount{Balance: newRPCBalance(new(big.Int).Mul(big.NewInt(1), big.NewInt(params.Ether)))},
365-
},
366-
},
367-
expectErr: nil,
368-
expect: &callTrace{
369-
Type: "CALL",
370-
From: randomAccounts[0].addr,
371-
To: randomAccounts[1].addr,
372-
Gas: newRPCUint64(24979000),
373-
GasUsed: newRPCUint64(0),
374-
Value: (*hexutil.Big)(big.NewInt(1000)),
375-
},
376-
},
377-
// Invalid call without state overriding
378-
{
379-
blockNumber: rpc.PendingBlockNumber,
380-
call: ethapi.TransactionArgs{
381-
From: &randomAccounts[0].addr,
382-
To: &randomAccounts[1].addr,
383-
Value: (*hexutil.Big)(big.NewInt(1000)),
384-
},
385-
config: &TraceCallConfig{
386-
Tracer: &tracer,
387-
},
388-
expectErr: core.ErrInsufficientFundsForTransfer,
389-
expect: nil,
390-
},
391-
// Successful simple contract call
392-
//
393-
// // SPDX-License-Identifier: GPL-3.0
394-
//
395-
// pragma solidity >=0.7.0 <0.8.0;
396-
//
397-
// /**
398-
// * @title Storage
399-
// * @dev Store & retrieve value in a variable
400-
// */
401-
// contract Storage {
402-
// uint256 public number;
403-
// constructor() {
404-
// number = block.number;
405-
// }
406-
// }
407-
{
408-
blockNumber: rpc.PendingBlockNumber,
409-
call: ethapi.TransactionArgs{
410-
From: &randomAccounts[0].addr,
411-
To: &randomAccounts[2].addr,
412-
Data: newRPCBytes(common.Hex2Bytes("8381f58a")), // call number()
413-
},
414-
config: &TraceCallConfig{
415-
Tracer: &tracer,
416-
StateOverrides: &ethapi.StateOverride{
417-
randomAccounts[2].addr: ethapi.OverrideAccount{
418-
Code: newRPCBytes(common.Hex2Bytes("6080604052348015600f57600080fd5b506004361060285760003560e01c80638381f58a14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea2646970667358221220eab35ffa6ab2adfe380772a48b8ba78e82a1b820a18fcb6f59aa4efb20a5f60064736f6c63430007040033")),
419-
StateDiff: newStates([]common.Hash{{}}, []common.Hash{common.BigToHash(big.NewInt(123))}),
420-
},
421-
},
422-
},
423-
expectErr: nil,
424-
expect: &callTrace{
425-
Type: "CALL",
426-
From: randomAccounts[0].addr,
427-
To: randomAccounts[2].addr,
428-
Input: hexutil.Bytes(common.Hex2Bytes("8381f58a")),
429-
Output: hexutil.Bytes(common.BigToHash(big.NewInt(123)).Bytes()),
430-
Gas: newRPCUint64(24978936),
431-
GasUsed: newRPCUint64(383), // TODO ethereum cost 2283, check if this is right
432-
Value: (*hexutil.Big)(big.NewInt(0)),
433-
},
434-
},
435-
}
436-
for i, testspec := range testSuite {
437-
result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config)
438-
if testspec.expectErr != nil {
439-
if err == nil {
440-
t.Errorf("test %d: want error %v, have nothing", i, testspec.expectErr)
441-
continue
442-
}
443-
if !errors.Is(err, testspec.expectErr) {
444-
t.Errorf("test %d: error mismatch, want %v, have %v", i, testspec.expectErr, err)
445-
}
446-
} else {
447-
if err != nil {
448-
t.Errorf("test %d: want no error, have %v", i, err)
449-
continue
450-
}
451-
ret := new(callTrace)
452-
if err := json.Unmarshal(result.(json.RawMessage), ret); err != nil {
453-
t.Fatalf("test %d: failed to unmarshal trace result: %v", i, err)
454-
}
455-
if !jsonEqual(ret, testspec.expect) {
456-
// uncomment this for easier debugging
457-
//have, _ := json.MarshalIndent(ret, "", " ")
458-
//want, _ := json.MarshalIndent(testspec.expect, "", " ")
459-
//t.Fatalf("trace mismatch: \nhave %+v\nwant %+v", string(have), string(want))
460-
t.Fatalf("trace mismatch: \nhave %+v\nwant %+v", ret, testspec.expect)
461-
}
462-
}
463-
}
464-
}
465-
466-
=======
467-
>>>>>>> 6b9c77f06 (eth/tracers: package restructuring (#23857))
468324
func TestTraceTransaction(t *testing.T) {
469325
t.Parallel()
470326

@@ -638,7 +494,20 @@ func TestTracingWithOverrides(t *testing.T) {
638494
// Transfer from account[0] to account[1]
639495
// value: 1000 wei
640496
// fee: 0 wei
641-
tx, _ := types.SignTx(types.NewTransaction(uint64(i), accounts[1].addr, big.NewInt(1000), params.TxGas, b.BaseFee(), nil), signer, accounts[0].key)
497+
tx, _ := types.SignTx(
498+
types.NewTransaction(
499+
uint64(i),
500+
accounts[1].addr,
501+
big.NewInt(1000),
502+
params.TxGas,
503+
common.Big0,
504+
nil,
505+
nil,
506+
nil,
507+
nil),
508+
signer,
509+
accounts[0].key,
510+
)
642511
b.AddTx(tx)
643512
}))
644513
randomAccounts := newAccounts(3)
@@ -678,7 +547,7 @@ func TestTracingWithOverrides(t *testing.T) {
678547
Value: (*hexutil.Big)(big.NewInt(1000)),
679548
},
680549
config: &TraceCallConfig{},
681-
expectErr: core.ErrInsufficientFunds,
550+
expectErr: core.ErrInsufficientFundsForTransfer,
682551
},
683552
// Successful simple contract call
684553
//
@@ -712,7 +581,7 @@ func TestTracingWithOverrides(t *testing.T) {
712581
},
713582
},
714583
},
715-
want: `{"gas":23347,"failed":false,"returnValue":"000000000000000000000000000000000000000000000000000000000000007b"}`,
584+
want: `{"gas":21447,"failed":false,"returnValue":"000000000000000000000000000000000000000000000000000000000000007b"}`,
716585
},
717586
}
718587
for i, tc := range testSuite {

eth/tracers/native/tracer.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ Aside from implementing the tracer, it also needs to register itself, using the
2727
Example:
2828
2929
```golang
30-
func init() {
31-
register("noopTracerNative", newNoopTracer)
32-
}
30+
31+
func init() {
32+
register("noopTracerNative", newNoopTracer)
33+
}
34+
3335
```
3436
*/
3537
package native

0 commit comments

Comments
 (0)