github.com/theQRL/go-zond@v0.1.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 geth with 24 // 25 // build/bin/geth --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 = eth.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 = eth.signTransaction({from: a, to: a, value: 1, nonce: 1, gas: 1, gasPrice: 1}) 48 var v = parseInt(txdata.tx.v) 49 console.log("V value: ", v) 50 if (v == 37 || v == 38){ 51 console.log("Mainnet 155-protected chainid was used") 52 } 53 if (v == 27 || v == 28){ 54 throw new Error("Mainnet chainid was used, but without replay protection!") 55 } 56 } 57 } 58 function testSignText(){ 59 if( accts && accts.length > 0){ 60 var a = accts[0] 61 var r = eth.sign(a, "0x68656c6c6f20776f726c64"); //hello world 62 console.log("signing response", r) 63 } 64 } 65 function testClique(){ 66 if( accts && accts.length > 0){ 67 var a = accts[0] 68 var r = debug.testSignCliqueBlock(a, 0); // Sign genesis 69 console.log("signing response", r) 70 if( a != r){ 71 throw new Error("Requested signing by "+a+ " but got sealer "+r) 72 } 73 } 74 } 75 76 function test(){ 77 var tests = [ 78 testTx, 79 testSignText, 80 testClique, 81 ] 82 for( i in tests){ 83 try{ 84 tests[i]() 85 }catch(err){ 86 console.log(err) 87 } 88 } 89 }