forked from bandprotocol/bandchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func readWatFile(fileName string) []byte { | ||
code, err := ioutil.ReadFile(fmt.Sprintf("./../wasm/%s.wat", fileName)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return code | ||
} | ||
|
||
func readWasmFile(fileName string) []byte { | ||
code, err := ioutil.ReadFile(fmt.Sprintf("./../wasm/%s.wasm", fileName)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return code | ||
} | ||
|
||
func TestSuccessWatToOwasm(t *testing.T) { | ||
code := readWatFile("test") | ||
wasm, err := WatToWasm(code) | ||
require.NoError(t, err) | ||
|
||
expectedWasm := readWasmFile("test") | ||
require.Equal(t, expectedWasm, wasm) | ||
} | ||
|
||
func TestFailInvalidWatContent(t *testing.T) { | ||
code := []byte("invalid wat content") | ||
wasm, err := WatToWasm(code) | ||
require.Equal(t, ErrParseFail, err) | ||
require.Equal(t, []byte(""), wasm) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(module | ||
(type $t0 (func)) | ||
(type $t1 (func (param i64 i64 i64 i64))) | ||
(import "env" "ask_external_data" (func $ask_external_data (type $t1))) | ||
(func $prepare (export "prepare") (type $t0) | ||
(local $l0 i64) | ||
i64.const 1 | ||
i64.const 1 | ||
i32.const 1024 | ||
i64.extend_u/i32 | ||
tee_local $l0 | ||
i64.const 10 | ||
call $ask_external_data | ||
i64.const 2 | ||
i64.const 3 | ||
get_local $l0 | ||
i64.const 10 | ||
call $ask_external_data | ||
i64.const 4 | ||
i64.const 5 | ||
get_local $l0 | ||
i64.const 10 | ||
call $ask_external_data) | ||
(table $T0 1 1 anyfunc) | ||
(memory $memory (export "memory") 17) | ||
(data (i32.const 1024) "helloworld")) |