diff --git a/x/compute/internal/keeper/secret_contracts_test.go b/x/compute/internal/keeper/secret_contracts_test.go index fa97f1e05..33ede3a3d 100644 --- a/x/compute/internal/keeper/secret_contracts_test.go +++ b/x/compute/internal/keeper/secret_contracts_test.go @@ -6220,3 +6220,21 @@ func TestReplyGasExceedingMessageGas(t *testing.T) { }() _, _, _, _, _ = initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"measure_gas_for_submessage":{"id":2600}}`, false, true, defaultGasForTests) } + +func TestAddrValidateFunction(t *testing.T) { + ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract/v1-contract.wasm", sdk.NewCoins()) + + _, _, v1ContractAddress, _, err := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"nop":{}}`, true, true, defaultGasForTests) + require.Empty(t, err) + + _, _, data, _, _, err := execHelper(t, keeper, ctx, v1ContractAddress, walletA, privKeyA, fmt.Sprintf(`{"validate_address":{"addr":"%s"}}`, v1ContractAddress), true, true, defaultGasForTests, 0) + require.Empty(t, err) + + resp, aErr := sdk.AccAddressFromBech32(string(data)) + require.Empty(t, aErr) + + require.Equal(t, resp, v1ContractAddress) + + _, _, data, _, _, err = execHelper(t, keeper, ctx, v1ContractAddress, walletA, privKeyA, fmt.Sprintf(`{"validate_address":{"addr":"secret18vd8fpwxzck93qlwghaj6arh4p7c5nyf7hmag8"}}`), true, true, defaultGasForTests, 0) + require.Equal(t, string(data), "\"Apple\"") +} diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs index c6b5b6af9..1f16fbc60 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs @@ -1164,6 +1164,10 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S funds: coins, })), ), + ExecuteMsg::ValidateAddress { addr } => match deps.api.addr_validate(addr.as_str()) { + Ok(a) => Ok(Response::new().set_data(a.as_bytes())), + Err(_) => Ok(Response::new().set_data(to_binary("Apple")?)), + }, } } diff --git a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs index ff1480e28..7165edf57 100644 --- a/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs +++ b/x/compute/internal/keeper/testdata/v1-sanity-contract/src/msg.rs @@ -310,6 +310,9 @@ pub enum ExecuteMsg { to: String, code_hash: String, }, + ValidateAddress { + addr: String, + }, Sleep { ms: u64, },