-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve error msg on calling
json
on void function (#286)
- Loading branch information
Yasir Shariff
authored
Sep 9, 2023
1 parent
c068908
commit a885809
Showing
6 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "simple-contract" | ||
version = "0.1.0" | ||
publish = false | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
near-sdk = "4.1.1" | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "z" | ||
lto = true | ||
debug = false | ||
panic = "abort" | ||
# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 | ||
overflow-checks = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; | ||
use near_sdk::near_bindgen; | ||
|
||
#[near_bindgen] | ||
#[derive(Default, BorshDeserialize, BorshSerialize)] | ||
pub struct Noop; | ||
|
||
#[near_bindgen] | ||
impl Noop { | ||
pub fn noop() {} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// This contract has only one method `noop` which does nothing and returns nothing. | ||
const NOOP_CONTRACT_WASM_FILEPATH: &str = "./examples/res/noop_contract.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(NOOP_CONTRACT_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let res = contract.call("noop").transact().await?.json::<()>(); | ||
|
||
// Ok to error for call with no return value | ||
assert_eq!( | ||
*res.unwrap_err().kind(), | ||
workspaces::error::ErrorKind::DataConversion, | ||
"the function call returned an empty value, which cannot be parsed as JSON" | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters