-
Notifications
You must be signed in to change notification settings - Fork 0
/
how_to_modify_state.rs
59 lines (44 loc) · 1.42 KB
/
how_to_modify_state.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
use std::error::Error;
use ethers::prelude::abigen;
use crate::utils::ClientWithSigner;
abigen!(
ModifyState,
r#"[
function x() public view returns(uint)
function modifyToLeet() public
]"#;
);
#[allow(dead_code)]
async fn modify_state(contract: &ModifyState<ClientWithSigner>) -> Result<(), Box<dyn Error>> {
contract.modify_to_leet().send().await?;
Ok(())
}
#[cfg(test)]
mod tests {
mod modify_state {
use std::error::Error;
use ethers::types::U256;
use crate::{
utils::{deploy_contract, ClientWithSigner},
week_4::how_to_modify_state::{modify_state, ModifyState},
};
const CONTRACT_PATH: &str = "./src/week_4/contracts/ModifyState.sol";
const CONTRACT_NAME: &str = "ModifyState";
#[tokio::test]
async fn should_change_x_to_1337() -> Result<(), Box<dyn Error>> {
// Arrange
let initial_x = U256::from(10);
let expected_value = U256::from(1337);
let contract_instance: ModifyState<ClientWithSigner> =
deploy_contract(CONTRACT_PATH, CONTRACT_NAME, initial_x, None)
.await?
.into();
// Act
modify_state(&contract_instance).await?;
// Assert
let x = contract_instance.x().call().await?;
assert_eq!(x, expected_value);
Ok(())
}
}
}