github.com/theQRL/go-zond@v0.2.1/cmd/clef/tests/testsigner.js (about)

     1  // Copyright 2019 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU 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  // go-ethereum 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 General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // This file is a test-utility for testing clef-functionality
    18  //
    19  // Start clef with
    20  //
    21  // build/bin/clef --4bytedb=./cmd/clef/4byte.json --rpc
    22  //
    23  // Start gzond with
    24  //
    25  // build/bin/gzond --nodiscover --maxpeers 0 --signer http://localhost:8550 console --preload=cmd/clef/tests/testsigner.js
    26  //
    27  // and in the console simply invoke
    28  //
    29  // > test()
    30  //
    31  // You can reload the file via `reload()`
    32  
    33  function reload(){
    34  	loadScript("./cmd/clef/tests/testsigner.js");
    35  }
    36  
    37  function init(){
    38      if (typeof accts == 'undefined' || accts.length == 0){
    39          accts = zond.accounts
    40          console.log("Got accounts ", accts);
    41      }
    42  }
    43  init()
    44  function testTx(){
    45      if( accts && accts.length > 0) {
    46          var a = accts[0]
    47          var txdata = zond.signTransaction({from: a, to: a, value: 1, nonce: 1, gas: 1, maxFeePerGas: 1, maxPriorityFeePerGas: 0})
    48          console.log("transaction signing response",  txdata)
    49      }
    50  }
    51  function testSignText(){
    52      if( accts && accts.length > 0){
    53          var a = accts[0]
    54          var r = zond.sign(a, "0x68656c6c6f20776f726c64"); //hello world
    55          console.log("signing response",  r)
    56      }
    57  }
    58  
    59  function test(){
    60      var tests = [
    61          testTx,
    62          testSignText,
    63      ]
    64      for( i in tests){
    65          try{
    66              tests[i]()
    67          }catch(err){
    68              console.log(err)
    69          }
    70      }
    71   }