Skip to content

Commit

Permalink
cleanup: api_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat authored Dec 20, 2024
1 parent 034b7ac commit 75d989b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,36 @@ import (
)

func TestValidateAddressFailure(t *testing.T) {
// Set up cache and ensure cleanup after test
cache, cleanup := withCache(t)
defer cleanup()
t.Cleanup(cleanup)

// create contract
// Create contract
wasm, err := os.ReadFile("../../testdata/hackatom.wasm")
require.NoError(t, err)
checksum, err := StoreCode(cache, wasm, true)
require.NoError(t, err)

gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT)
// instantiate it with this store
gasMeter := NewMockGasMeter(testingGasLimit)
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
// If the human address is larger than 32 bytes, it triggers an error in address validation
longName := "long123456789012345678901234567890long"
msg := []byte(`{"verifier": "` + longName + `", "beneficiary": "bob"}`)
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)
res, _, err := Instantiate(cache, checksum, env, info, msg, &igasMeter, store, api, &querier, testingGasLimit, testingPrintDebug)
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
// The contract call succeeds at the VM level but returns a JSON error inside ContractResult
require.Nil(t, result.Ok)
// with this error
require.Equal(t, "Generic error: addr_validate errored: human encoding too long", result.Err)
}

0 comments on commit 75d989b

Please sign in to comment.