github.com/theQRL/go-zond@v0.2.1/zond/tracers/internal/tracetest/util.go (about)

     1  package tracetest
     2  
     3  import (
     4  	"strings"
     5  	"unicode"
     6  
     7  	// Force-load native and js packages, to trigger registration
     8  	_ "github.com/theQRL/go-zond/zond/tracers/js"
     9  	_ "github.com/theQRL/go-zond/zond/tracers/native"
    10  )
    11  
    12  // To generate a new callTracer test, copy paste the makeTest method below into
    13  // a Gzond console and call it with a transaction hash you which to export.
    14  
    15  /*
    16  // makeTest generates a callTracer test by running a prestate reassembled and a
    17  // call trace run, assembling all the gathered information into a test case.
    18  var makeTest = function(tx, rewind) {
    19    // Generate the genesis block from the block, transaction and prestate data
    20    var block   = zond.getBlock(zond.getTransaction(tx).blockHash);
    21    var genesis = zond.getBlock(block.parentHash);
    22  
    23    delete genesis.gasUsed;
    24    delete genesis.logsBloom;
    25    delete genesis.parentHash;
    26    delete genesis.receiptsRoot;
    27    delete genesis.size;
    28    delete genesis.transactions;
    29    delete genesis.transactionsRoot;
    30  
    31    genesis.gasLimit  = genesis.gasLimit.toString();
    32    genesis.number    = genesis.number.toString();
    33    genesis.timestamp = genesis.timestamp.toString();
    34  
    35    genesis.alloc = debug.traceTransaction(tx, {tracer: "prestateTracer", rewind: rewind});
    36    for (var key in genesis.alloc) {
    37      var nonce = genesis.alloc[key].nonce;
    38      if (nonce) {
    39        genesis.alloc[key].nonce = nonce.toString();
    40      }
    41    }
    42    genesis.config = admin.nodeInfo.protocols.zond.config;
    43  
    44    // Generate the call trace and produce the test input
    45    var result = debug.traceTransaction(tx, {tracer: "callTracer", rewind: rewind});
    46    delete result.time;
    47  
    48    console.log(JSON.stringify({
    49      genesis: genesis,
    50      context: {
    51        number:     block.number.toString(),
    52        timestamp:  block.timestamp.toString(),
    53        gasLimit:   block.gasLimit.toString(),
    54        miner:      block.miner,
    55      },
    56      input:  zond.getRawTransaction(tx),
    57      result: result,
    58    }, null, 2));
    59  }
    60  */
    61  
    62  // camel converts a snake cased input string into a camel cased output.
    63  func camel(str string) string {
    64  	pieces := strings.Split(str, "_")
    65  	for i := 1; i < len(pieces); i++ {
    66  		pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
    67  	}
    68  	return strings.Join(pieces, "")
    69  }