Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: personal sign #1028

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/backend/tests/it/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@ fn test_sign_transaction() {
);
}

#[test]
fn test_personal_sign() {
let pic_setup = setup();

let caller = Principal::from_text(CALLER.to_string()).unwrap();

let transaction = update_call::<String>(
&pic_setup,
caller,
"personal_sign",
hex::encode("test message".to_string()),
);

assert_eq!(
transaction.unwrap(),
"0x304e37956709f56327742df8cbb0533407aad95f18fc052c039ac9cee1eea30462d8b68aab6799a70fd9163827b521030679c3c6d7d6027b3c255e34e02695fc00".to_string()
);
}

#[test]
fn test_cannot_personal_sign_if_message_is_not_hex_string() {
let pic_setup = setup();

let caller = Principal::from_text(CALLER.to_string()).unwrap();

let result = update_call::<String>(
&pic_setup,
caller,
"personal_sign",
"test message".to_string(),
);

assert!(result.is_err());
assert!(result.unwrap_err().contains("failed to decode hex"));
}

#[test]
fn test_cannot_sign_transaction_with_invalid_to_address() {
let pic_setup = setup();
Expand Down Expand Up @@ -65,3 +101,16 @@ fn test_anonymous_cannot_sign_transaction() {
"Anonymous caller not authorized.".to_string()
);
}

#[test]
fn test_anonymous_cannot_personal_sign() {
let pic_setup = setup();

let result = update_call::<String>(&pic_setup, Principal::anonymous(), "personal_sign", ());

assert!(result.is_err());
assert_eq!(
result.unwrap_err(),
"Anonymous caller not authorized.".to_string()
);
}