@@ -23,7 +23,6 @@ import (
2323 "errors"
2424 "fmt"
2525 "math/big"
26- "os"
2726 "reflect"
2827 "slices"
2928 "sync/atomic"
@@ -1376,118 +1375,3 @@ func TestTraceBlockWithBasefee(t *testing.T) {
13761375 }
13771376 }
13781377}
1379-
1380- func TestStandardTraceBlockToFile (t * testing.T ) {
1381- var (
1382- // A sender who makes transactions, has some funds
1383- key , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
1384- address = crypto .PubkeyToAddress (key .PublicKey )
1385- funds = big .NewInt (1000000000000000 )
1386-
1387- // first contract the sender transacts with
1388- aa = common .HexToAddress ("0x7217d81b76bdd8707601e959454e3d776aee5f43" )
1389- aaCode = []byte {byte (vm .PUSH1 ), 0x00 , byte (vm .POP )}
1390-
1391- // second contract the sender transacts with
1392- bb = common .HexToAddress ("0x7217d81b76bdd8707601e959454e3d776aee5f44" )
1393- bbCode = []byte {byte (vm .PUSH2 ), 0x00 , 0x01 , byte (vm .POP )}
1394- )
1395-
1396- genesis := & core.Genesis {
1397- Config : params .TestChainConfig ,
1398- Alloc : types.GenesisAlloc {
1399- address : {Balance : funds },
1400- aa : {
1401- Code : aaCode ,
1402- Nonce : 1 ,
1403- Balance : big .NewInt (0 ),
1404- },
1405- bb : {
1406- Code : bbCode ,
1407- Nonce : 1 ,
1408- Balance : big .NewInt (0 ),
1409- },
1410- },
1411- }
1412- txHashs := make ([]common.Hash , 0 , 2 )
1413- backend := newTestBackend (t , 1 , genesis , func (i int , b * core.BlockGen ) {
1414- b .SetCoinbase (common.Address {1 })
1415- // first tx to aa
1416- tx , _ := types .SignTx (types .NewTx (& types.LegacyTx {
1417- Nonce : 0 ,
1418- To : & aa ,
1419- Value : big .NewInt (0 ),
1420- Gas : 50000 ,
1421- GasPrice : b .BaseFee (),
1422- Data : nil ,
1423- }), types.HomesteadSigner {}, key )
1424- b .AddTx (tx )
1425- txHashs = append (txHashs , tx .Hash ())
1426- // second tx to bb
1427- tx , _ = types .SignTx (types .NewTx (& types.LegacyTx {
1428- Nonce : 1 ,
1429- To : & bb ,
1430- Value : big .NewInt (1 ),
1431- Gas : 100000 ,
1432- GasPrice : b .BaseFee (),
1433- Data : nil ,
1434- }), types.HomesteadSigner {}, key )
1435- b .AddTx (tx )
1436- txHashs = append (txHashs , tx .Hash ())
1437- })
1438- defer backend .chain .Stop ()
1439-
1440- var testSuite = []struct {
1441- blockNumber rpc.BlockNumber
1442- config * StdTraceConfig
1443- want []string
1444- }{
1445- {
1446- // test that all traces in the block were outputted if no trace config is specified
1447- blockNumber : rpc .LatestBlockNumber ,
1448- config : nil ,
1449- want : []string {
1450- `{"pc":0,"op":96,"gas":"0x7148","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
1451- {"pc":2,"op":80,"gas":"0x7145","gasCost":"0x2","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"POP"}
1452- {"pc":3,"op":0,"gas":"0x7143","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
1453- {"output":"","gasUsed":"0x5"}
1454- ` ,
1455- `{"pc":0,"op":97,"gas":"0x13498","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH2"}
1456- {"pc":3,"op":80,"gas":"0x13495","gasCost":"0x2","memSize":0,"stack":["0x1"],"depth":1,"refund":0,"opName":"POP"}
1457- {"pc":4,"op":0,"gas":"0x13493","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
1458- {"output":"","gasUsed":"0x5"}
1459- ` ,
1460- },
1461- },
1462- {
1463- // test that only a specific tx is traced if specified
1464- blockNumber : rpc .LatestBlockNumber ,
1465- config : & StdTraceConfig {TxHash : txHashs [1 ]},
1466- want : []string {
1467- `{"pc":0,"op":97,"gas":"0x13498","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH2"}
1468- {"pc":3,"op":80,"gas":"0x13495","gasCost":"0x2","memSize":0,"stack":["0x1"],"depth":1,"refund":0,"opName":"POP"}
1469- {"pc":4,"op":0,"gas":"0x13493","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}
1470- {"output":"","gasUsed":"0x5"}
1471- ` ,
1472- },
1473- },
1474- }
1475-
1476- api := NewAPI (backend )
1477- for i , tc := range testSuite {
1478- block , _ := api .blockByNumber (context .Background (), tc .blockNumber )
1479- txTraces , err := api .StandardTraceBlockToFile (context .Background (), block .Hash (), tc .config )
1480- if err != nil {
1481- t .Fatalf ("test index %d received error %v" , i , err )
1482- }
1483- for j , traceFileName := range txTraces {
1484- traceReceived , err := os .ReadFile (traceFileName )
1485- if err != nil {
1486- t .Fatalf ("could not read trace file: %v" , err )
1487- }
1488- if tc .want [j ] != string (traceReceived ) {
1489- t .Fatalf ("unexpected trace result. expected\n '%s'\n \n received\n '%s'\n " , tc .want [j ], string (traceReceived ))
1490- }
1491- }
1492- }
1493- }
0 commit comments