Skip to content

Commit

Permalink
Fix wasm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Oct 6, 2023
1 parent 852189b commit 5d14070
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 6 additions & 4 deletions node/src/browser/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,12 @@ pub fn get_did(address: &str, addr_type: AddressType) -> Result<Did, JsError> {
/// * pubkey: hex pubkey
#[wasm_export]
pub fn get_address_from_hex_pubkey(pubkey: String) -> Result<String, JsError> {
Ok(PublicKey::from_hex_string(pubkey.as_str())
.map_err(JsError::from)?
.address()
.to_string())
Ok(Did::from(
PublicKey::from_hex_string(pubkey.as_str())
.map_err(JsError::from)?
.address(),
)
.to_string())
}

/// Get address from other address
Expand Down
13 changes: 5 additions & 8 deletions node/src/tests/wasm/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ async fn test_get_address_from_hex_pubkey() {
assert!(addr_result.is_ok(), "addr_result is error");
let addr = addr_result.ok().unwrap();
assert!(
addr.eq_ignore_ascii_case("fada88633e01d2f6704a7f2a6ebc57263aca6978"),
addr.eq_ignore_ascii_case("0xfada88633e01d2f6704a7f2a6ebc57263aca6978"),
"got addr {:?}",
addr
);
}

#[wasm_bindgen_test]
async fn test_get_address() {
let expect_address = "8b98cf912975b4b6b67ce94882fc25c210a60a60";
let expect_address = "0x8b98cf912975b4b6b67ce94882fc25c210a60a60";
let got_address = browser::get_address(
"9z1ZTaGocNSAu3DSqGKR6Dqt214X4dXucVd6C53EgqBK",
browser::AddressType::Ed25519,
Expand All @@ -163,12 +163,9 @@ async fn test_get_address() {
got_address,
expect_address
);
let got_address = browser::get_address(
format!("0x{}", expect_address).as_str(),
browser::AddressType::DEFAULT,
)
.ok()
.unwrap();
let got_address = browser::get_address(expect_address, browser::AddressType::DEFAULT)
.ok()
.unwrap();

assert!(
got_address.eq_ignore_ascii_case(expect_address),
Expand Down

0 comments on commit 5d14070

Please sign in to comment.