@@ -29,7 +29,6 @@ import (
29
29
"testing"
30
30
"time"
31
31
32
- "github.com/celo-org/celo-blockchain/accounts/abi"
33
32
"github.com/celo-org/celo-blockchain/common"
34
33
"github.com/celo-org/celo-blockchain/common/hexutil"
35
34
"github.com/celo-org/celo-blockchain/consensus"
@@ -468,130 +467,6 @@ func TestCallTraceTransactionNativeTransfer(t *testing.T) {
468
467
}
469
468
}
470
469
471
- // Use the callTracer to trace a CELO transfer made via the transfer
472
- // precompile (by sending this from the registered GoldToken contract).
473
- func TestCallTraceTransactionPrecompileTransfer (t * testing.T ) {
474
- // Invoke the transfer precompile by sending a transfer from an account
475
- // registered as GoldToken in the mock registry
476
- t .Parallel ()
477
- // Initialize test accounts
478
- accounts := newAccounts (3 )
479
- goldToken := accounts [0 ]
480
- registryProxyAddr := common .HexToAddress ("0xce10" )
481
- registryImplAddr := common .HexToAddress ("0xce11" )
482
- genesis := & core.Genesis {Alloc : core.GenesisAlloc {
483
- goldToken .addr : {Balance : big .NewInt (params .Ether )},
484
- accounts [1 ].addr : {Balance : big .NewInt (params .Ether )},
485
- accounts [2 ].addr : {Balance : big .NewInt (params .Ether )},
486
- registryProxyAddr : { // Registry Proxy
487
- Code : testutil .RegistryProxyOpcodes ,
488
- Storage : map [common.Hash ]common.Hash {
489
- common .HexToHash ("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ): common .HexToHash ("0xce11" ), // Registry Implementation
490
- common .HexToHash ("0x91646b8507bf2e54d7c3de9155442ba111546b81af1cbdd1f68eeb6926b98d58" ): common .HexToHash ("0xd023" ), // Governance Proxy
491
- common .HexToHash ("0x773cc8652456781771d48fb3d560d7ba3d6d1882654492b68beec583d2c590aa" ): goldToken .addr .Hash (), // GoldToken Implementation
492
- common .HexToHash ("0x2131a4338f6fb8d4507e234a7c72af8efefbbf2f1817ed570bce33eb6667feb9" ): common .HexToHash ("0xd007" ), // Reserve Implementation
493
- },
494
- Balance : big .NewInt (0 ),
495
- },
496
- registryImplAddr : { // Registry Implementation
497
- Code : testutil .RegistryOpcodes ,
498
- Balance : big .NewInt (0 ),
499
- },
500
- }}
501
-
502
- target := common.Hash {}
503
- signer := types.HomesteadSigner {}
504
- transferVal := big .NewInt (1000 )
505
-
506
- // Construct and pack data for transfer precompile representing [from, to, value]
507
- addressTy , err := abi .NewType ("address" , "" , nil )
508
- if err != nil {
509
- t .Fatalf ("failed to create address type: %v" , err )
510
- }
511
- uint256Ty , err := abi .NewType ("uint256" , "" , nil )
512
- if err != nil {
513
- t .Fatalf ("failed to create uint256 type: %v" , err )
514
- }
515
-
516
- transferArgs := abi.Arguments {
517
- {
518
- Type : addressTy ,
519
- },
520
- {
521
- Type : addressTy ,
522
- },
523
- {
524
- Type : uint256Ty ,
525
- },
526
- }
527
- data , err := transferArgs .Pack (accounts [1 ].addr , accounts [2 ].addr , transferVal )
528
- if err != nil {
529
- t .Fatalf ("failed to pack args: %v" , err )
530
- }
531
- transferPrecompile := common .HexToAddress ("0xfd" )
532
- gas := params .TxGas * 2
533
- api := NewAPI (newTestBackend (t , 1 , genesis , func (i int , b * core.BlockGen ) {
534
- // Transfer via transfer precompile by sending tx from GoldToken addr
535
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ), transferPrecompile , big .NewInt (0 ), gas , big .NewInt (3 ), nil , nil , nil , data ), signer , goldToken .key )
536
- b .AddTx (tx )
537
- target = tx .Hash ()
538
- }))
539
- tracerStr := "callTracer"
540
- result , err := api .TraceTransaction (context .Background (), target , & TraceConfig {Tracer : & tracerStr })
541
-
542
- if err != nil {
543
- t .Errorf ("Failed to trace transaction %v" , err )
544
- }
545
-
546
- ret := new (callTrace )
547
- if err := json .Unmarshal (result .(json.RawMessage ), ret ); err != nil {
548
- t .Fatalf ("failed to unmarshal trace result: %v" , err )
549
- }
550
-
551
- // Registry ABI packed version of Registry.getAddressFor("GoldToken")
552
- packedGetAddressForGoldToken := common .FromHex ("0xdd927233d7e89ade8430819f08bf97a087285824af3351ee12d72a2d132b0c6c0687bfaf" )
553
- expectedTrace := & callTrace {
554
- // Outer transaction call
555
- Type : "CALL" ,
556
- From : goldToken .addr ,
557
- To : transferPrecompile ,
558
- Input : data ,
559
- Output : data ,
560
- Gas : newRPCUint64 (20112 ),
561
- // Note that top-level traces do not currently include intrinsic gas
562
- GasUsed : newRPCUint64 (params .CallValueTransferGas ),
563
- Value : (* hexutil .Big )(big .NewInt (0 )),
564
- Calls : []callTrace {
565
- {
566
- // Lookup of GoldToken contract address with capped gas
567
- Type : "STATICCALL" ,
568
- From : common .ZeroAddress ,
569
- To : registryProxyAddr ,
570
- Input : packedGetAddressForGoldToken ,
571
- Output : common .LeftPadBytes (goldToken .addr .Bytes (), 32 ),
572
- Gas : newRPCUint64 (params .MaxGasForGetAddressFor ),
573
- GasUsed : newRPCUint64 (0 ),
574
- Calls : []callTrace {
575
- {
576
- // RegistryProxy -> RegistryImpl delegate call to
577
- // retrieve GoldToken address
578
- Type : "DELEGATECALL" ,
579
- From : registryProxyAddr ,
580
- To : registryImplAddr ,
581
- Input : packedGetAddressForGoldToken ,
582
- Output : common .LeftPadBytes (goldToken .addr .Bytes (), 32 ),
583
- Gas : newRPCUint64 (0 ),
584
- GasUsed : newRPCUint64 (0 ),
585
- },
586
- },
587
- },
588
- },
589
- }
590
- if ! jsonEqual (ret , expectedTrace ) {
591
- t .Fatalf ("trace mismatch: \n have %+v\n want %+v" , ret , expectedTrace )
592
- }
593
- }
594
-
595
470
func TestTraceBlock (t * testing.T ) {
596
471
t .Parallel ()
597
472
0 commit comments