Skip to content
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
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[toolchain]
# For deploy
channel = "1.81.0"
# channel = "1.81.0"
# For develop and test
# channel = "stable"
channel = "stable"
components = ["rustfmt"]
targets = ["wasm32-unknown-unknown"]
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod tests {
fn get_obj() {
let (_, contract) = setup_contract();
let obj = contract.return_obj();
assert_eq!(obj.greeting, "Hello");
assert_eq!(obj.greeting, accounts(0).to_string());
assert_eq!(obj.number, 42);
}

Expand Down
16 changes: 11 additions & 5 deletions tests/test_basics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use near_sdk::{AccountId, NearToken};
use serde_json::json;

#[tokio::test]
Expand All @@ -13,25 +14,30 @@ async fn test_basics_on(contract_wasm: &[u8]) -> Result<(), Box<dyn std::error::
let contract = sandbox.dev_deploy(contract_wasm).await?;

let user_account = sandbox.dev_create_account().await?;
let user_account_2 = sandbox.dev_create_account().await?;

let outcome_initalize = user_account
.call(contract.id(), "new")
.args_json(json!({"initial_greeting": "Hello"}))
.args_json(json!({"initial_owner": user_account.id()}))
.transact()
.await
.unwrap();
assert!(outcome_initalize.is_success());

let outcome = user_account
.call(contract.id(), "set_greeting")
.args_json(json!({"greeting": "Hello World!"}))
.call(contract.id(), "set_owner")
.args_json(json!({"owner": user_account_2.id()}))
.deposit(NearToken::from_yoctonear(1))
.transact()
.await
.unwrap();
assert!(outcome.is_success());

let user_message_outcome = contract.view("get_greeting").args_json(json!({})).await?;
assert_eq!(user_message_outcome.json::<String>()?, "Hello World!");
let user_message_outcome = contract.view("get_owner").args_json(json!({})).await?;
assert_eq!(
&user_message_outcome.json::<AccountId>()?,
user_account_2.id()
);

Ok(())
}
Loading