|
16 | 16 | ) |
17 | 17 | ) |
18 | 18 |
|
| 19 | + (func $current_balance (param $sp i32) (result i64) |
| 20 | + (i32.store |
| 21 | + (i32.sub (get_local $sp) (i32.const 16)) |
| 22 | + (i32.const 8) |
| 23 | + ) |
| 24 | + (call $seal_balance |
| 25 | + (i32.sub (get_local $sp) (i32.const 8)) |
| 26 | + (i32.sub (get_local $sp) (i32.const 16)) |
| 27 | + ) |
| 28 | + (call $assert |
| 29 | + (i32.eq (i32.load (i32.sub (get_local $sp) (i32.const 16))) (i32.const 8)) |
| 30 | + ) |
| 31 | + (i64.load (i32.sub (get_local $sp) (i32.const 8))) |
| 32 | + ) |
| 33 | + |
19 | 34 | (func (export "deploy")) |
20 | 35 |
|
21 | 36 | (func (export "call") |
22 | 37 | (local $sp i32) |
23 | 38 | (local $exit_code i32) |
| 39 | + (local $balance i64) |
24 | 40 |
|
25 | 41 | ;; Length of the buffer |
26 | 42 | (i32.store (i32.const 20) (i32.const 32)) |
|
38 | 54 |
|
39 | 55 | ;; Read current balance into local variable. |
40 | 56 | (set_local $sp (i32.const 1024)) |
| 57 | + (set_local $balance |
| 58 | + (call $current_balance (get_local $sp)) |
| 59 | + ) |
41 | 60 |
|
42 | 61 | ;; Fail to deploy the contract since it returns a non-zero exit status. |
43 | 62 | (set_local $exit_code |
|
63 | 82 | (i32.eq (get_local $exit_code) (i32.const 2)) ;; ReturnCode::CalleeReverted |
64 | 83 | ) |
65 | 84 |
|
| 85 | + ;; Check that balance has not changed. |
| 86 | + (call $assert |
| 87 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 88 | + ) |
| 89 | + |
66 | 90 | ;; Fail to deploy the contract due to insufficient gas. |
67 | 91 | (set_local $exit_code |
68 | 92 | (call $seal_instantiate |
|
88 | 112 | (i32.eq (get_local $exit_code) (i32.const 1)) ;; ReturnCode::CalleeTrapped |
89 | 113 | ) |
90 | 114 |
|
| 115 | + ;; Check that balance has not changed. |
| 116 | + (call $assert |
| 117 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 118 | + ) |
| 119 | + |
91 | 120 | ;; Length of the output buffer |
92 | 121 | (i32.store |
93 | 122 | (i32.sub (get_local $sp) (i32.const 4)) |
|
124 | 153 | (i32.eq (i32.load (i32.sub (get_local $sp) (i32.const 4))) (i32.const 32)) |
125 | 154 | ) |
126 | 155 |
|
| 156 | + ;; Check that balance has been deducted. |
| 157 | + (set_local $balance |
| 158 | + (i64.sub (get_local $balance) (i64.load (i32.const 0))) |
| 159 | + ) |
| 160 | + (call $assert |
| 161 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 162 | + ) |
| 163 | + |
127 | 164 | ;; Zero out destination buffer of output |
128 | 165 | (i32.store |
129 | 166 | (i32.sub (get_local $sp) (i32.const 4)) |
|
167 | 204 | ) |
168 | 205 | ) |
169 | 206 |
|
| 207 | + ;; Check that balance has not changed. |
| 208 | + (call $assert |
| 209 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 210 | + ) |
| 211 | + |
170 | 212 | ;; Fail to call the contract due to insufficient gas. |
171 | 213 | (set_local $exit_code |
172 | 214 | (call $seal_call |
|
187 | 229 | (i32.eq (get_local $exit_code) (i32.const 1)) ;; ReturnCode::CalleeTrapped |
188 | 230 | ) |
189 | 231 |
|
| 232 | + ;; Check that balance has not changed. |
| 233 | + (call $assert |
| 234 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 235 | + ) |
| 236 | + |
190 | 237 | ;; Zero out destination buffer of output |
191 | 238 | (i32.store |
192 | 239 | (i32.sub (get_local $sp) (i32.const 4)) |
|
229 | 276 | (i32.const 0x77665544) |
230 | 277 | ) |
231 | 278 | ) |
| 279 | + |
| 280 | + ;; Check that balance has been deducted. |
| 281 | + (set_local $balance |
| 282 | + (i64.sub (get_local $balance) (i64.load (i32.const 0))) |
| 283 | + ) |
| 284 | + (call $assert |
| 285 | + (i64.eq (get_local $balance) (call $current_balance (get_local $sp))) |
| 286 | + ) |
232 | 287 | ) |
233 | 288 |
|
234 | 289 | (data (i32.const 0) "\00\80") ;; The value to transfer on instantiation and calls. |
|
0 commit comments