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

feat: NTRN-260 control tx submission workflow via INTEGRATION_TESTS_QUERY_MOCK variable #68

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
94c97b03bf43e1d2064f7255b0cbdecf9eb3cbb90aee04ac885f11dd744f07d7 ibc_transfer.wasm
07586abddaff15b84725b5266d39564acd1929c22b64efd2af9db06a99e924df neutron_interchain_queries.wasm
115c0b64f0ce6bb2299e9deb35dc238dc059fbf3971c7e4a0f4819e88c687595 neutron_interchain_queries.wasm
94b991497c807fbb3fd9b7c95458029a9fd2c39fe08aff6211a5ef0f3173a087 neutron_interchain_txs.wasm
beecb5de00039e7104117060c66c2ece4ff85ea30ea1bc3c884f15b778e7ea87 neutron_validators_test.wasm
2e7a0f168de97eebf4080df6f9fe23987fc96ac5852f29ca6c489dee7b10e6dd reflect.wasm
Binary file modified artifacts/neutron_interchain_queries.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions contracts/neutron_interchain_queries/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@
"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",
"required": [
"integration_tests_set_kv_query_mock"
"integration_tests_set_query_mock"
],
"properties": {
"integration_tests_set_kv_query_mock": {
"integration_tests_set_query_mock": {
"type": "object"
}
},
Expand All @@ -385,10 +385,10 @@
"description": "Used only in integration tests framework to simulate failures. After executing this message, contract will revert back to normal behaviour.",
"type": "object",
"required": [
"integration_tests_unset_kv_query_mock"
"integration_tests_unset_query_mock"
],
"properties": {
"integration_tests_unset_kv_query_mock": {
"integration_tests_unset_query_mock": {
"type": "object"
}
},
Expand Down
20 changes: 13 additions & 7 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::msg::{
KvCallbackStatsResponse, MigrateMsg, QueryMsg,
};
use crate::state::{
IntegrationTestsKvMock, Transfer, INTEGRATION_TESTS_KV_MOCK, KV_CALLBACK_STATS, RECIPIENT_TXS,
TRANSFERS,
IntegrationTestsQueryMock, Transfer, INTEGRATION_TESTS_QUERY_MOCK, KV_CALLBACK_STATS,
RECIPIENT_TXS, TRANSFERS,
};
use neutron_sdk::bindings::msg::NeutronMsg;
use neutron_sdk::bindings::query::{InterchainQueries, QueryRegisteredQueryResponse};
Expand All @@ -45,7 +45,7 @@ use neutron_sdk::interchain_queries::{
use neutron_sdk::sudo::msg::SudoMsg;
use neutron_sdk::{NeutronError, NeutronResult};

use crate::integration_tests_mock_handlers::{set_kv_query_mock, unset_kv_query_mock};
use crate::integration_tests_mock_handlers::{set_query_mock, unset_query_mock};
use neutron_sdk::interchain_queries::types::{
QueryType, TransactionFilterItem, TransactionFilterOp, TransactionFilterValue,
COSMOS_SDK_TRANSFER_MSG_URL, RECIPIENT_FIELD,
Expand Down Expand Up @@ -123,8 +123,8 @@ pub fn execute(
new_recipient,
} => update_interchain_query(query_id, new_keys, new_update_period, new_recipient),
ExecuteMsg::RemoveInterchainQuery { query_id } => remove_interchain_query(query_id),
ExecuteMsg::IntegrationTestsSetKvQueryMock {} => set_kv_query_mock(deps),
ExecuteMsg::IntegrationTestsUnsetKvQueryMock {} => unset_kv_query_mock(deps),
ExecuteMsg::IntegrationTestsSetQueryMock {} => set_query_mock(deps),
ExecuteMsg::IntegrationTestsUnsetQueryMock {} => unset_query_mock(deps),
ExecuteMsg::IntegrationTestsRegisterQueryEmptyId { connection_id } => {
register_query_empty_id(deps, env, connection_id)
}
Expand Down Expand Up @@ -380,6 +380,12 @@ pub fn sudo_tx_query_result(
_height: u64,
data: Binary,
) -> NeutronResult<Response> {
if let Some(IntegrationTestsQueryMock::Enabled {}) =
INTEGRATION_TESTS_QUERY_MOCK.may_load(deps.storage)?
{
// simulate error on tx query submit for integration tests
return Err(NeutronError::IntegrationTestsMock {});
}
// Decode the transaction data
let tx: TxRaw = TxRaw::decode(data.as_slice())?;
let body: TxBody = TxBody::decode(tx.body_bytes.as_slice())?;
Expand Down Expand Up @@ -504,8 +510,8 @@ pub fn sudo_kv_query_result(
.as_str(),
);

if let Some(IntegrationTestsKvMock::Enabled {}) =
INTEGRATION_TESTS_KV_MOCK.may_load(deps.storage)?
if let Some(IntegrationTestsQueryMock::Enabled {}) =
INTEGRATION_TESTS_QUERY_MOCK.may_load(deps.storage)?
{
// doesn't really matter whatever data we try to save here, it should all be reverted
// since we return an error in this branch anyway. in fact, this branch exists for the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::state::{IntegrationTestsKvMock, INTEGRATION_TESTS_KV_MOCK};
use crate::state::{IntegrationTestsQueryMock, INTEGRATION_TESTS_QUERY_MOCK};
use cosmwasm_std::{DepsMut, Response};
use neutron_sdk::bindings::msg::NeutronMsg;
use neutron_sdk::bindings::query::InterchainQueries;
use neutron_sdk::NeutronResult;

pub fn set_kv_query_mock(deps: DepsMut<InterchainQueries>) -> NeutronResult<Response<NeutronMsg>> {
INTEGRATION_TESTS_KV_MOCK.save(deps.storage, &IntegrationTestsKvMock::Enabled)?;
pub fn set_query_mock(deps: DepsMut<InterchainQueries>) -> NeutronResult<Response<NeutronMsg>> {
INTEGRATION_TESTS_QUERY_MOCK.save(deps.storage, &IntegrationTestsQueryMock::Enabled)?;
Ok(Response::default())
}

pub fn unset_kv_query_mock(
deps: DepsMut<InterchainQueries>,
) -> NeutronResult<Response<NeutronMsg>> {
INTEGRATION_TESTS_KV_MOCK.save(deps.storage, &IntegrationTestsKvMock::Disabled)?;
pub fn unset_query_mock(deps: DepsMut<InterchainQueries>) -> NeutronResult<Response<NeutronMsg>> {
INTEGRATION_TESTS_QUERY_MOCK.save(deps.storage, &IntegrationTestsQueryMock::Disabled)?;
Ok(Response::default())
}
4 changes: 2 additions & 2 deletions contracts/neutron_interchain_queries/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ pub enum ExecuteMsg {
/// 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.
IntegrationTestsSetKvQueryMock {},
IntegrationTestsSetQueryMock {},
/// Used only in integration tests framework to simulate failures.
/// After executing this message, contract will revert back to normal behaviour.
IntegrationTestsUnsetKvQueryMock {},
IntegrationTestsUnsetQueryMock {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/neutron_interchain_queries/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub struct Transfer {
pub amount: String,
}

pub const INTEGRATION_TESTS_KV_MOCK: Item<IntegrationTestsKvMock> =
pub const INTEGRATION_TESTS_QUERY_MOCK: Item<IntegrationTestsQueryMock> =
Item::new("integration_tests_kv_mock");

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub enum IntegrationTestsKvMock {
pub enum IntegrationTestsQueryMock {
Enabled,
Disabled,
}
Expand Down