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

fix: remove unnecessary decode #438

Merged
merged 2 commits into from
Nov 16, 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
39 changes: 18 additions & 21 deletions homestar-runtime/tests/fixtures/test-workflow-jco.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
{
"name": "componentize",
"workflow": {
"tasks": [
{
"cause": null,
"meta": {
"memory": 4294967296,
"time": 100000
},
"prf": [],
"run": {
"input": {
"args": ["hello", 10],
"func": "sum"
},
"nnc": "",
"op": "wasm/run",
"rsc": "ipfs://"
}
"tasks": [
{
"cause": null,
"meta": {
"memory": 4294967296,
"time": 100000
},
"prf": [],
"run": {
"input": {
"args": ["hello", 10],
"func": "sum"
},
"nnc": "",
"op": "wasm/run",
"rsc": "ipfs://bafybeibawnb3pytqmky4ph37hj7y7qosqcneofjextqq55zhxfniiletfu"
}
]
}
}
]
}
28 changes: 15 additions & 13 deletions homestar-wasm/src/wasmtime/ipld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ use crate::error::{InterpreterError, TagsError};
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use itertools::{FoldWhile::Done, Itertools};
use libipld::{
cid::{
self,
multibase::{self, Base},
Cid,
},
cid::{self, multibase::Base, Cid},
Ipld,
};
use rust_decimal::{
Expand Down Expand Up @@ -345,9 +341,6 @@ impl TryFrom<RuntimeVal> for Ipld {
type Error = InterpreterError;

fn try_from(val: RuntimeVal) -> Result<Self, Self::Error> {
fn base_64_bytes(s: &str) -> Result<Vec<u8>, multibase::Error> {
Base::Base64.decode(s)
}
fn cid(s: &str) -> Result<Cid, cid::Error> {
Cid::try_from(s)
}
Expand All @@ -360,8 +353,6 @@ impl TryFrom<RuntimeVal> for Ipld {
s => {
if let Ok(cid) = cid(&s) {
Ipld::Link(cid)
} else if let Ok(decoded) = base_64_bytes(&s) {
Ipld::Bytes(decoded)
} else {
Ipld::String(s)
}
Expand Down Expand Up @@ -704,11 +695,22 @@ mod test {
fn try_bytes_roundtrip() {
let bytes = b"hell0".to_vec();
let ipld = Ipld::Bytes(bytes.clone());
let encoded_cid = Base::Base64.encode(bytes);
let runtime = RuntimeVal::new(Val::String(Box::from(encoded_cid)));

let ty = test_utils::component::setup_component("(list u8)".to_string(), 8);
let val_list = ty
.unwrap_list()
.new_val(Box::new([
Val::U8(104),
Val::U8(101),
Val::U8(108),
Val::U8(108),
Val::U8(48),
]))
.unwrap();
let runtime = RuntimeVal::new(val_list);

assert_eq!(
RuntimeVal::try_from(ipld.clone(), &InterfaceType::Any).unwrap(),
RuntimeVal::try_from(ipld.clone(), &InterfaceType::Type(ty)).unwrap(),
runtime
);

Expand Down
Loading