|
| 1 | +package api |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "io/ioutil" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + "github.com/CosmWasm/wasmvm/types" |
| 11 | +) |
| 12 | + |
| 13 | +func TestValidateAddressFailure(t *testing.T) { |
| 14 | + cache, cleanup := withCache(t) |
| 15 | + defer cleanup() |
| 16 | + |
| 17 | + // create contract |
| 18 | + wasm, err := ioutil.ReadFile("../../testdata/hackatom.wasm") |
| 19 | + require.NoError(t, err) |
| 20 | + checksum, err := StoreCode(cache, wasm) |
| 21 | + require.NoError(t, err) |
| 22 | + |
| 23 | + gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT) |
| 24 | + // instantiate it with this store |
| 25 | + store := NewLookup(gasMeter) |
| 26 | + api := NewMockAPI() |
| 27 | + querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")}) |
| 28 | + env := MockEnvBin(t) |
| 29 | + info := MockInfoBin(t, "creator") |
| 30 | + |
| 31 | + // if the human address is larger than 32 bytes, this will lead to an error in the go side |
| 32 | + longName := "long123456789012345678901234567890long" |
| 33 | + msg := []byte(`{"verifier": "` + longName + `", "beneficiary": "bob"}`) |
| 34 | + |
| 35 | + // make sure the call doesn't error, but we get a JSON-encoded error result from ContractResult |
| 36 | + igasMeter := types.GasMeter(gasMeter) |
| 37 | + res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) |
| 38 | + require.NoError(t, err) |
| 39 | + var result types.ContractResult |
| 40 | + err = json.Unmarshal(res, &result) |
| 41 | + require.NoError(t, err) |
| 42 | + |
| 43 | + // ensure the error message is what we expect |
| 44 | + require.Nil(t, result.Ok) |
| 45 | + // with this error |
| 46 | + require.Equal(t, "Generic error: addr_validate errored: human encoding too long", result.Err) |
| 47 | +} |
0 commit comments