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: query variant error on invalid function-name/args #239

Merged
merged 1 commit into from
Nov 12, 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: 1 addition & 1 deletion workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ near-account-id = "0.15.0"
near-crypto = "0.15.0"
near-primitives = "0.15.0"
near-jsonrpc-primitives = "0.15.0"
near-jsonrpc-client = { version = "0.4.0", features = ["sandbox"] }
near-jsonrpc-client = { version = "0.4.1", features = ["sandbox"] }
near-sandbox-utils = "0.6.1"

[build-dependencies]
Expand Down
46 changes: 46 additions & 0 deletions workspaces/tests/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use workspaces::{network::Sandbox, Contract, Worker};

async fn init() -> anyhow::Result<(Worker<Sandbox>, Contract)> {
let worker = workspaces::sandbox().await?;
let status_msg = worker
.dev_deploy(include_bytes!("../../examples/res/status_message.wasm"))
.await?;

Ok((worker, status_msg))
}

#[tokio::test]
async fn test_invalid_query() -> anyhow::Result<()> {
let (_worker, contract) = init().await?;

// incorrect method name;
let result = contract.view("view_status").args_json(("some_id",)).await;
let error =
result.expect_err("expected error while calling invalid method `status_msg.view_status`");
assert!(format!("{error:?}").contains("MethodNotFound"));

// incorrect args:
let result = contract
.view("get_status")
.args_json(serde_json::json!({
"account_id": 10,
}))
.await;
let error =
result.expect_err("expected error while passing invalid args to `status_msg.get_status`");
assert!(format!("{error:?}").contains("Failed to deserialize input from JSON."));

// deposit supplied when not required:
let result = contract
.call("set_status")
.args_json(("some message",))
.deposit(1)
.transact()
.await?
.into_result();
let error =
result.expect_err("expected error while passing deposit to `status_msg.set_status`");
assert!(format!("{error:?}").contains("Smart contract panicked: Method doesn't accept deposit"));

Ok(())
}