Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port v0.10 test contract to v1 #944

Merged
merged 14 commits into from
Jul 5, 2022
6 changes: 3 additions & 3 deletions x/compute/internal/keeper/secret_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ type v1QueryResponse struct {
func TestV1EndpointsSanity(t *testing.T) {
ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract.wasm")

contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":10, "expires":100}`, true, true, defaultGasForTests)
contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests)

data, _, _, err := execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, `{"increment":{"addition": 13}}`, true, true, math.MaxUint64, 0)

Expand All @@ -2817,7 +2817,7 @@ func TestV1EndpointsSanity(t *testing.T) {
func TestV1QueryWorksWithEnv(t *testing.T) {
ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract.wasm")

contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":10, "expires":0}`, true, true, defaultGasForTests)
contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":0}}`, true, true, defaultGasForTests)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 10)

queryRes, qErr := queryHelper(t, keeper, ctx, contractAddress, `{"get":{}}`, true, true, math.MaxUint64)
Expand All @@ -2833,7 +2833,7 @@ func TestV1QueryWorksWithEnv(t *testing.T) {
func TestV1ReplySanity(t *testing.T) {
ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, "./testdata/v1-sanity-contract.wasm")

contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":10, "expires":100}`, true, true, defaultGasForTests)
contractAddress, _, _ := initHelper(t, keeper, ctx, codeID, walletA, privKeyA, `{"counter":{"counter":10, "expires":100}}`, true, true, defaultGasForTests)

data, _, _, err := execHelper(t, keeper, ctx, contractAddress, walletA, privKeyA, `{"increment":{"addition": 13}}`, true, true, math.MaxUint64, 0)

Expand Down
206 changes: 196 additions & 10 deletions x/compute/internal/keeper/testdata/v1-sanity-contract/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{
coins, entry_point, to_binary, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
QueryRequest, Reply, ReplyOn, Response, StdError, StdResult, SubMsg, SubMsgResult, WasmMsg,
WasmQuery,
attr, coins, entry_point, to_binary, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env,
assafmo marked this conversation as resolved.
Show resolved Hide resolved
MessageInfo, QueryRequest, Reply, ReplyOn, Response, StdError, StdResult, SubMsg, SubMsgResult,
WasmMsg, WasmQuery,
};

use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg, QueryRes};
Expand All @@ -14,13 +14,61 @@ pub fn instantiate(
_info: MessageInfo,
msg: InstantiateMsg,
) -> StdResult<Response> {
count(deps.storage).save(&msg.counter)?;
let expires = env.block.height + msg.expires;
expiration(deps.storage).save(&expires)?;
match msg {
InstantiateMsg::Counter { counter, expires } => {
count(deps.storage).save(&counter)?;
let expires = env.block.height + expires;
expiration(deps.storage).save(&expires)?;
let mut resp = Response::default();
resp.data = Some(env.contract.address.as_bytes().into());
Ok(resp)
}

let mut resp = Response::default();
resp.data = Some(env.contract.address.as_bytes().into());
Ok(resp)
// These were ported from the v0.10 test-contract:
InstantiateMsg::Nop {} => Ok(Response::new().add_attribute("init", "🌈")),
InstantiateMsg::Callback {
contract_addr,
code_hash,
} => todo!(),
InstantiateMsg::CallbackContractError {
contract_addr,
code_hash,
} => todo!(),
InstantiateMsg::ContractError { error_type } => todo!(),
InstantiateMsg::NoLogs {} => todo!(),
InstantiateMsg::CallbackToInit { code_id, code_hash } => todo!(),
InstantiateMsg::CallbackBadParams {
contract_addr,
code_hash,
} => todo!(),
InstantiateMsg::Panic {} => todo!(),
InstantiateMsg::SendExternalQueryDepthCounter {
to,
depth,
code_hash,
} => todo!(),
InstantiateMsg::SendExternalQueryRecursionLimit {
to,
depth,
code_hash,
} => todo!(),
InstantiateMsg::CallToInit {
code_id,
code_hash,
label,
msg,
} => todo!(),
InstantiateMsg::CallToExec {
addr,
code_hash,
msg,
} => todo!(),
InstantiateMsg::CallToQuery {
addr,
code_hash,
msg,
} => todo!(),
}
}

#[entry_point]
Expand All @@ -36,6 +84,140 @@ pub fn execute(
ExecuteMsg::RecursiveReply {} => recursive_reply(env, deps),
ExecuteMsg::RecursiveReplyFail {} => recursive_reply_fail(env, deps),
ExecuteMsg::InitNewContract {} => init_new_contract(env, deps),

// These were ported from the v0.10 test-contract:
ExecuteMsg::A {
contract_addr,
code_hash,
x,
y,
} => todo!(),
ExecuteMsg::B {
contract_addr,
code_hash,
x,
y,
} => todo!(),
ExecuteMsg::C { x, y } => todo!(),
ExecuteMsg::UnicodeData {} => todo!(),
ExecuteMsg::EmptyLogKeyValue {} => todo!(),
ExecuteMsg::EmptyData {} => todo!(),
ExecuteMsg::NoData {} => todo!(),
ExecuteMsg::ContractError { error_type } => todo!(),
ExecuteMsg::NoLogs {} => todo!(),
ExecuteMsg::CallbackToInit { code_id, code_hash } => todo!(),
ExecuteMsg::CallbackContractError {
contract_addr,
code_hash,
} => todo!(),
ExecuteMsg::CallbackBadParams {
contract_addr,
code_hash,
} => todo!(),
ExecuteMsg::SetState { key, value } => todo!(),
ExecuteMsg::GetState { key } => todo!(),
ExecuteMsg::RemoveState { key } => todo!(),
ExecuteMsg::TestCanonicalizeAddressErrors {} => todo!(),
ExecuteMsg::Panic {} => todo!(),
ExecuteMsg::AllocateOnHeap { bytes } => todo!(),
ExecuteMsg::PassNullPointerToImportsShouldThrow { pass_type } => todo!(),
ExecuteMsg::SendExternalQuery { to, code_hash } => todo!(),
ExecuteMsg::SendExternalQueryPanic { to, code_hash } => todo!(),
ExecuteMsg::SendExternalQueryError { to, code_hash } => todo!(),
ExecuteMsg::SendExternalQueryBadAbi { to, code_hash } => todo!(),
ExecuteMsg::SendExternalQueryBadAbiReceiver { to, code_hash } => todo!(),
ExecuteMsg::LogMsgSender {} => todo!(),
ExecuteMsg::CallbackToLogMsgSender { to, code_hash } => todo!(),
ExecuteMsg::DepositToContract {} => todo!(),
ExecuteMsg::SendFunds {
amount,
denom,
to,
from,
} => todo!(),
ExecuteMsg::SendFundsToInitCallback {
amount,
denom,
code_id,
code_hash,
} => todo!(),
ExecuteMsg::SendFundsToExecCallback {
amount,
denom,
to,
code_hash,
} => todo!(),
ExecuteMsg::Sleep { ms } => todo!(),
ExecuteMsg::SendExternalQueryDepthCounter {
to,
code_hash,
depth,
} => todo!(),
ExecuteMsg::SendExternalQueryRecursionLimit {
to,
code_hash,
depth,
} => todo!(),
ExecuteMsg::WithFloats { x, y } => todo!(),
ExecuteMsg::CallToInit {
code_id,
code_hash,
label,
msg,
} => todo!(),
ExecuteMsg::CallToExec {
addr,
code_hash,
msg,
} => todo!(),
ExecuteMsg::CallToQuery {
addr,
code_hash,
msg,
} => todo!(),
ExecuteMsg::StoreReallyLongKey {} => todo!(),
ExecuteMsg::StoreReallyShortKey {} => todo!(),
ExecuteMsg::StoreReallyLongValue {} => todo!(),
ExecuteMsg::Secp256k1Verify {
pubkey,
sig,
msg_hash,
iterations,
} => todo!(),
ExecuteMsg::Secp256k1VerifyFromCrate {
pubkey,
sig,
msg_hash,
iterations,
} => todo!(),
ExecuteMsg::Ed25519Verify {
pubkey,
sig,
msg,
iterations,
} => todo!(),
ExecuteMsg::Ed25519BatchVerify {
pubkeys,
sigs,
msgs,
iterations,
} => todo!(),
ExecuteMsg::Secp256k1RecoverPubkey {
msg_hash,
sig,
recovery_param,
iterations,
} => todo!(),
ExecuteMsg::Secp256k1Sign {
msg,
privkey,
iterations,
} => todo!(),
ExecuteMsg::Ed25519Sign {
msg,
privkey,
iterations,
} => todo!(),
}
}

Expand Down Expand Up @@ -109,7 +291,11 @@ pub fn init_new_contract(env: Env, _deps: DepsMut) -> StdResult<Response> {
msg: CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: None,
code_hash: env.contract.code_hash,
msg: Binary::from("{\"counter\":150, \"expires\":100}".as_bytes().to_vec()),
msg: Binary::from(
"{\"counter\":{\"counter\":150, \"expires\":100}}"
.as_bytes()
.to_vec(),
),
funds: vec![],
label: "new202213".to_string(),
code_id: 1,
Expand Down
Loading