From dba8cf3a3b483aa19fbb538395688097b59e107c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 7 Dec 2016 17:58:22 +0100 Subject: [PATCH] Add test for RPC side --- rpc/src/v1/impls/parity_accounts.rs | 2 +- rpc/src/v1/tests/mocked/parity_accounts.rs | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/parity_accounts.rs b/rpc/src/v1/impls/parity_accounts.rs index a765c8bb0..7bbfb1dd3 100644 --- a/rpc/src/v1/impls/parity_accounts.rs +++ b/rpc/src/v1/impls/parity_accounts.rs @@ -131,7 +131,7 @@ impl ParityAccounts for ParityAccountsClient where C: MiningBlock let store = take_weak!(self.accounts); let addr: Address = addr.into(); - store.remove_address(addr, name)) + store.remove_address(addr) .expect("remove_address always returns Ok; qed"); Ok(true) } diff --git a/rpc/src/v1/tests/mocked/parity_accounts.rs b/rpc/src/v1/tests/mocked/parity_accounts.rs index 3b1899f38..8b42500e6 100644 --- a/rpc/src/v1/tests/mocked/parity_accounts.rs +++ b/rpc/src/v1/tests/mocked/parity_accounts.rs @@ -152,3 +152,32 @@ fn should_be_able_to_kill_account() { let accounts = tester.accounts.accounts().unwrap(); assert_eq!(accounts.len(), 0); } + +#[test] +fn should_be_able_to_remove_address() { + let tester = setup(); + + // add an address + let request = r#"{"jsonrpc": "2.0", "method": "parity_setAccountName", "params": ["0x000baba1000baba2000baba3000baba4000baba5", "Test"], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; + let res = tester.io.handle_request_sync(&request); + assert_eq!(res, Some(response.into())); + + // verify it exists + let request = r#"{"jsonrpc": "2.0", "method": "parity_accountsInfo", "params": [], "id": 2}"#; + let res = tester.io.handle_request_sync(request); + let response = r#"{"jsonrpc":"2.0","result":{"0x000baba1000baba2000baba3000baba4000baba5":{"meta":"{}","name":"Test","uuid":null}},"id":2}"#; + assert_eq!(res, Some(response.into())); + + // remove the address + let request = r#"{"jsonrpc": "2.0", "method": "parity_removeAddress", "params": ["0x000baba1000baba2000baba3000baba4000baba5"], "id": 3}"#; + let response = r#"{"jsonrpc":"2.0","result":true,"id":3}"#; + let res = tester.io.handle_request_sync(&request); + assert_eq!(res, Some(response.into())); + + // verify empty + let request = r#"{"jsonrpc": "2.0", "method": "parity_accountsInfo", "params": [], "id": 4}"#; + let res = tester.io.handle_request_sync(request); + let response = r#"{"jsonrpc":"2.0","result":{},"id":4}"#; + assert_eq!(res, Some(response.into())); +}