-
Notifications
You must be signed in to change notification settings - Fork 2
/
guest_function_test.go
61 lines (48 loc) · 1.18 KB
/
guest_function_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package wasify_test
import (
"context"
_ "embed"
"testing"
"github.com/stretchr/testify/assert"
"github.com/wasify-io/wasify-go"
)
//go:embed testdata/wasm/guest_all_available_types/main.wasm
var wasm_guestAllAvailableTypes []byte
func TestGuestFunctions(t *testing.T) {
testRuntimeConfig := wasify.RuntimeConfig{
Runtime: wasify.RuntimeWazero,
LogSeverity: wasify.LogError,
}
testModuleConfig := wasify.ModuleConfig{
Namespace: "guest_all_available_types",
Wasm: wasify.Wasm{
Binary: wasm_guestAllAvailableTypes,
},
}
t.Run("successful instantiation", func(t *testing.T) {
ctx := context.Background()
runtime, err := wasify.NewRuntime(ctx, &testRuntimeConfig)
assert.NoError(t, err)
defer func() {
err = runtime.Close(ctx)
assert.NoError(t, err)
}()
module, err := runtime.NewModule(ctx, &testModuleConfig)
defer func() {
err = module.Close(ctx)
assert.NoError(t, err)
}()
res, err := module.GuestFunction(ctx, "guestTest").Invoke(
[]byte("bytes!"),
byte(1),
uint32(32),
uint64(64),
float32(32.0),
float64(64.01),
"Wasify",
"any type",
)
assert.NoError(t, err)
t.Log("TestGuestFunctions RES:", res)
})
}