16
16
package tracers
17
17
18
18
import (
19
- "crypto/ecdsa"
20
- "crypto/rand"
21
- "encoding/json"
22
19
"math/big"
23
20
"testing"
24
21
25
22
"github.com/celo-org/celo-blockchain/common"
26
- "github.com/celo-org/celo-blockchain/common/hexutil"
27
23
"github.com/celo-org/celo-blockchain/contracts/testutil"
28
24
"github.com/celo-org/celo-blockchain/core"
29
25
"github.com/celo-org/celo-blockchain/core/rawdb"
@@ -35,87 +31,6 @@ import (
35
31
"github.com/celo-org/celo-blockchain/tests"
36
32
)
37
33
38
- // callTrace is the result of a callTracer run.
39
- type callTrace struct {
40
- Type string `json:"type"`
41
- From common.Address `json:"from"`
42
- To common.Address `json:"to"`
43
- Input hexutil.Bytes `json:"input"`
44
- Output hexutil.Bytes `json:"output"`
45
- Gas * hexutil.Uint64 `json:"gas,omitempty"`
46
- GasUsed * hexutil.Uint64 `json:"gasUsed,omitempty"`
47
- Value * hexutil.Big `json:"value,omitempty"`
48
- Error string `json:"error,omitempty"`
49
- Calls []callTrace `json:"calls,omitempty"`
50
- }
51
-
52
- func TestPrestateTracerTransfer (t * testing.T ) {
53
- celoMock := testutil .NewCeloMock ()
54
-
55
- toAddr := "0x00000000000000000000000000000000deadbeef"
56
- unsignedTx := types .NewTransaction (1 , common .HexToAddress (toAddr ), new (big.Int ), 5000000 , big .NewInt (1 ), nil , nil , nil , []byte {})
57
-
58
- privateKeyECDSA , err := ecdsa .GenerateKey (crypto .S256 (), rand .Reader )
59
- if err != nil {
60
- t .Fatalf ("err %v" , err )
61
- }
62
- signer := types .NewEIP155Signer (big .NewInt (1 ))
63
- tx , err := types .SignTx (unsignedTx , signer , privateKeyECDSA )
64
- if err != nil {
65
- t .Fatalf ("err %v" , err )
66
- }
67
- origin , _ := signer .Sender (tx )
68
- txContext := vm.TxContext {
69
- Origin : origin ,
70
- GasPrice : big .NewInt (1 ),
71
- }
72
- context := vm.BlockContext {
73
- CanTransfer : vmcontext .CanTransfer ,
74
- Transfer : vmcontext .TobinTransfer ,
75
- Coinbase : common.Address {},
76
- BlockNumber : new (big.Int ).SetUint64 (8000000 ),
77
- Time : new (big.Int ).SetUint64 (5 ),
78
- GetRegisteredAddress : vmcontext .GetRegisteredAddress ,
79
- }
80
- alloc := core.GenesisAlloc {}
81
- alloc [origin ] = core.GenesisAccount {
82
- Nonce : 1 ,
83
- Code : []byte {},
84
- Balance : big .NewInt (500000000000000 ),
85
- }
86
- _ , statedb := tests .MakePreState (rawdb .NewMemoryDatabase (), alloc , false )
87
-
88
- // Create the tracer, the EVM environment and run it
89
- tracer , err := New ("prestateTracer" , new (Context ))
90
- if err != nil {
91
- t .Fatalf ("failed to create prestate tracer: %v" , err )
92
- }
93
- vmConfig := vm.Config {Debug : true , Tracer : tracer }
94
- evm := vm .NewEVM (context , txContext , statedb , params .MainnetChainConfig , vmConfig )
95
-
96
- msg , err := tx .AsMessage (signer , nil )
97
- if err != nil {
98
- t .Fatalf ("failed to prepare transaction for tracing: %v" , err )
99
- }
100
-
101
- st := core .NewStateTransition (evm , msg , new (core.GasPool ).AddGas (tx .Gas ()), celoMock .Runner , nil )
102
- if _ , err = st .TransitionDb (); err != nil {
103
- t .Fatalf ("failed to execute transaction: %v" , err )
104
- }
105
- // Retrieve the trace result and compare against the etalon
106
- res , err := tracer .GetResult ()
107
- if err != nil {
108
- t .Fatalf ("failed to retrieve trace result: %v" , err )
109
- }
110
- ret := make (map [string ]interface {})
111
- if err := json .Unmarshal (res , & ret ); err != nil {
112
- t .Fatalf ("failed to unmarshal trace result: %v" , err )
113
- }
114
- if _ , has := ret [toAddr ]; ! has {
115
- t .Fatalf ("Expected %s in result" , toAddr )
116
- }
117
- }
118
-
119
34
func BenchmarkTransactionTrace (b * testing.B ) {
120
35
celoMock := testutil .NewCeloMock ()
121
36
key , _ := crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
0 commit comments