2020-09-22 14:53:52 +02:00
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of OpenEthereum.
2016-03-14 00:48:43 +01:00
2020-09-22 14:53:52 +02:00
// OpenEthereum is free software: you can redistribute it and/or modify
2016-03-14 00:48:43 +01:00
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
2020-09-22 14:53:52 +02:00
// OpenEthereum is distributed in the hope that it will be useful,
2016-03-14 00:48:43 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
2020-09-22 14:53:52 +02:00
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
2016-03-14 00:48:43 +01:00
2016-05-26 20:10:15 +02:00
use std ::{ str ::FromStr , sync ::Arc } ;
2017-02-08 17:57:18 +01:00
2019-02-07 14:34:24 +01:00
use accounts ::AccountProvider ;
2019-02-25 14:27:28 +01:00
use bytes ::ToPretty ;
2017-02-08 17:57:18 +01:00
use ethcore ::client ::TestBlockChainClient ;
2019-02-25 14:27:28 +01:00
use ethereum_types ::{ Address , H520 , U256 } ;
2018-11-14 09:02:40 +01:00
use hash ::keccak ;
2017-01-11 20:02:27 +01:00
use jsonrpc_core ::IoHandler ;
2018-10-22 09:40:50 +02:00
use parity_runtime ::Runtime ;
2017-11-01 11:23:18 +01:00
use parking_lot ::Mutex ;
2019-01-04 14:05:46 +01:00
use types ::transaction ::{ Action , Transaction } ;
2017-02-08 17:57:18 +01:00
2018-01-10 21:44:10 +01:00
use ethkey ::Secret ;
2018-11-14 09:02:40 +01:00
use rustc_hex ::ToHex ;
use serde_json ::to_value ;
use v1 ::{
2020-08-05 06:08:03 +02:00
helpers ::{
2018-11-14 09:02:40 +01:00
dispatch ::{ eth_data_hash , FullDispatcher } ,
eip191 , nonce ,
2020-08-05 06:08:03 +02:00
} ,
2018-11-14 09:02:40 +01:00
tests ::helpers ::TestMinerService ,
types ::{ EIP191Version , PresignedTransaction } ,
Metadata , Personal , PersonalClient ,
} ;
2016-05-26 20:10:15 +02:00
struct PersonalTester {
2018-10-22 09:40:50 +02:00
_runtime : Runtime ,
2016-06-20 00:10:34 +02:00
accounts : Arc < AccountProvider > ,
2017-01-30 21:08:36 +01:00
io : IoHandler < Metadata > ,
2016-05-26 20:10:15 +02:00
miner : Arc < TestMinerService > ,
}
fn blockchain_client ( ) -> Arc < TestBlockChainClient > {
let client = TestBlockChainClient ::new ( ) ;
Arc ::new ( client )
}
2016-03-14 00:48:43 +01:00
2016-06-20 00:10:34 +02:00
fn accounts_provider ( ) -> Arc < AccountProvider > {
Arc ::new ( AccountProvider ::transient_provider ( ) )
2016-03-14 00:48:43 +01:00
}
2016-05-26 20:10:15 +02:00
fn miner_service ( ) -> Arc < TestMinerService > {
Arc ::new ( TestMinerService ::default ( ) )
}
2016-10-24 12:21:15 +02:00
fn setup ( ) -> PersonalTester {
2018-11-16 14:00:34 +01:00
setup_with ( Config {
allow_experimental_rpcs : true ,
} )
}
struct Config {
pub allow_experimental_rpcs : bool ,
}
fn setup_with ( c : Config ) -> PersonalTester {
2018-10-22 09:40:50 +02:00
let runtime = Runtime ::with_thread_count ( 1 ) ;
2016-05-26 20:10:15 +02:00
let accounts = accounts_provider ( ) ;
let client = blockchain_client ( ) ;
let miner = miner_service ( ) ;
2018-10-22 09:40:50 +02:00
let reservations = Arc ::new ( Mutex ::new ( nonce ::Reservations ::new ( runtime . executor ( ) ) ) ) ;
2020-08-05 06:08:03 +02:00
2018-01-09 12:43:36 +01:00
let dispatcher = FullDispatcher ::new ( client , miner . clone ( ) , reservations , 50 ) ;
2020-08-07 19:36:32 +02:00
let personal = PersonalClient ::new ( & accounts , dispatcher , c . allow_experimental_rpcs ) ;
2020-08-05 06:08:03 +02:00
2017-01-11 20:02:27 +01:00
let mut io = IoHandler ::default ( ) ;
io . extend_with ( personal . to_delegate ( ) ) ;
2020-08-05 06:08:03 +02:00
2016-05-26 20:10:15 +02:00
let tester = PersonalTester {
2018-10-22 09:40:50 +02:00
_runtime : runtime ,
2016-05-26 20:10:15 +02:00
accounts : accounts ,
io : io ,
miner : miner ,
} ;
2020-08-05 06:08:03 +02:00
2016-05-26 20:10:15 +02:00
tester
2016-03-14 00:48:43 +01:00
}
#[ test ]
fn accounts ( ) {
2016-10-24 12:21:15 +02:00
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " " . into ( ) ) . unwrap ( ) ;
2016-03-14 00:48:43 +01:00
let request = r # "{"jsonrpc": "2.0", "method": "personal_listAccounts", "params": [], "id": 1}"# ;
2018-04-02 13:12:52 +02:00
let response = r # "{"jsonrpc":"2.0","result":[""# . to_owned ( )
+ & format! ( " 0x {:x} " , address )
+ r # ""],"id":1}"# ;
2020-08-05 06:08:03 +02:00
2016-09-01 12:00:00 +02:00
assert_eq! (
tester . io . handle_request_sync ( request ) ,
Some ( response . to_owned ( ) )
) ;
2016-03-14 00:48:43 +01:00
}
2016-03-14 01:06:42 +01:00
#[ test ]
fn new_account ( ) {
2016-10-24 12:21:15 +02:00
let tester = setup ( ) ;
2016-03-14 01:06:42 +01:00
let request =
r # "{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"# ;
2016-09-01 12:00:00 +02:00
let res = tester . io . handle_request_sync ( request ) ;
2016-04-06 12:15:20 +02:00
2016-07-31 10:44:17 +02:00
let accounts = tester . accounts . accounts ( ) . unwrap ( ) ;
2016-04-06 12:15:20 +02:00
assert_eq! ( accounts . len ( ) , 1 ) ;
2016-06-20 00:10:34 +02:00
let address = accounts [ 0 ] ;
2018-04-02 13:12:52 +02:00
let response = r # "{"jsonrpc":"2.0","result":""# . to_owned ( )
+ format! ( " 0x {:x} " , address ) . as_ref ( )
+ r # "","id":1}"# ;
2016-04-06 12:15:20 +02:00
assert_eq! ( res , Some ( response ) ) ;
2016-03-14 01:06:42 +01:00
}
2017-12-19 10:49:49 +01:00
fn invalid_password_test ( method : & str ) {
2016-10-24 12:21:15 +02:00
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2017-12-19 10:49:49 +01:00
2016-05-26 20:10:15 +02:00
let request = r #" {
" jsonrpc " : " 2.0 " ,
2017-12-19 10:49:49 +01:00
" method " : " " #
. to_owned ( )
+ method
+ r #" " ,
2016-05-26 20:10:15 +02:00
" params " : [ {
2018-04-02 13:12:52 +02:00
" from " : " " #
+ format! ( " 0x {:x} " , address ) . as_ref ( )
+ r #" " ,
2016-05-26 20:10:15 +02:00
" to " : " 0xd46e8dd67c5d32be8058bb8eb970870f07244567 " ,
" gas " : " 0x76c0 " ,
" gasPrice " : " 0x9184e72a000 " ,
" value " : " 0x9184e72a "
} , " password321 " ] ,
" id " : 1
2018-01-09 12:43:36 +01:00
} " #;
2016-05-26 20:10:15 +02:00
2016-07-20 12:37:49 +02:00
let response = r # "{"jsonrpc":"2.0","error":{"code":-32021,"message":"Account password is invalid or account does not exist.","data":"SStore(InvalidPassword)"},"id":1}"# ;
2016-05-26 20:10:15 +02:00
2016-09-01 12:00:00 +02:00
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response . into ( ) )
) ;
2016-05-26 20:10:15 +02:00
}
2018-01-10 21:44:10 +01:00
#[ test ]
fn sign ( ) {
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2018-01-10 21:44:10 +01:00
let data = vec! [ 5 u8 ] ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_sign " ,
" params " : [
" " #
. to_owned ( )
+ format! ( " 0x {} " , data . to_hex ( ) ) . as_ref ( )
2018-04-02 13:12:52 +02:00
+ r #" " ,
" " # + format! ( " 0x {:x} " , address ) . as_ref ( )
2020-08-05 06:08:03 +02:00
+ r #" " ,
2018-01-10 21:44:10 +01:00
" password123 "
] ,
" id " : 1
} " #;
let hash = eth_data_hash ( data ) ;
let signature = H520 (
tester
. accounts
. sign ( address , Some ( " password123 " . into ( ) ) , hash )
. unwrap ( )
. into_electrum ( ) ,
) ;
2019-02-25 14:27:28 +01:00
let signature = format! ( " {:?} " , signature ) ;
2020-08-05 06:08:03 +02:00
2018-01-10 21:44:10 +01:00
let response = r # "{"jsonrpc":"2.0","result":""# . to_owned ( ) + & signature + r # "","id":1}"# ;
2020-08-05 06:08:03 +02:00
2018-01-10 21:44:10 +01:00
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response )
) ;
}
#[ test ]
fn sign_with_invalid_password ( ) {
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2018-01-10 21:44:10 +01:00
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_sign " ,
" params " : [
" 0x0000000000000000000000000000000000000000000000000000000000000005 " ,
2018-04-02 13:12:52 +02:00
" " #
. to_owned ( )
+ format! ( " 0x {:x} " , address ) . as_ref ( )
+ r #" " ,
2018-01-10 21:44:10 +01:00
" "
] ,
" id " : 1
} " #;
let response = r # "{"jsonrpc":"2.0","error":{"code":-32021,"message":"Account password is invalid or account does not exist.","data":"SStore(InvalidPassword)"},"id":1}"# ;
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response . into ( ) )
) ;
}
2017-12-19 10:49:49 +01:00
#[ test ]
fn sign_transaction_with_invalid_password ( ) {
invalid_password_test ( " personal_signTransaction " ) ;
}
#[ test ]
fn sign_and_send_transaction_with_invalid_password ( ) {
invalid_password_test ( " personal_sendTransaction " ) ;
}
2017-02-15 16:57:27 +01:00
#[ test ]
fn send_transaction ( ) {
sign_and_send_test ( " personal_sendTransaction " ) ;
}
2016-05-26 20:10:15 +02:00
#[ test ]
fn sign_and_send_transaction ( ) {
2017-02-15 16:57:27 +01:00
sign_and_send_test ( " personal_signAndSendTransaction " ) ;
}
fn sign_and_send_test ( method : & str ) {
2016-10-24 12:21:15 +02:00
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2016-06-20 00:10:34 +02:00
2016-05-26 20:10:15 +02:00
let request = r #" {
" jsonrpc " : " 2.0 " ,
2017-02-15 16:57:27 +01:00
" method " : " " #
. to_owned ( )
+ method
+ r #" " ,
2016-05-26 20:10:15 +02:00
" params " : [ {
2018-04-02 13:12:52 +02:00
" from " : " " #
+ format! ( " 0x {:x} " , address ) . as_ref ( )
+ r #" " ,
2016-05-26 20:10:15 +02:00
" to " : " 0xd46e8dd67c5d32be8058bb8eb970870f07244567 " ,
" gas " : " 0x76c0 " ,
" gasPrice " : " 0x9184e72a000 " ,
" value " : " 0x9184e72a "
} , " password123 " ] ,
" id " : 1
} " #;
let t = Transaction {
nonce : U256 ::zero ( ) ,
gas_price : U256 ::from ( 0x9184e72a000 u64 ) ,
gas : U256 ::from ( 0x76c0 ) ,
action : Action ::Call (
Address ::from_str ( " d46e8dd67c5d32be8058bb8eb970870f07244567 " ) . unwrap ( ) ,
2020-08-05 06:08:03 +02:00
) ,
2016-05-26 20:10:15 +02:00
value : U256 ::from ( 0x9184e72a u64 ) ,
data : vec ! [ ] ,
2016-06-20 00:10:34 +02:00
} ;
tester
. accounts
. unlock_account_temporarily ( address , " password123 " . into ( ) )
. unwrap ( ) ;
2016-11-03 22:22:25 +01:00
let signature = tester . accounts . sign ( address , None , t . hash ( None ) ) . unwrap ( ) ;
let t = t . with_signature ( signature , None ) ;
2020-08-05 06:08:03 +02:00
2018-04-02 13:12:52 +02:00
let response = r # "{"jsonrpc":"2.0","result":""# . to_owned ( )
+ format! ( " 0x {:x} " , t . hash ( ) ) . as_ref ( )
+ r # "","id":1}"# ;
2020-08-05 06:08:03 +02:00
2016-09-01 12:00:00 +02:00
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response )
) ;
2020-08-05 06:08:03 +02:00
2018-04-13 17:34:27 +02:00
tester . miner . increment_nonce ( & address ) ;
2020-08-05 06:08:03 +02:00
2016-05-26 20:10:15 +02:00
let t = Transaction {
nonce : U256 ::one ( ) ,
gas_price : U256 ::from ( 0x9184e72a000 u64 ) ,
gas : U256 ::from ( 0x76c0 ) ,
action : Action ::Call (
Address ::from_str ( " d46e8dd67c5d32be8058bb8eb970870f07244567 " ) . unwrap ( ) ,
2020-08-05 06:08:03 +02:00
) ,
2016-05-26 20:10:15 +02:00
value : U256 ::from ( 0x9184e72a u64 ) ,
data : vec ! [ ] ,
2016-06-20 00:10:34 +02:00
} ;
tester
. accounts
. unlock_account_temporarily ( address , " password123 " . into ( ) )
. unwrap ( ) ;
2016-11-03 22:22:25 +01:00
let signature = tester . accounts . sign ( address , None , t . hash ( None ) ) . unwrap ( ) ;
let t = t . with_signature ( signature , None ) ;
2020-08-05 06:08:03 +02:00
2018-04-02 13:12:52 +02:00
let response = r # "{"jsonrpc":"2.0","result":""# . to_owned ( )
+ format! ( " 0x {:x} " , t . hash ( ) ) . as_ref ( )
+ r # "","id":1}"# ;
2020-08-05 06:08:03 +02:00
2016-09-01 12:00:00 +02:00
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response )
) ;
2016-06-01 19:37:34 +02:00
}
2016-11-28 17:15:40 +01:00
2018-01-10 21:44:10 +01:00
#[ test ]
fn ec_recover ( ) {
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2018-01-10 21:44:10 +01:00
let data = vec! [ 5 u8 ] ;
2020-08-05 06:08:03 +02:00
2018-01-10 21:44:10 +01:00
let hash = eth_data_hash ( data . clone ( ) ) ;
let signature = H520 (
tester
. accounts
. sign ( address , Some ( " password123 " . into ( ) ) , hash )
. unwrap ( )
. into_electrum ( ) ,
) ;
2019-02-25 14:27:28 +01:00
let signature = format! ( " {:?} " , signature ) ;
2020-08-05 06:08:03 +02:00
2018-01-10 21:44:10 +01:00
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_ecRecover " ,
" params " : [
" " #
. to_owned ( )
+ format! ( " 0x {} " , data . to_hex ( ) ) . as_ref ( )
+ r #" " ,
" " # + & signature
+ r #" "
] ,
" id " : 1
} " #;
2018-04-02 13:12:52 +02:00
let address = format! ( " 0x {:x} " , address ) ;
2018-01-10 21:44:10 +01:00
let response = r # "{"jsonrpc":"2.0","result":""# . to_owned ( ) + & address + r # "","id":1}"# ;
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response . into ( ) )
) ;
}
#[ test ]
fn ec_recover_invalid_signature ( ) {
let tester = setup ( ) ;
let data = vec! [ 5 u8 ] ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_ecRecover " ,
" params " : [
" " #
. to_owned ( )
+ format! ( " 0x {} " , data . to_hex ( ) ) . as_ref ( )
+ r #" " ,
" 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 "
] ,
" id " : 1
} " #;
let response = r # "{"jsonrpc":"2.0","error":{"code":-32055,"message":"Encryption error.","data":"InvalidSignature"},"id":1}"# ;
assert_eq! (
tester . io . handle_request_sync ( request . as_ref ( ) ) ,
Some ( response . into ( ) )
) ;
}
2016-11-28 17:15:40 +01:00
#[ test ]
fn should_unlock_account_permanently ( ) {
let tester = setup ( ) ;
2018-06-22 15:09:15 +02:00
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
2016-11-28 17:15:40 +01:00
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_unlockAccount " ,
" params " : [
2018-04-02 13:12:52 +02:00
" " #
. to_owned ( )
+ & format! ( " 0x {:x} " , address )
+ r #" " ,
2016-11-28 17:15:40 +01:00
" password123 " ,
null
] ,
" id " : 1
} " #;
let response = r # "{"jsonrpc":"2.0","result":true,"id":1}"# ;
assert_eq! (
tester . io . handle_request_sync ( & request ) ,
Some ( response . into ( ) )
) ;
assert! (
tester
. accounts
. sign ( address , None , Default ::default ( ) )
. is_ok ( ) ,
" Should unlock account. "
) ;
}
2018-11-14 09:02:40 +01:00
#[ test ]
fn sign_eip191_with_validator ( ) {
let tester = setup ( ) ;
let address = tester . accounts . new_account ( & " password123 " . into ( ) ) . unwrap ( ) ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_sign191 " ,
" params " : [
" 0x00 " ,
{
" validator " : " " #
. to_owned ( )
+ & format! ( " 0x {:x} " , address )
+ r #" " ,
" data " : " " #
+ & format! ( " 0x {:x} " , keccak ( " hello world " ) )
+ r #" "
} ,
" " # + & format! ( " 0x {:x} " , address )
+ r #" " ,
" password123 "
] ,
" id " : 1
} " #;
let with_validator = to_value ( PresignedTransaction {
validator : address . into ( ) ,
data : keccak ( " hello world " ) . to_vec ( ) . into ( ) ,
} )
. unwrap ( ) ;
let result = eip191 ::hash_message ( EIP191Version ::PresignedTransaction , with_validator ) . unwrap ( ) ;
let result = tester
. accounts
. sign ( address , Some ( " password123 " . into ( ) ) , result )
. unwrap ( )
. into_electrum ( ) ;
let expected = r # "{"jsonrpc":"2.0","result":""# . to_owned ( )
+ & format! ( " 0x {} " , result . to_hex ( ) )
+ r # "","id":1}"# ;
let response = tester . io . handle_request_sync ( & request ) . unwrap ( ) ;
assert_eq! ( response , expected )
}
#[ test ]
fn sign_eip191_structured_data ( ) {
let tester = setup ( ) ;
let secret : Secret = keccak ( " cow " ) . into ( ) ;
let address = tester
. accounts
. insert_account ( secret , & " lol " . into ( ) )
. unwrap ( ) ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_sign191 " ,
" params " : [
" 0x01 " ,
{
" primaryType " : " Mail " ,
" domain " : {
" name " : " Ether Mail " ,
" version " : " 1 " ,
" chainId " : " 0x1 " ,
" verifyingContract " : " 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC "
} ,
" message " : {
" from " : {
" name " : " Cow " ,
" wallet " : " 0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 "
} ,
" to " : {
" name " : " Bob " ,
" wallet " : " 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB "
} ,
" contents " : " Hello, Bob! "
} ,
" types " : {
" EIP712Domain " : [
{ " name " : " name " , " type " : " string " } ,
{ " name " : " version " , " type " : " string " } ,
{ " name " : " chainId " , " type " : " uint256 " } ,
{ " name " : " verifyingContract " , " type " : " address " }
] ,
" Person " : [
{ " name " : " name " , " type " : " string " } ,
{ " name " : " wallet " , " type " : " address " }
] ,
" Mail " : [
{ " name " : " from " , " type " : " Person " } ,
{ " name " : " to " , " type " : " Person " } ,
{ " name " : " contents " , " type " : " string " }
]
}
} ,
" " #
. to_owned ( )
+ & format! ( " 0x {:x} " , address )
+ r #" " ,
" lol "
] ,
" id " : 1
} " #;
let expected = r # "{"jsonrpc":"2.0","result":"0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c","id":1}"# ;
let response = tester . io . handle_request_sync ( & request ) . unwrap ( ) ;
assert_eq! ( response , expected )
}
2018-11-16 14:00:34 +01:00
#[ test ]
fn sign_structured_data ( ) {
let tester = setup ( ) ;
let secret : Secret = keccak ( " cow " ) . into ( ) ;
let address = tester
. accounts
. insert_account ( secret , & " lol " . into ( ) )
. unwrap ( ) ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_signTypedData " ,
" params " : [
{
" primaryType " : " Mail " ,
" domain " : {
" name " : " Ether Mail " ,
" version " : " 1 " ,
" chainId " : " 0x1 " ,
" verifyingContract " : " 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC "
} ,
" message " : {
" from " : {
" name " : " Cow " ,
" wallet " : " 0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826 "
} ,
" to " : {
" name " : " Bob " ,
" wallet " : " 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB "
} ,
" contents " : " Hello, Bob! "
} ,
" types " : {
" EIP712Domain " : [
{ " name " : " name " , " type " : " string " } ,
{ " name " : " version " , " type " : " string " } ,
{ " name " : " chainId " , " type " : " uint256 " } ,
{ " name " : " verifyingContract " , " type " : " address " }
] ,
" Person " : [
{ " name " : " name " , " type " : " string " } ,
{ " name " : " wallet " , " type " : " address " }
] ,
" Mail " : [
{ " name " : " from " , " type " : " Person " } ,
{ " name " : " to " , " type " : " Person " } ,
{ " name " : " contents " , " type " : " string " }
]
}
} ,
" " #
. to_owned ( )
+ & format! ( " 0x {:x} " , address )
+ r #" " ,
" lol "
] ,
" id " : 1
} " #;
let expected = r # "{"jsonrpc":"2.0","result":"0x4355c47d63924e8a72e509b65029052eb6c299d53a04e167c5775fd466751c9d07299936d304c153f6443dfa05f40ff007d72911b6f72307f996231605b915621c","id":1}"# ;
let response = tester . io . handle_request_sync ( & request ) . unwrap ( ) ;
assert_eq! ( response , expected )
}
#[ test ]
fn should_disable_experimental_apis ( ) {
// given
let tester = setup_with ( Config {
allow_experimental_rpcs : false ,
} ) ;
// when
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_sign191 " ,
" params " : [
" 0x01 " ,
{ } ,
" 0x1234567891234567891234567891234567891234 " ,
" lol "
] ,
" id " : 1
} " #;
let r1 = tester . io . handle_request_sync ( & request ) . unwrap ( ) ;
let request = r #" {
" jsonrpc " : " 2.0 " ,
" method " : " personal_signTypedData " ,
" params " : [
{
" types " : { } ,
" message " : { } ,
" domain " : {
" name " : " " ,
" version " : " 1 " ,
" chainId " : " 0x1 " ,
" verifyingContract " : " 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC "
} ,
" primaryType " : " "
} ,
" 0x1234567891234567891234567891234678912344 " ,
" lol "
] ,
" id " : 1
} " #;
let r2 = tester . io . handle_request_sync ( & request ) . unwrap ( ) ;
// then
let expected = r # "{"jsonrpc":"2.0","error":{"code":-32071,"message":"This method is not part of the official RPC API yet (EIP-191). Run with `--jsonrpc-experimental` to enable it.","data":"See EIP: https://eips.ethereum.org/EIPS/eip-191"},"id":1}"# ;
assert_eq! ( r1 , expected ) ;
let expected = r # "{"jsonrpc":"2.0","error":{"code":-32071,"message":"This method is not part of the official RPC API yet (EIP-712). Run with `--jsonrpc-experimental` to enable it.","data":"See EIP: https://eips.ethereum.org/EIPS/eip-712"},"id":1}"# ;
assert_eq! ( r2 , expected ) ;
}