Skip to content

Commit

Permalink
Fixing b64UrlToBuffer (#214)
Browse files Browse the repository at this point in the history
Fixing b64UrlToBuffer (#214)
  • Loading branch information
andreespirela authored Oct 29, 2022
1 parent 747b552 commit a09dfde
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions crates/js/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,29 @@ export async function handle(slice) {
);
}

#[tokio::test]
async fn test_runtime_smartweave_arweave_wallets_ownertoaddress() {
let buf: Vec<u8> = vec![0x00];
let mut rt = Runtime::new(
r#"
export async function handle() {
return { state: await SmartWeave.arweave.wallets.ownerToAddress("kTuBmCmd8dbEiq4zbEPx0laVMEbgXNQ1KBUYqg3TWpLDokkcrZfa04hxYWVLZMnXH2PRSCjvCi5YVu3TG27kl29eMs-CJ-D97WyfvEZwZ7V4EDLS1uqiOrfnkBxXDfJwMI7pdGWg0JYwhsqePB8A9WfIfjrWXiGkleAAtU-dLc8Q3QYIbUBa_rNrvC_AwhXhoKUNq5gaKAdB5xQBfHJg8vMFaTsbGOxIH8v7gJyz7gc9JQf0F42ByWPmhIsm4bIHs7eGPgtUKASNBmWIgs8blP7AmbzyJp4bx_AOQ4KOCei25Smw2-UAZehCGibl50i-blv5ldpGhcKDBC7ukjZpOY99V0mdDynbQBi606DdTWGJSXGNkvpwYnLh53VOE3uX0zuxNnRlwA9BN_VisWMrQwk_KnB0Fz0qGlJsXNQEWb_TEaf6eWLcSIUZUUC9o0L6J6mI9hiJjf_sisiR6AsWF4UoA-snWsFNzgPdkeOHW_biJMep6DOnWX8lmh8meDGMi1XOxJ4hJAawD7uS3A8jL7Kn7eYtiQ7bnZG69WtBueyOQh78yStMvoKz6awzBt1IaTBUG9_CHrEy_Tx6aQZu1c2D_nZonTd0pV2ljC7E642VtOWsRFL78-1xF6P0FD4eWh6HoDpD05_3oUBrAdusLMkn8Gm5tl0wIwMrLF58FYk") }
}
"#,
ZeroCopyBuf::from(buf),
(80, String::from("arweave.net"), String::from("https")),
never_op::decl(),
HashMap::new(),
None,
)
.await
.unwrap();

rt.call((), None).await.unwrap();
let address = rt.get_contract_state::<String>().unwrap();
assert_eq!(address, "z5-Ql2zU5Voac97BHMDGrk3_2gEDqM72iHxCJhkcJ5A");
}

#[tokio::test]
async fn test_runtime_smartweave_crypto_sign() {
let buf: Vec<u8> = vec![0x00];
Expand Down
4 changes: 3 additions & 1 deletion crates/smartweave/smartweave.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
}

b64UrlToBuffer(b64UrlString) {
return Uint8Array.from(atob(b64UrlString), (c) => c.charCodeAt(0));
return new Uint8Array(atob(b64UrlString.replace(/-/g, '+').replace(/_/g, '/')).split('').map(val => {
return val.charCodeAt(0);
}));
}

bufferTob64(buffer) {
Expand Down

0 comments on commit a09dfde

Please sign in to comment.