Move contracts wasm test code into separate files (#5337)

* Move contracts wasm test code into separate files

* Move crypto_hashes into a separate file

* Load wasm code at runtime

* Move wasm files

* Fix wasm formatting

* Update crypto_hashes file
This commit is contained in:
Stanislav Tkach
2020-04-09 01:16:49 +03:00
committed by GitHub
parent 7e5424ddad
commit 8576937f44
17 changed files with 1169 additions and 1196 deletions
@@ -0,0 +1,74 @@
(module
(import "env" "ext_get_runtime_storage"
(func $ext_get_runtime_storage (param i32 i32) (result i32))
)
(import "env" "ext_scratch_size" (func $ext_scratch_size (result i32)))
(import "env" "ext_scratch_read" (func $ext_scratch_read (param i32 i32 i32)))
(import "env" "ext_scratch_write" (func $ext_scratch_write (param i32 i32)))
(import "env" "memory" (memory 1 1))
(func (export "deploy"))
(func $assert (param i32)
(block $ok
(br_if $ok
(get_local 0)
)
(unreachable)
)
)
(func $call (export "call")
;; Load runtime storage for the first key and assert that it exists.
(call $assert
(i32.eq
(call $ext_get_runtime_storage
(i32.const 16)
(i32.const 4)
)
(i32.const 0)
)
)
;; assert $ext_scratch_size == 4
(call $assert
(i32.eq
(call $ext_scratch_size)
(i32.const 4)
)
)
;; copy contents of the scratch buffer into the contract's memory.
(call $ext_scratch_read
(i32.const 4) ;; Pointer in memory to the place where to copy.
(i32.const 0) ;; Offset from the start of the scratch buffer.
(i32.const 4) ;; Count of bytes to copy.
)
;; assert that contents of the buffer is equal to the i32 value of 0x14144020.
(call $assert
(i32.eq
(i32.load
(i32.const 4)
)
(i32.const 0x14144020)
)
)
;; Load the second key and assert that it doesn't exist.
(call $assert
(i32.eq
(call $ext_get_runtime_storage
(i32.const 20)
(i32.const 4)
)
(i32.const 1)
)
)
)
;; The first key, 4 bytes long.
(data (i32.const 16) "\01\02\03\04")
;; The second key, 4 bytes long.
(data (i32.const 20) "\02\03\04\05")
)