forked from CosmWasm/wasmvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_test.go
47 lines (38 loc) · 1.47 KB
/
api_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
package api
import (
"encoding/json"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/CosmWasm/wasmvm/v2/types"
)
func TestValidateAddressFailure(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()
// create contract
wasm, err := os.ReadFile("../../testdata/hackatom.wasm")
require.NoError(t, err)
checksum, err := StoreCode(cache, wasm)
require.NoError(t, err)
gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
// instantiate it with this store
store := NewLookup(gasMeter)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
// if the human address is larger than 32 bytes, this will lead to an error in the go side
longName := "long123456789012345678901234567890long"
msg := []byte(`{"verifier": "` + longName + `", "beneficiary": "bob"}`)
// make sure the call doesn't error, but we get a JSON-encoded error result from ContractResult
igasMeter := types.GasMeter(gasMeter)
res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
require.NoError(t, err)
var result types.ContractResult
err = json.Unmarshal(res, &result)
require.NoError(t, err)
// ensure the error message is what we expect
require.Nil(t, result.Ok)
// with this error
require.Equal(t, "Generic error: addr_validate errored: human encoding too long", result.Err)
}