forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_and_call.fe
More file actions
69 lines (58 loc) · 1.64 KB
/
Copy pathdeploy_and_call.fe
File metadata and controls
69 lines (58 loc) · 1.64 KB
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
60
61
62
63
64
65
66
67
68
69
/// Test deploying a high-level contract and calling methods on it.
/// Uses the high-level create2 and Call traits for contract interactions.
// Message types for the Counter contract
msg CounterMsg {
#[selector = 0xd09de08a]
Increment,
#[selector = 0x6d4ce63c]
Get -> u256,
}
// Storage struct for the counter
struct CounterStore {
value: u256,
}
// High-level Counter contract using storage struct pattern
pub contract Counter {
mut store: CounterStore
init() uses (mut store) {
store.value = 0
}
recv CounterMsg {
Increment uses (mut store) {
store.value = store.value + 1
}
Get -> u256 uses (store) {
store.value
}
}
}
#[test]
fn test_deploy_and_call_counter() uses (evm: mut Evm) {
// Deploy the counter contract using the high-level create2 API
let contract_addr = evm.create2<Counter>(value: 0, args: (), salt: 0)
// Verify deployment succeeded (address != 0)
assert!(contract_addr.inner != 0)
// Call Get() using high-level Call trait - should return 0
let initial_value: u256 = evm.call(
addr: contract_addr,
gas: 100000,
value: 0,
message: CounterMsg::Get {}
)
assert!(initial_value == 0)
// Call Increment() using high-level Call trait
evm.call(
addr: contract_addr,
gas: 100000,
value: 0,
message: CounterMsg::Increment {}
)
// Call Get() again - should return 1
let final_value: u256 = evm.call(
addr: contract_addr,
gas: 100000,
value: 0,
message: CounterMsg::Get {}
)
assert!(final_value == 1)
}