/
integration_tests.rs
59 lines (46 loc) · 2.42 KB
/
integration_tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#[cfg(test)]
mod tests {
use casper_engine_test_support::{
ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR,
DEFAULT_RUN_GENESIS_REQUEST,
};
use casper_types::account::AccountHash;
use casper_types::{runtime_args, RuntimeArgs};
const ASSOCIATED_ACCOUNT_HASH: AccountHash = AccountHash::new([1u8; 32]); // hash of the associated account
const ASSOCIATED_ACCOUNT: &str = "deployment-account"; // the associated account argument
const CONTRACT_WASM: &str = "contract.wasm"; // file to pass to the instance of the EE
#[test]
fn should_add_associated_key() {
// Initialize an instance of the execution engine and assign it to the builder variable
let mut builder = InMemoryWasmTestBuilder::default();
// Execute the genesis process
builder.run_genesis(&*DEFAULT_RUN_GENESIS_REQUEST).commit();
let account = builder
.get_account(*DEFAULT_ACCOUNT_ADDR)
.expect("should have a primary account");
let associated_keys = account.associated_keys();
assert!(!associated_keys.contains_key(&ASSOCIATED_ACCOUNT_HASH));
// Retrieve runtime arguments. These should be same as defined in the contract
// This allows use to check and assert behavior of the session code
let runtime_args = runtime_args! {
ASSOCIATED_ACCOUNT => ASSOCIATED_ACCOUNT_HASH
};
// Create the execution request that will eventually be executed by the EE
// Load the session wasm and pass in the runtime arguments
// Sets up the session code to be executed in the default account using auth keys and default account address
let execute_request =
ExecuteRequestBuilder::standard(*DEFAULT_ACCOUNT_ADDR, CONTRACT_WASM, runtime_args)
.build();
// Invoke the EE to execute the session code that we are testing
builder.exec(execute_request).expect_success().commit();
// Verify the results of the execution match our expectations from the contract using the test results
let account = builder
.get_account(*DEFAULT_ACCOUNT_ADDR)
.expect("should have a primary account");
let associated_keys = account.associated_keys();
assert!(associated_keys.contains_key(&ASSOCIATED_ACCOUNT_HASH));
}
}
fn main() {
panic!("Execute \"cargo test\" to test the contract, not \"cargo run\".");
}