Skip to content

Commit

Permalink
Merge pull request #1141 from scrtlabs/add-validate-test
Browse files Browse the repository at this point in the history
Add validate test
  • Loading branch information
liorbond authored Sep 8, 2022
2 parents 8bcf46c + 3744932 commit d4b5a44
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions x/compute/internal/keeper/secret_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")?)),
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ pub enum ExecuteMsg {
to: String,
code_hash: String,
},
ValidateAddress {
addr: String,
},
Sleep {
ms: u64,
},
Expand Down

0 comments on commit d4b5a44

Please sign in to comment.