Skip to content

Commit

Permalink
Integration testing sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Feb 6, 2024
1 parent ea0f709 commit ad67ef4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sandbox-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "sandbox"
version = "1.0.0"
publish = false
edition = "2021"

[dev-dependencies]
tokio = { version = "1.18.1", features = ["full"] }
near-workspaces = "0.9.0"
serde_json = { version = "1.0", features = ["arbitrary_precision"] }

[[example]]
name = "sandbox"
path = "src/tests.rs"
68 changes: 68 additions & 0 deletions sandbox-rs/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use near_workspaces::{types::NearToken, Account, Contract};
use serde_json::json;
use std::{env, fs};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let wasm_arg: &str = &(env::args().nth(1).unwrap());
let wasm_filepath = fs::canonicalize(env::current_dir()?.join(wasm_arg))?;

let worker = near_workspaces::sandbox().await?;
let wasm = std::fs::read(wasm_filepath)?;
let contract = worker.dev_deploy(&wasm).await?;

// create accounts
let account = worker.dev_create_account().await?;
let alice = account
.create_subaccount("alice")
.initial_balance(NearToken::from_near(30))
.transact()
.await?
.into_result()?;

// begin tests
// test_default_message(&alice, &contract).await?;
// test_changes_message(&alice, &contract).await?;
Ok(())
}


/*
async fn test_default_message(
user: &Account,
contract: &Contract,
) -> Result<(), Box<dyn std::error::Error>> {
let greeting: String = user
.call(contract.id(), "get_greeting")
.args_json(json!({}))
.transact()
.await?
.json()?;
assert_eq!(greeting, "Hello".to_string());
println!(" Passed ✅ gets default greeting");
Ok(())
}
async fn test_changes_message(
user: &Account,
contract: &Contract,
) -> Result<(), Box<dyn std::error::Error>> {
user.call(contract.id(), "set_greeting")
.args_json(json!({"greeting": "Howdy"}))
.transact()
.await?
.into_result()?;
let greeting: String = user
.call(contract.id(), "get_greeting")
.args_json(json!({}))
.transact()
.await?
.json()?;
assert_eq!(greeting, "Howdy".to_string());
println!(" Passed ✅ changes greeting");
Ok(())
}
*/

0 comments on commit ad67ef4

Please sign in to comment.