Skip to content

Commit

Permalink
Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Mar 19, 2024
1 parent ba652ac commit 32b9244
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use hex_literal::hex;
mod test_addr;
mod test_bech32;
mod test_bech32m;
mod test_prefixed;

const SECP256K1_MSG_HASH: [u8; 32] =
hex!("5ae8317d34d1e595e3fa7247db80c0af4320cce1116de187f8f7e2e099c0d8d0");
Expand Down
99 changes: 99 additions & 0 deletions tests/test_api/test_prefixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use super::*;
use cosmwasm_std::CanonicalAddr;
use cw_multi_test::MockApiBech32;

const HUMAN_ADDRESS: &str = "juno1h34lmpywh4upnjdg90cjf4j70aee6z8qqfspugamjp42e4q28kqsksmtyp";

fn api_prefix(prefix: &'static str) -> MockApiBech32 {
MockApiBech32::new(prefix)
}

fn api_juno() -> MockApiBech32 {
api_prefix("juno")
}

fn api_osmo() -> MockApiBech32 {
api_prefix("osmo")
}

#[test]
fn new_api_bech32_should_work() {
let addr = api_juno().addr_make("creator");
assert_eq!(HUMAN_ADDRESS, addr.as_str(),);
}

#[test]
fn address_validate_should_work() {
assert_eq!(
api_juno().addr_validate(HUMAN_ADDRESS).unwrap().as_str(),
HUMAN_ADDRESS
)
}

#[test]
fn address_validate_invalid_address() {
api_juno().addr_validate("creator").unwrap_err();
}

#[test]
fn addr_validate_invalid_prefix() {
api_juno()
.addr_validate(api_osmo().addr_make("creator").as_str())
.unwrap_err();
}

#[test]
fn address_canonicalize_humanize_should_work() {
let api = api_juno();
assert_eq!(
api.addr_humanize(&api.addr_canonicalize(HUMAN_ADDRESS).unwrap())
.unwrap()
.as_str(),
HUMAN_ADDRESS
);
}

#[test]
fn address_humanize_prefix_too_long() {
api_prefix(
"juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_",
)
.addr_humanize(&CanonicalAddr::from([1, 2, 3, 4, 5]))
.unwrap_err();
}

#[test]
fn debug_should_not_panic() {
assert_debug_does_not_panic(&api_juno());
}

#[test]
#[should_panic(
expected = "Generating address failed with reason: hrp is too long, found 85 characters, must be <= 126"
)]
fn address_make_prefix_too_long() {
api_prefix(
"juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_juno_",
)
.addr_make("creator");
}

#[test]
fn secp256k1_verify_works() {
assert_secp256k1_verify_works(&api_juno());
}

#[test]
fn secp256k1_recover_pubkey_works() {
assert_secp256k1_recover_pubkey_works(&api_juno());
}

#[test]
fn ed25519_verify_works() {
assert_ed25519_verify_works(&api_juno());
}

#[test]
fn ed25519_batch_verify_works() {
assert_ed25519_batch_verify_works(&api_juno());
}

0 comments on commit 32b9244

Please sign in to comment.