-
Notifications
You must be signed in to change notification settings - Fork 106
/
lib_test.go
32 lines (25 loc) · 949 Bytes
/
lib_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
package cosmwasm
import (
"testing"
"github.com/CosmWasm/wasmvm/v2/types"
"github.com/stretchr/testify/require"
)
func TestCreateChecksum(t *testing.T) {
// nil
_, err := CreateChecksum(nil)
require.ErrorContains(t, err, "nil or empty")
// empty
_, err = CreateChecksum([]byte{})
require.ErrorContains(t, err, "nil or empty")
// short
_, err = CreateChecksum([]byte("\x00\x61\x73"))
require.ErrorContains(t, err, " shorter than 4 bytes")
// Wasm blob returns correct hash
// echo "(module)" > my.wat && wat2wasm my.wat && hexdump -C my.wasm && sha256sum my.wasm
checksum, err := CreateChecksum([]byte("\x00\x61\x73\x6d\x01\x00\x00\x00"))
require.NoError(t, err)
require.Equal(t, types.ForceNewChecksum("93a44bbb96c751218e4c00d479e4c14358122a389acca16205b1e4d0dc5f9476"), checksum)
// Text file fails
_, err = CreateChecksum([]byte("Hello world"))
require.ErrorContains(t, err, "do not not start with Wasm magic number")
}