Skip to content

Commit

Permalink
return None if table item returns not found (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Dec 5, 2022
1 parent 67b7fe9 commit 556fc67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,23 @@ mod tests {
assert_eq!(execution_result.return_values.len(), 1);
debug!("{}", execution_result.return_values[0]);
}

#[test]
fn test_account_deposit() {
let mut execution_result = ExecutionResult {
log_path: String::new(),
return_values: vec![],
};
exec_func(
String::from("0xa46f37ead5670b6862709a0f17f7464a767877cba7c3c18196bc8e1e0f3c3a89::stability_pool::account_deposit"),
None,
Some(vec![String::from("0x4da77591b6f79f490ce7ee66743b6985236fbed0e86d3afd65717553d4b780f8")]),
0,
&Network::Testnet,
&CONFIG,
&mut execution_result,
);
assert_eq!(execution_result.return_values.len(), 1);
debug!("{}", execution_result.return_values[0]);
}
}
10 changes: 7 additions & 3 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::{
collections::{btree_map, BTreeMap},
fmt::Debug,
};
use reqwest::StatusCode;
use tokio::runtime::Runtime;

/// Simple in-memory storage for modules and resources under an account.
Expand Down Expand Up @@ -228,9 +229,12 @@ impl TableResolver for InMemoryLazyStorage {
.header(ACCEPT, BCS)
.json(&map)
.send()
.unwrap()
.bytes()
.unwrap();
Ok(Some(resp.to_vec()))
if (resp.status() == StatusCode::NOT_FOUND) {
return Ok(None)
}

let bytes = resp.bytes().unwrap();
Ok(Some(bytes.to_vec()))
}
}

0 comments on commit 556fc67

Please sign in to comment.