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

Add tests, only hash sign arb message once #8

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion account/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Authenticator {
// are signing with signArbitrary (common for cosmos wallets)
let verification = sign_arb::verify(
api,
tx_bytes_hash.as_slice(),
tx_bytes.as_slice(),
sig_bytes.as_slice(),
pubkey.as_slice(),
)?;
Expand Down
5 changes: 2 additions & 3 deletions account/src/auth/sign_arb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
mod tests {
use crate::auth::sign_arb::wrap_message;
use crate::auth::Authenticator::Secp256K1;
use crate::auth::{util, Authenticator};

Check warning on line 34 in account/src/auth/sign_arb.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Authenticator`
use crate::contract::instantiate;
use crate::msg::InstantiateMsg;
use base64::{engine::general_purpose, Engine as _};
Expand Down Expand Up @@ -97,7 +97,7 @@
let info = mock_info("sender", &[]);
// This is the local faucet address to simplify reuse
env.contract.address = Addr::unchecked(
"xion14apeydfljtmvv8vdj97u3mtmlednfhz6dr5scfs2p6xd0gdlxutqvfagkh".to_string(),
"xion1cyyld62ly828e2xnp0c0ckpyz68wwfs26tjpscmqlaum2jcj8zdstlxvya".to_string(),
);

let pubkey = "Ayrlj6q3WWs91p45LVKwI8JyfMYNmWMrcDinLNEdWYE4";
Expand All @@ -111,7 +111,7 @@
signer.as_str()
);

let signature = "ywxOndY+x+AzT77KBVptdCarKG6YyPBVRkpm188P8Sh9SOQ4sIIFK5ZMzN8XLqClTTIsXT14FeeRhuDaL+fMYA==";
let signature = "AKgG8slCFM78fE9tZzmf+L6yQskPQI0acUg3PBv/kNIO0i19i/RNaJtfFJ8A8MyHmg7Ate5imbwuzsP6mfbEaA==";
let signature_bytes = general_purpose::STANDARD.decode(signature).unwrap();

let instantiate_msg = InstantiateMsg {
Expand All @@ -122,7 +122,6 @@
signature: Binary::from(signature_bytes),
};

let res = instantiate(deps.as_mut(), env.clone(), info, instantiate_msg).unwrap();

Check warning on line 125 in account/src/auth/sign_arb.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `res`
println!("response: {:?}", res);
}
}
40 changes: 40 additions & 0 deletions account/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,43 @@

Ok(())
}

#[cfg(test)]
mod tests {
use base64::{engine::general_purpose, Engine as _};
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::Binary;

use crate::auth::Authenticator;
use crate::execute::before_tx;
use crate::state::AUTHENTICATORS;

#[test]
fn test_before_tx() {
let authId = 0;

Check warning on line 197 in account/src/execute.rs

View workflow job for this annotation

GitHub Actions / Test Suite

variable `authId` should have a snake case name
let mut deps = mock_dependencies();

let pubkey = "Ayrlj6q3WWs91p45LVKwI8JyfMYNmWMrcDinLNEdWYE4";
let pubkey_bytes = general_purpose::STANDARD.decode(pubkey).unwrap();
let auth = Authenticator::Secp256K1 {
pubkey: Binary::from(pubkey_bytes),
};

let signature = "UDerMpp4QzGxjuu3uTmqoOdPrmRnwiOf6BOlL5xG2pAEx+gS8DV3HwBzrb+QRIVyKVc3D7RYMOAlRFRkpVANDA==";
let sig_arr = general_purpose::STANDARD.decode(signature).unwrap();

// The index of the first authenticator is 0.
let credIndex = vec![0u8];

Check warning on line 210 in account/src/execute.rs

View workflow job for this annotation

GitHub Actions / Test Suite

variable `credIndex` should have a snake case name

let mut new_vec = Vec::new();
new_vec.extend_from_slice(&credIndex);
new_vec.extend_from_slice(&sig_arr);

AUTHENTICATORS.save(deps.as_mut().storage, authId, &auth);

Check warning on line 216 in account/src/execute.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused `Result` that must be used

let sig_bytes = Binary::from(new_vec);
let tx_bytes = Binary::from(general_purpose::STANDARD.decode("Cp0BCpoBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnoKP3hpb24xbTZ2aDIwcHM3NW0ybjZxeHdwandmOGZzM2t4dzc1enN5M3YycnllaGQ5c3BtbnUwcTlyc2g0NnljeRIreGlvbjFlMmZ1d2UzdWhxOHpkOW5ra2s4NzZuYXdyd2R1bGd2NDYwdnpnNxoKCgV1eGlvbhIBMRJTCksKQwodL2Fic3RyYWN0YWNjb3VudC52MS5OaWxQdWJLZXkSIgog3pl1PDD1NqnoBnBk5J0wjYzvUFAkWKGTN2lgHc+PAUcSBAoCCAESBBDgpxIaFHhpb24tbG9jYWwtdGVzdG5ldC0xIAg=").unwrap());

before_tx(deps.as_ref(), &tx_bytes, Some(&sig_bytes), false).unwrap();
}
}
Loading