Skip to content

Commit

Permalink
feat: tooling for tests about malformed kv queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik committed Oct 17, 2022
1 parent 2a3c862 commit 3cbf7f0
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 4 deletions.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ead6981fb868b4eb91a11c12f6b35f9320ebdb24ef90867cfd1e12afcbf2ec0a ibc_transfer.wasm
183df19e69fa3df61ea7b6f213f855ed16a01d36d48cc5317218c7b3bdcabf58 neutron_interchain_queries.wasm
545b0c7d43927767617dc74820108af20dd250ae3f70326cd2f9cba63bb650ef neutron_interchain_queries.wasm
bff6464e045915d4286718630624a1bcb3b535d49808539225eedf9eedc2830f neutron_interchain_txs.wasm
577c821c8667df4cb1c34bb0ff80af5cc96c8f42a7286e1b2a7e7fd76ef7d689 reflect.wasm
Binary file modified artifacts/neutron_interchain_queries.wasm
Binary file not shown.
63 changes: 63 additions & 0 deletions contracts/neutron_interchain_queries/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,69 @@
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures.",
"type": "object",
"required": [
"integration_tests_register_query_empty_keys"
],
"properties": {
"integration_tests_register_query_empty_keys": {
"type": "object",
"required": [
"connection_id"
],
"properties": {
"connection_id": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures.",
"type": "object",
"required": [
"integration_tests_register_query_empty_path"
],
"properties": {
"integration_tests_register_query_empty_path": {
"type": "object",
"required": [
"connection_id"
],
"properties": {
"connection_id": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures.",
"type": "object",
"required": [
"integration_tests_register_query_empty_id"
],
"properties": {
"integration_tests_register_query_empty_id": {
"type": "object",
"required": [
"connection_id"
],
"properties": {
"connection_id": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "Used only in integration tests framework to simulate failures. After executing this message, contract will attempt to alter state, zero out kv query statistics and then fail, all of this happening in sudo kv callback handler.",
"type": "object",
Expand Down
71 changes: 70 additions & 1 deletion contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use cosmos_sdk_proto::cosmos::tx::v1beta1::{TxBody, TxRaw};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
};
use neutron_sdk::interchain_queries::register_queries::register_interchain_query_msg;
use prost::Message as ProstMessage;

use crate::msg::{
Expand All @@ -42,7 +43,7 @@ use neutron_sdk::{NeutronError, NeutronResult};

use crate::integration_tests_mock_handlers::{set_kv_query_mock, unset_kv_query_mock};
use neutron_sdk::interchain_queries::types::{
TransactionFilterItem, TransactionFilterOp, TransactionFilterValue,
QueryType, TransactionFilterItem, TransactionFilterOp, TransactionFilterValue,
COSMOS_SDK_TRANSFER_MSG_URL, RECIPIENT_FIELD,
};
use serde_json_wasm;
Expand Down Expand Up @@ -109,6 +110,15 @@ pub fn execute(
ExecuteMsg::RemoveInterchainQuery { query_id } => remove_interchain_query(query_id),
ExecuteMsg::IntegrationTestsSetKvQueryMock {} => set_kv_query_mock(deps),
ExecuteMsg::IntegrationTestsUnsetKvQueryMock {} => unset_kv_query_mock(deps),
ExecuteMsg::IntegrationTestsRegisterQueryEmptyId { connection_id } => {
register_query_empty_id(deps, env, connection_id)
}
ExecuteMsg::IntegrationTestsRegisterQueryEmptyPath { connection_id } => {
register_query_empty_path(deps, env, connection_id)
}
ExecuteMsg::IntegrationTestsRegisterQueryEmptyKeys { connection_id } => {
register_query_empty_keys(deps, env, connection_id)
}
}
}

Expand Down Expand Up @@ -165,6 +175,65 @@ pub fn register_transfers_query(
Ok(Response::new().add_message(msg))
}

pub fn register_query_empty_id(
deps: DepsMut<InterchainQueries>,
env: Env,
connection_id: String,
) -> NeutronResult<Response<NeutronMsg>> {
let kv_key = KVKey {
path: "test".to_string(),
key: Binary(vec![]),
};
let msg = register_interchain_query_msg(
deps,
env,
connection_id,
QueryType::KV,
vec![kv_key],
String::new(),
10,
)?;
Ok(Response::new().add_message(msg))
}

pub fn register_query_empty_path(
deps: DepsMut<InterchainQueries>,
env: Env,
connection_id: String,
) -> NeutronResult<Response<NeutronMsg>> {
let kv_key = KVKey {
path: "".to_string(),
key: Binary("test".as_bytes().to_vec()),
};
let msg = register_interchain_query_msg(
deps,
env,
connection_id,
QueryType::KV,
vec![kv_key],
String::new(),
10,
)?;
Ok(Response::new().add_message(msg))
}

pub fn register_query_empty_keys(
deps: DepsMut<InterchainQueries>,
env: Env,
connection_id: String,
) -> NeutronResult<Response<NeutronMsg>> {
let msg = register_interchain_query_msg(
deps,
env,
connection_id,
QueryType::KV,
vec![],
String::new(),
10,
)?;
Ok(Response::new().add_message(msg))
}

pub fn update_interchain_query(
query_id: u64,
new_keys: Option<Vec<KVKey>>,
Expand Down
12 changes: 12 additions & 0 deletions contracts/neutron_interchain_queries/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ pub enum ExecuteMsg {
query_id: u64,
},
/// Used only in integration tests framework to simulate failures.
IntegrationTestsRegisterQueryEmptyKeys {
connection_id: String,
},
/// Used only in integration tests framework to simulate failures.
IntegrationTestsRegisterQueryEmptyPath {
connection_id: String,
},
/// Used only in integration tests framework to simulate failures.
IntegrationTestsRegisterQueryEmptyId {
connection_id: String,
},
/// Used only in integration tests framework to simulate failures.
/// After executing this message, contract will attempt to alter state,
/// zero out kv query statistics and then fail, all of this happening
/// in sudo kv callback handler.
Expand Down
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/interchain_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

pub mod helpers;
pub mod queries;
mod register_queries;
pub mod register_queries;
pub mod types;

pub use register_queries::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use schemars::_serde_json::to_string;

#[allow(clippy::too_many_arguments)]
/// Creates a message to register an Interchain Query with provided params
fn register_interchain_query_msg(
pub fn register_interchain_query_msg(
_deps: DepsMut<InterchainQueries>,
_env: Env,
connection_id: String,
Expand Down

0 comments on commit 3cbf7f0

Please sign in to comment.