Skip to content

Commit

Permalink
final test case rs integration cases
Browse files Browse the repository at this point in the history
  • Loading branch information
idea404 committed May 4, 2022
1 parent 52ca597 commit 21ee368
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions integration-tests/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ path = "src/set.rs"
[[example]]
name = "null"
path = "src/null.rs"

[[example]]
name = "statuses"
path = "src/statuses.rs"
1 change: 1 addition & 0 deletions integration-tests/rs/src/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async fn main() -> anyhow::Result<()> {
.await?
.into_result()?;

// begin test
let alice_status: Option<String> = owner
.call(&worker, contract.id(), "get_status")
.args_json(json!({ "account_id": alice.id() }))?
Expand Down
49 changes: 49 additions & 0 deletions integration-tests/rs/src/statuses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use serde_json::json;
use near_units::parse_near;
use workspaces::prelude::*;

const WASM_FILEPATH: &str = "../../res/status_message.wasm";

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let worker = workspaces::sandbox().await?;
let wasm = std::fs::read(WASM_FILEPATH)?;
let contract = worker.dev_deploy(&wasm).await?;

// create accounts
let owner = worker.root_account();
let alice = owner
.create_subaccount(&worker, "alice")
.initial_balance(parse_near!("30 N"))
.transact()
.await?
.into_result()?;

// begin test
alice
.call(&worker, contract.id(), "set_status")
.args_json(json!({ "message": "world" }))?
.transact()
.await?;

let alice_status: String = owner
.call(&worker, contract.id(), "get_status")
.args_json(json!({ "account_id": alice.id() }))?
.transact()
.await?
.json()?;

assert_eq!(alice_status, "world");

let owner_status: Option<String> = owner
.call(&worker, contract.id(), "get_status")
.args_json(json!({ "account_id": owner.id() }))?
.transact()
.await?
.json()?;

assert_eq!(owner_status, None);

println!("Passed ✅");
Ok(())
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "npm run test:unit && npm run test:integration",
"test:unit": "cargo test -- --nocapture",
"test:integration": "npm run build && npm run postbuild && npm run test:integration:rs && npm run test:integration:ts",
"test:integration:rs": "cd integration-tests/rs && cargo run --example set && cargo run --example null",
"test:integration:rs": "cd integration-tests/rs && cargo run --example set && cargo run --example null && cargo run --example statuses",
"test:integration:ts": "ava --verbose"
},
"repository": {
Expand Down

0 comments on commit 21ee368

Please sign in to comment.