Skip to content

Commit 24209d3

Browse files
committed
Add test for SimulateStoreCode
1 parent 57a7cd3 commit 24209d3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib_libwasmvm_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,41 @@ func TestStoreCode(t *testing.T) {
102102
}
103103
}
104104

105+
func TestSimulateStoreCode(t *testing.T) {
106+
vm := withVM(t)
107+
108+
hackatom, err := os.ReadFile(HACKATOM_TEST_CONTRACT)
109+
require.NoError(t, err)
110+
111+
specs := map[string]struct {
112+
wasm []byte
113+
err string
114+
}{
115+
"valid hackatom contract": {
116+
wasm: hackatom,
117+
},
118+
"no wasm": {
119+
wasm: []byte("foobar"),
120+
err: "Wasm bytecode could not be deserialized",
121+
},
122+
}
123+
124+
for name, spec := range specs {
125+
t.Run(name, func(t *testing.T) {
126+
checksum, _, err := vm.SimulateStoreCode(spec.wasm, TESTING_GAS_LIMIT)
127+
128+
if spec.err != "" {
129+
assert.ErrorContains(t, err, spec.err)
130+
} else {
131+
assert.NoError(t, err)
132+
133+
_, err = vm.GetCode(checksum)
134+
assert.ErrorContains(t, err, "Error opening Wasm file for reading")
135+
}
136+
})
137+
}
138+
}
139+
105140
func TestStoreCodeAndGet(t *testing.T) {
106141
vm := withVM(t)
107142

0 commit comments

Comments
 (0)