Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Adds test for invalid password
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7CFE committed Nov 10, 2017
1 parent 6acf0c2 commit 6b932d1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions rpc/src/v1/tests/mocked/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,39 @@ fn new_account() {
assert_eq!(res, Some(response));
}

#[test]
fn sign_and_send_transaction_with_invalid_password() {
fn invalid_password_test(method: &str)
{
let tester = setup();
let address = tester.accounts.new_account("password123").unwrap();

let request = r#"{
"jsonrpc": "2.0",
"method": "personal_sendTransaction",
"method": ""#.to_owned() + method + r#"",
"params": [{
"from": ""#.to_owned() + format!("0x{:?}", address).as_ref() + r#"",
"from": ""# + format!("0x{:?}", address).as_ref() + r#"",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a"
}, "password321"],
"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()));
}

#[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");
}

#[test]
fn send_transaction() {
sign_and_send_test("personal_sendTransaction");
Expand Down

0 comments on commit 6b932d1

Please sign in to comment.