diff --git a/examples/src/ref_finance.rs b/examples/src/ref_finance.rs index e227a0b7..be6e0e86 100644 --- a/examples/src/ref_finance.rs +++ b/examples/src/ref_finance.rs @@ -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?; @@ -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?; diff --git a/workspaces/Cargo.toml b/workspaces/Cargo.toml index b9f6566d..d7096049 100644 --- a/workspaces/Cargo.toml +++ b/workspaces/Cargo.toml @@ -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"] } diff --git a/workspaces/src/network/account.rs b/workspaces/src/network/account.rs index 8704814c..86a5a0dc 100644 --- a/workspaces/src/network/account.rs +++ b/workspaces/src/network/account.rs @@ -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, } diff --git a/workspaces/tests/optional_args.rs b/workspaces/tests/optional_args.rs new file mode 100644 index 00000000..5e10a24a --- /dev/null +++ b/workspaces/tests/optional_args.rs @@ -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) -> anyhow::Result { + 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")); + + 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::()?); + + Ok(()) +}