cmd/clef, signer: refresh tutorial, fix noticed issues (#19774)
* cmd/clef, signer: refresh tutorial, fix noticed issues * cmd/clef, signer: support removing stored keys (delpw + rules) * cmd/clef: polishes + Geth integration in the tutorial
This commit is contained in:
		| @@ -301,23 +301,23 @@ func TestStorage(t *testing.T) { | ||||
|  | ||||
| 	js := ` | ||||
| 	function testStorage(){ | ||||
| 		storage.Put("mykey", "myvalue") | ||||
| 		a = storage.Get("mykey") | ||||
| 		storage.put("mykey", "myvalue") | ||||
| 		a = storage.get("mykey") | ||||
|  | ||||
| 		storage.Put("mykey", ["a", "list"])  	// Should result in "a,list" | ||||
| 		a += storage.Get("mykey") | ||||
| 		storage.put("mykey", ["a", "list"])  	// Should result in "a,list" | ||||
| 		a += storage.get("mykey") | ||||
|  | ||||
|  | ||||
| 		storage.Put("mykey", {"an": "object"}) 	// Should result in "[object Object]" | ||||
| 		a += storage.Get("mykey") | ||||
| 		storage.put("mykey", {"an": "object"}) 	// Should result in "[object Object]" | ||||
| 		a += storage.get("mykey") | ||||
|  | ||||
|  | ||||
| 		storage.Put("mykey", JSON.stringify({"an": "object"})) // Should result in '{"an":"object"}' | ||||
| 		a += storage.Get("mykey") | ||||
| 		storage.put("mykey", JSON.stringify({"an": "object"})) // Should result in '{"an":"object"}' | ||||
| 		a += storage.get("mykey") | ||||
|  | ||||
| 		a += storage.Get("missingkey")		//Missing keys should result in empty string | ||||
| 		storage.Put("","missing key==noop") // Can't store with 0-length key | ||||
| 		a += storage.Get("")				// Should result in '' | ||||
| 		a += storage.get("missingkey")		//Missing keys should result in empty string | ||||
| 		storage.put("","missing key==noop") // Can't store with 0-length key | ||||
| 		a += storage.get("")				// Should result in '' | ||||
|  | ||||
| 		var b = new BigNumber(2) | ||||
| 		var c = new BigNumber(16)//"0xf0",16) | ||||
| @@ -337,7 +337,6 @@ func TestStorage(t *testing.T) { | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Unexpected error %v", err) | ||||
| 	} | ||||
|  | ||||
| 	retval, err := v.ToString() | ||||
|  | ||||
| 	if err != nil { | ||||
| @@ -369,7 +368,7 @@ const ExampleTxWindow = ` | ||||
| 		var windowstart = new Date().getTime() - window; | ||||
|  | ||||
| 		var txs = []; | ||||
| 		var stored = storage.Get('txs'); | ||||
| 		var stored = storage.get('txs'); | ||||
|  | ||||
| 		if(stored != ""){ | ||||
| 			txs = JSON.parse(stored) | ||||
| @@ -414,19 +413,18 @@ const ExampleTxWindow = ` | ||||
| 		var value = big(resp.tx.value) | ||||
| 		var txs = [] | ||||
| 		// Load stored transactions | ||||
| 		var stored = storage.Get('txs'); | ||||
| 		var stored = storage.get('txs'); | ||||
| 		if(stored != ""){ | ||||
| 			txs = JSON.parse(stored) | ||||
| 		} | ||||
| 		// Add this to the storage | ||||
| 		txs.push({tstamp: new Date().getTime(), value: value}); | ||||
| 		storage.Put("txs", JSON.stringify(txs)); | ||||
| 		storage.put("txs", JSON.stringify(txs)); | ||||
| 	} | ||||
|  | ||||
| ` | ||||
|  | ||||
| func dummyTx(value hexutil.Big) *core.SignTxRequest { | ||||
|  | ||||
| 	to, _ := mixAddr("000000000000000000000000000000000000dead") | ||||
| 	from, _ := mixAddr("000000000000000000000000000000000000dead") | ||||
| 	n := hexutil.Uint64(3) | ||||
| @@ -448,28 +446,27 @@ func dummyTx(value hexutil.Big) *core.SignTxRequest { | ||||
| 		Meta: core.Metadata{Remote: "remoteip", Local: "localip", Scheme: "inproc"}, | ||||
| 	} | ||||
| } | ||||
| func dummyTxWithV(value uint64) *core.SignTxRequest { | ||||
|  | ||||
| func dummyTxWithV(value uint64) *core.SignTxRequest { | ||||
| 	v := big.NewInt(0).SetUint64(value) | ||||
| 	h := hexutil.Big(*v) | ||||
| 	return dummyTx(h) | ||||
| } | ||||
|  | ||||
| func dummySigned(value *big.Int) *types.Transaction { | ||||
| 	to := common.HexToAddress("000000000000000000000000000000000000dead") | ||||
| 	gas := uint64(21000) | ||||
| 	gasPrice := big.NewInt(2000000) | ||||
| 	data := make([]byte, 0) | ||||
| 	return types.NewTransaction(3, to, value, gas, gasPrice, data) | ||||
|  | ||||
| } | ||||
| func TestLimitWindow(t *testing.T) { | ||||
|  | ||||
| func TestLimitWindow(t *testing.T) { | ||||
| 	r, err := initRuleEngine(ExampleTxWindow) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("Couldn't create evaluator %v", err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// 0.3 ether: 429D069189E0000 wei | ||||
| 	v := big.NewInt(0).SetBytes(common.Hex2Bytes("0429D069189E0000")) | ||||
| 	h := hexutil.Big(*v) | ||||
| @@ -496,7 +493,6 @@ func TestLimitWindow(t *testing.T) { | ||||
| 	if resp.Approved { | ||||
| 		t.Errorf("Expected check to resolve to 'Reject'") | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| // dontCallMe is used as a next-handler that does not want to be called - it invokes test failure | ||||
| @@ -508,6 +504,7 @@ func (d *dontCallMe) OnInputRequired(info core.UserInputRequest) (core.UserInput | ||||
| 	d.t.Fatalf("Did not expect next-handler to be called") | ||||
| 	return core.UserInputResponse{}, nil | ||||
| } | ||||
|  | ||||
| func (d *dontCallMe) RegisterUIServer(api *core.UIServerAPI) { | ||||
| } | ||||
|  | ||||
| @@ -589,7 +586,7 @@ func TestSignData(t *testing.T) { | ||||
| function ApproveSignData(r){ | ||||
|     if( r.address.toLowerCase() == "0x694267f14675d7e1b9494fd8d72fefe1755710fa") | ||||
|     { | ||||
|         if(r.message[0].value.indexOf("bazonk") >= 0){ | ||||
|         if(r.messages[0].value.indexOf("bazonk") >= 0){ | ||||
|             return "Approve" | ||||
|         } | ||||
|         return "Reject" | ||||
| @@ -615,11 +612,11 @@ function ApproveSignData(r){ | ||||
| 		}, | ||||
| 	} | ||||
| 	resp, err := r.ApproveSignData(&core.SignDataRequest{ | ||||
| 		Address: *addr, | ||||
| 		Message: nvt, | ||||
| 		Hash:    hash, | ||||
| 		Meta:    core.Metadata{Remote: "remoteip", Local: "localip", Scheme: "inproc"}, | ||||
| 		Rawdata: []byte(rawdata), | ||||
| 		Address:  *addr, | ||||
| 		Messages: nvt, | ||||
| 		Hash:     hash, | ||||
| 		Meta:     core.Metadata{Remote: "remoteip", Local: "localip", Scheme: "inproc"}, | ||||
| 		Rawdata:  []byte(rawdata), | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("Unexpected error %v", err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user