github.com/amazechain/amc@v0.1.3/internal/tracers/tracers_test.go (about) 1 // Copyright 2023 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The AmazeChain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package tracers 18 19 //func BenchmarkTransactionTrace(b *testing.B) { 20 // key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 21 // from := crypto.PubkeyToAddress(key.PublicKey) 22 // gas := uint64(1000000) // 1M gas 23 // to := common.HexToAddress("0x00000000000000000000000000000000deadbeef") 24 // signer :=transaction.LatestSignerForChainID(big.NewInt(1337)) 25 // tx, err := transaction.SignNewTx(key, signer, 26 // &transaction.LegacyTx{ 27 // Nonce: 1, 28 // GasPrice: uint256.NewInt(500), 29 // Gas: gas, 30 // To: &to, 31 // }) 32 // if err != nil { 33 // b.Fatal(err) 34 // } 35 // txContext := evmtypes.TxContext{ 36 // Origin: from, 37 // GasPrice: tx.GasPrice(), 38 // } 39 // context := evmtypes.BlockContext{ 40 // CanTransfer: core.CanTransfer, 41 // Transfer: core.Transfer, 42 // Coinbase: common.Address{}, 43 // BlockNumber: uint64(5), 44 // Time: 5, 45 // Difficulty: big.NewInt(0xffffffff), 46 // GasLimit: gas, 47 // BaseFee: uint256.NewInt(8), 48 // } 49 // var alloc []conf.Allocate 50 // // The code pushes 'deadbeef' into memory, then the other params, and calls CREATE2, then returns 51 // // the address 52 // loop := []byte{ 53 // byte(vm.JUMPDEST), // [ count ] 54 // byte(vm.PUSH1), 0, // jumpdestination 55 // byte(vm.JUMP), 56 // } 57 // alloc[] = conf.Allocate{ 58 // Address: common.HexToAddress("0x00000000000000000000000000000000deadbeef"), 59 // Nonce: 1, 60 // Code: loop, 61 // Balance: "1", 62 // } 63 // alloc[] = conf.Allocate{ 64 // Address: from, 65 // Nonce: 1, 66 // Code: []byte{}, 67 // Balance: big.NewInt(500000000000000), 68 // } 69 // _, statedb := tests.MakePreState(rawdb.NewMemoryDatabase(), alloc, false) 70 // // Create the tracer, the EVM environment and run it 71 // tracer := logger.NewStructLogger(&logger.Config{ 72 // Debug: false, 73 // //DisableStorage: true, 74 // //EnableMemory: false, 75 // //EnableReturnData: false, 76 // }) 77 // evm := vm.NewEVM(context, txContext, statedb, params.AllEthashProtocolChanges, vm.Config{Debug: true, Tracer: tracer}) 78 // msg, err := core.TransactionToMessage(tx, signer, nil) 79 // if err != nil { 80 // b.Fatalf("failed to prepare transaction for tracing: %v", err) 81 // } 82 // b.ResetTimer() 83 // b.ReportAllocs() 84 // 85 // for i := 0; i < b.N; i++ { 86 // snap := statedb.Snapshot() 87 // st := core.NewStateTransition(evm, msg, new(common2.GasPool).AddGas(tx.Gas())) 88 // _, err = st.TransitionDb() 89 // if err != nil { 90 // b.Fatal(err) 91 // } 92 // statedb.RevertToSnapshot(snap) 93 // if have, want := len(tracer.StructLogs()), 244752; have != want { 94 // b.Fatalf("trace wrong, want %d steps, have %d", want, have) 95 // } 96 // tracer.Reset() 97 // } 98 //}