Skip to content

Commit

Permalink
[rooch-networkgh-2287] add test cases to session_validator.move.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Sep 15, 2024
1 parent d2ad80d commit b2dae5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ async fn test_session_key_rooch() {
);
let tx_data = RoochTransactionData::new_for_test(sender, sequence_number, action);
let tx = keystore.sign_transaction(&sender, tx_data, None).unwrap();
println!("{:?}", tx.clone().tx_hash());
binding_test.execute(tx).unwrap();

let session_key_module =
Expand All @@ -59,7 +58,6 @@ async fn test_session_key_rooch() {
assert_eq!(&session_key.authentication_key, session_auth_key.as_ref());
assert_eq!(session_key.scopes, vec![session_scope.clone()]);
assert_eq!(session_key.max_inactive_interval, max_inactive_interval);
println!("{:?}", session_key.clone().to_bytes().as_hex());
keystore.binding_session_key(sender, session_key).unwrap();

// send transaction via session key, it in the scop of session key, so it should success.
Expand All @@ -69,6 +67,8 @@ async fn test_session_key_rooch() {
let tx = keystore
.sign_transaction_via_session_key(&sender, tx_data, &session_auth_key, None)
.unwrap();
println!("tx hash: {:?}", hex::encode(tx.clone().tx_hash().0));
println!("authenticator payload: {:?}", hex::encode(tx.clone().authenticator.payload));

binding_test.execute(tx).unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,27 @@ module rooch_framework::session_validator {

#[test]
fun test_validate_signature_success() {
let tx_hash = x"14563b3603703b02c89f15dbaa67f8f0e939c46c152d6700e515459d48fbec31";
let authenticator_payload = x"0004746573741b68747470733a3a2f2f746573742e726f6f63682e6e6574776f726b204ad70a371cff3b7b5c9fc08d7c33f2081d3663d7e37a6461917a106078fe5304010000000000000000000000000000000000000000000000000000000000000003012a012a000000000000000000000000000000006400000000000000";
let tx_hash = x"fdacd89ff32c5dedb2b49117ffa457b29cb932055e34be2629064887c0f4e2c6";
let authenticator_payload = x"008b91427a5eaea2970a093a5a996a947fd7073d0155eaf85db9367715572662b20ddeb9fbb56a3d2a9ebd9d41c8cfc0089e7f7c6b2b2da954c4764527a8a2bd077495252f4c098ae79597de12da55e446256953a5a05d95e54adcd5e1e561cbe0";

validate_signature(&authenticator_payload, &tx_hash);
}

// #[test]
// fun test_validate_signature_fail() {
// let tx_hash = x"5415b18de0b880bb2af5dfe1ee27fd19ae8a0c99b5328e8b4b44f4c86cc7176a";
// let authenticator_payload = x"007e5b0c1da7d2bed7c2497b7c7c46b1a485883029a3bb1479493688ad347bcafa2bd82c6fd9bb2515f9e0c697f621ac0a28fb9f8c0e565d5b6d4e20bf18ce86621a18426974636f696e205369676e6564204d6573736167653a0ae2a201526f6f6368205472616e73616374696f6e3a0a57656c636f6d6520746f20726f6f63685f746573740a596f752077696c6c20617574686f72697a652073657373696f6e3a0a53636f70653a0a3078663962313065366337363066316361646365393563363634623361336561643363393835626265396436336264353161396266313736303738356432366131623a3a2a3a3a2a0a54696d654f75743a313030300a21031a446b6ac064acb14687764871dad6c08186a788248d585b3cce69231b48d1382a62633171333234356e706d3430346874667a76756c783676347736356d61717a7536617474716c336677";
#[test]
#[expected_failure(abort_code = 1010, location = Self)]
fun test_validate_signature_fail_with_scheme() {
let tx_hash = x"fdacd89ff32c5dedb2b49117ffa457b29cb932055e34be2629064887c0f4e2c6";
let authenticator_payload = x"018b91427a5eaea2970a093a5a996a947fd7073d0155eaf85db9367715572662b20ddeb9fbb56a3d2a9ebd9d41c8cfc0089e7f7c6b2b2da954c4764527a8a2bd077495252f4c098ae79597de12da55e446256953a5a05d95e54adcd5e1e561cbe0";

validate_signature(&authenticator_payload, &tx_hash);
}

// validate_signature(&authenticator_payload, &tx_hash);
// }
#[test]
#[expected_failure(abort_code = 1010, location = Self)]
fun test_validate_signature_fail_verify() {
let tx_hash = x"fdacd89ff32c5dedb2b49117ffa457b29cb932055e34be2629064887c0f4e2c5";
let authenticator_payload = x"008b91427a5eaea2970a093a5a996a947fd7073d0155eaf85db9367715572662b20ddeb9fbb56a3d2a9ebd9d41c8cfc0089e7f7c6b2b2da954c4764527a8a2bd077495252f4c098ae79597de12da55e446256953a5a05d95e54adcd5e1e561cbe0";

validate_signature(&authenticator_payload, &tx_hash);
}
}

0 comments on commit b2dae5f

Please sign in to comment.