-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use casperlabs_engine_test_support::{Code, Error, SessionBuilder, TestContextBuilder, Value}; | ||
use casperlabs_types::{account::PublicKey, U512}; | ||
|
||
const MY_ACCOUNT: PublicKey = PublicKey::ed25519_from([7u8; 32]); | ||
// define KEY constant to match that in the contract | ||
const KEY: &str = "special_value"; | ||
const VALUE: &str = "hello world"; | ||
|
||
#[test] | ||
fn should_store_hello_world() { | ||
let mut context = TestContextBuilder::new() | ||
.with_account(MY_ACCOUNT, U512::from(128_000_000)) | ||
.build(); | ||
|
||
// The test framework checks for compiled Wasm files in '<current working dir>/wasm'. Paths | ||
// relative to the current working dir (e.g. 'wasm/contract.wasm') can also be used, as can | ||
// absolute paths. | ||
let session_code = Code::from("contract.wasm"); | ||
let session_args = (VALUE,); | ||
let session = SessionBuilder::new(session_code, session_args) | ||
.with_address(MY_ACCOUNT) | ||
.with_authorization_keys(&[MY_ACCOUNT]) | ||
.build(); | ||
|
||
let result_of_query: Result<Value, Error> = context.run(session).query(MY_ACCOUNT, &[KEY]); | ||
|
||
let returned_value = result_of_query.expect("should be a value"); | ||
|
||
let expected_value = Value::from_t(VALUE.to_string()).expect("should construct Value"); | ||
assert_eq!(expected_value, returned_value); | ||
} | ||
} | ||
|
||
fn main() { | ||
panic!("Execute \"cargo test\" to test the contract, not \"cargo run\"."); | ||
} |