runtime: Fix `ipfs_map` test
@@ -315,7 +315,7 @@ fn make_thing(subgraph_id: &str, id: &str, value: &str) -> (String, EntityModifi
)
}
-#[tokio::test]
+#[tokio::test(threaded_scheduler)]
async fn ipfs_map() {
const BAD_IPFS_HASH: &str = "bad-ipfs-hash";
@@ -324,15 +324,18 @@ async fn ipfs_map() {
let run_ipfs_map = move |json_string| {
let ipfs = ipfs.clone();
- async move {
- let (mut module, store) = test_valid_module_and_store(
- subgraph_id,
- mock_data_source("wasm_test/ipfs_map.wasm"),
- );
+
+ let (mut module, store) =
+ test_valid_module_and_store(subgraph_id, mock_data_source("wasm_test/ipfs_map.wasm"));
let hash = if json_string == BAD_IPFS_HASH {
"Qm".to_string()
} else {
- ipfs.add(Cursor::new(json_string)).await.unwrap().hash
+ graph::spawn(async move { ipfs.add(Cursor::new(json_string)).await })
+ .compat()
+ .wait()
+ .unwrap()
+ .unwrap()
+ .hash
};
let user_data = RuntimeValue::from(module.asc_new(USER_DATA));
let converted = module.module.clone().invoke_export(
@@ -356,46 +359,38 @@ async fn ipfs_map() {
.unwrap()
});
Ok(mods)
- }
};
// Try it with two valid objects
let (str1, thing1) = make_thing(subgraph_id, "one", "eins");
let (str2, thing2) = make_thing(subgraph_id, "two", "zwei");
- let ops = run_ipfs_map(format!("{}\n{}", str1, str2))
- .await
- .expect("call failed");
+ let ops = run_ipfs_map(format!("{}\n{}", str1, str2)).expect("call failed");
let expected = vec![thing1, thing2];
assert_eq!(expected, ops);
// Valid JSON, but not what the callback expected; it will
// fail on an assertion
- let err: Error = run_ipfs_map(format!("{}\n[1,2]", str1)).await.unwrap_err();
+ let err: Error = run_ipfs_map(format!("{}\n[1,2]", str1)).unwrap_err();
assert!(err.to_string().contains("JSON value is not an object."));
// Malformed JSON
let errmsg = run_ipfs_map(format!("{}\n[", str1))
- .await
.unwrap_err()
.to_string();
assert!(errmsg.contains("EOF while parsing a list"));
// Empty input
- let ops = run_ipfs_map("".to_string())
- .await
- .expect("call failed for emoty string");
+ let ops = run_ipfs_map("".to_string()).expect("call failed for emoty string");
assert_eq!(0, ops.len());
// Missing entry in the JSON object
let errmsg = run_ipfs_map("{\"value\": \"drei\"}".to_string())
- .await
.unwrap_err()
.to_string();
assert!(errmsg.contains("JSON value is not a string."));
// Bad IPFS hash.
let errmsg = run_ipfs_map(BAD_IPFS_HASH.to_string())
- .await
.unwrap_err()
.to_string();
assert!(errmsg.contains("api returned error"))
