github.com/devkononov/go-func@v0.0.0-20190722084534-f14392d369a7/cmd/clef/tests/testsigner.js (about) 1 // This file is a test-utility for testing clef-functionality 2 // 3 // Start clef with 4 // 5 // build/bin/clef --4bytedb=./cmd/clef/4byte.json --rpc 6 // 7 // Start geth with 8 // 9 // build/bin/geth --nodiscover --maxpeers 0 --signer http://localhost:8550 console --preload=cmd/clef/tests/testsigner.js 10 // 11 // and in the console simply invoke 12 // 13 // > test() 14 // 15 // You can reload the file via `reload()` 16 17 function reload(){ 18 loadScript("./cmd/clef/tests/testsigner.js"); 19 } 20 21 function init(){ 22 if (typeof accts == 'undefined' || accts.length == 0){ 23 accts = eth.accounts 24 console.log("Got accounts ", accts); 25 } 26 } 27 init() 28 function testTx(){ 29 if( accts && accts.length > 0) { 30 var a = accts[0] 31 var txdata = eth.signTransaction({from: a, to: a, value: 1, nonce: 1, gas: 1, gasPrice: 1}) 32 var v = parseInt(txdata.tx.v) 33 console.log("V value: ", v) 34 if (v == 37 || v == 38){ 35 console.log("Mainnet 155-protected chainid was used") 36 } 37 if (v == 27 || v == 28){ 38 throw new Error("Mainnet chainid was used, but without replay protection!") 39 } 40 } 41 } 42 function testSignText(){ 43 if( accts && accts.length > 0){ 44 var a = accts[0] 45 var r = eth.sign(a, "0x68656c6c6f20776f726c64"); //hello world 46 console.log("signing response", r) 47 } 48 } 49 function testClique(){ 50 if( accts && accts.length > 0){ 51 var a = accts[0] 52 var r = debug.testSignCliqueBlock(a, 0); // Sign genesis 53 console.log("signing response", r) 54 if( a != r){ 55 throw new Error("Requested signing by "+a+ " but got sealer "+r) 56 } 57 } 58 } 59 60 function test(){ 61 var tests = [ 62 testTx, 63 testSignText, 64 testClique, 65 ] 66 for( i in tests){ 67 try{ 68 tests[i]() 69 }catch(err){ 70 console.log(err) 71 } 72 } 73 }