Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 2bfb866

Browse files
committed
added missing fixtures
1 parent edf1aac commit 2bfb866

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
;; This instantiates another contract and passes some input to its constructor.
2+
(module
3+
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
4+
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
5+
(import "seal2" "instantiate" (func $seal_instantiate
6+
(param i32 i64 i64 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
7+
))
8+
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
9+
(import "env" "memory" (memory 1 1))
10+
11+
;; [0, 8) send 10_000 balance
12+
(data (i32.const 48) "\10\27\00\00\00\00\00\00")
13+
14+
(func $assert (param i32)
15+
(block $ok
16+
(br_if $ok
17+
(get_local 0)
18+
)
19+
(unreachable)
20+
)
21+
)
22+
23+
(func (export "deploy"))
24+
25+
(func (export "call")
26+
;; store length of input buffer
27+
(i32.store (i32.const 0) (i32.const 512))
28+
;; store length of contract address
29+
(i32.store (i32.const 84) (i32.const 32))
30+
31+
;; copy input at address 4
32+
(call $seal_input (i32.const 4) (i32.const 0))
33+
34+
;; memory layout is:
35+
;; [0,4): size of input buffer
36+
;; [4,8): size of the storage to be created in callee
37+
;; [8,40): the code hash of the contract to instantiate
38+
;; [40,48): for the encoded deposit limit
39+
;; [48,52): value to transfer
40+
;; [52,84): address of the deployed contract
41+
;; [84,88): len of the address
42+
43+
;; instantiate a contract
44+
(call $assert (i32.eqz
45+
;; (i32.store
46+
;; (i32.const 64)
47+
(call $seal_instantiate
48+
(i32.const 8) ;; Pointer to the code hash.
49+
(i64.const 0) ;; How much ref_time weight to devote for the execution. 0 = all.
50+
(i64.const 0) ;; How much proof_size weight to devote for the execution. 0 = all.
51+
(i32.const 40) ;; Pointer to the storage deposit limit
52+
(i32.const 48) ;; Pointer to the buffer with value to transfer
53+
(i32.const 4) ;; Pointer to input data buffer address
54+
(i32.const 4) ;; Length of input data buffer
55+
(i32.const 52) ;; Pointer to where to copy address
56+
(i32.const 84) ;; Pointer to address len ptr
57+
(i32.const 0xffffffff) ;; u32 max sentinel value: do not copy output
58+
(i32.const 0) ;; Length is ignored in this case
59+
(i32.const 0) ;; salt_ptr
60+
(i32.const 0) ;; salt_len
61+
)
62+
))
63+
;; return the deployed contract address
64+
(call $seal_return (i32.const 0) (i32.const 52) (i32.const 32))
65+
)
66+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
;; Stores a value of the passed size.
2+
(module
3+
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
4+
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
5+
(import "env" "memory" (memory 16 16))
6+
7+
;; [0, 32) storage key
8+
(data (i32.const 0) "\01")
9+
10+
;; [32, 36) buffer where input is copied (expected size of storage item)
11+
12+
;; [36, 40) size of the input buffer
13+
(data (i32.const 36) "\04")
14+
15+
(func $assert (param i32)
16+
(block $ok
17+
(br_if $ok
18+
(get_local 0)
19+
)
20+
(unreachable)
21+
)
22+
)
23+
24+
(func (export "call")
25+
(call $seal_input (i32.const 32) (i32.const 36))
26+
27+
;; assert input size == 4
28+
(call $assert
29+
(i32.eq
30+
(i32.load (i32.const 36))
31+
(i32.const 4)
32+
)
33+
)
34+
35+
;; place a value in storage, the size of which is specified by the call input.
36+
;; we don't care about the contents of the storage item
37+
(call $seal_set_storage
38+
(i32.const 0) ;; Pointer to storage key
39+
(i32.const 0) ;; Pointer to value
40+
(i32.load (i32.const 32)) ;; Size of value
41+
)
42+
)
43+
44+
(func (export "deploy"))
45+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
;; Stores a value of the passed size in constructor.
2+
(module
3+
(import "seal0" "seal_set_storage" (func $seal_set_storage (param i32 i32 i32)))
4+
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
5+
(import "env" "memory" (memory 16 16))
6+
7+
;; [0, 32) storage key
8+
(data (i32.const 0) "\01")
9+
10+
;; [32, 36) buffer where input is copied (expected size of storage item)
11+
12+
;; [36, 40) size of the input buffer
13+
(data (i32.const 36) "\04")
14+
15+
(func $assert (param i32)
16+
(block $ok
17+
(br_if $ok
18+
(get_local 0)
19+
)
20+
(unreachable)
21+
)
22+
)
23+
24+
(func (export "deploy")
25+
(call $seal_input (i32.const 32) (i32.const 36))
26+
27+
;; assert input size == 4
28+
(call $assert
29+
(i32.eq
30+
(i32.load (i32.const 36))
31+
(i32.const 4)
32+
)
33+
)
34+
35+
;; place a value in storage, the size of which is specified by the call input.
36+
;; we don't care about the contents of the storage item
37+
(call $seal_set_storage
38+
(i32.const 0) ;; Pointer to storage key
39+
(i32.const 0) ;; Pointer to value
40+
(i32.load (i32.const 32)) ;; Size of value
41+
)
42+
)
43+
44+
(func (export "call"))
45+
)

0 commit comments

Comments
 (0)