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: make empty array the default function argument #84

Merged
merged 6 commits into from
Mar 8, 2022
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
2 changes: 2 additions & 0 deletions examples/src/ref_finance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async fn create_ref(

owner
.call(&worker, ref_finance.id(), "storage_deposit")
.args_json(serde_json::json!({}))?
.deposit(parse_near!("30 mN"))
.transact()
.await?;
Expand Down Expand Up @@ -78,6 +79,7 @@ async fn create_wnear(

owner
.call(&worker, wnear.id(), "storage_deposit")
.args_json(serde_json::json!({}))?
.deposit(parse_near!("0.008 N"))
.transact()
.await?;
Expand Down
1 change: 1 addition & 0 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ libc = "0.2"

[dev-dependencies]
borsh = "0.9"
near-units = "0.1.0"
test-log = { version = "0.2.8", default-features = false, features = ["trace"] }
tracing-subscriber = { version = "0.3.5", features = ["env-filter"] }
2 changes: 1 addition & 1 deletion workspaces/src/network/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a, T: Network> CallBuilder<'a, T> {
signer,
contract_id,
function,
args: serde_json::json!({}).to_string().into_bytes(),
args: vec![],
deposit: DEFAULT_CALL_DEPOSIT,
gas: DEFAULT_CALL_FN_GAS,
}
Expand Down
57 changes: 57 additions & 0 deletions workspaces/tests/optional_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![recursion_limit = "256"]
use near_units::parse_near;
use test_log::test;
use workspaces::prelude::*;
use workspaces::{Contract, DevNetwork, Worker};

async fn init(worker: &Worker<impl DevNetwork>) -> anyhow::Result<Contract> {
let contract = worker
.dev_deploy(include_bytes!("../../examples/res/fungible_token.wasm"))
.await?;

contract
.call(worker, "new_default_meta")
.args_json(serde_json::json!({
"owner_id": contract.id(),
"total_supply": parse_near!("1,000,000,000 N").to_string(),
}))?
.transact()
.await?;

Ok(contract)
}

#[test(tokio::test)]
async fn test_empty_args_error() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let contract = init(&worker).await?;

let res = contract
.call(&worker, "storage_unregister")
.gas(300_000_000_000_000)
.deposit(1)
.transact()
.await;
assert!(format!("{:?}", res.unwrap_err()).contains("Failed to deserialize input from JSON"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this error message is pretty unintuitive, so best for us to change this on the SDK side in the future


Ok(())
}

#[test(tokio::test)]
async fn test_optional_args_present() -> anyhow::Result<()> {
let worker = workspaces::sandbox();
let contract = init(&worker).await?;

let res = contract
.call(&worker, "storage_unregister")
.args_json(serde_json::json!({
"force": true
}))?
.gas(300_000_000_000_000)
.deposit(1)
.transact()
.await?;
assert!(res.json::<bool>()?);

Ok(())
}