Skip to content

Commit

Permalink
Handle genesis config 'voting_perdiod' and CLI 'query txs' changes fo…
Browse files Browse the repository at this point in the history
…r Cosmos SDK v0.50.1
  • Loading branch information
ljoss17 committed Nov 13, 2023
1 parent b9b9373 commit d57911e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tools/integration-test/src/tests/client_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use ibc_test_framework::{
};

const MAX_DEPOSIT_PERIOD: &str = "10s";
const VOTING_PERIOD: &str = "10s";
const VOTING_PERIOD: u64 = 10;
const DELTA_HEIGHT: u64 = 15;
const WAIT_CHAIN_UPGRADE: Duration = Duration::from_secs(4);
const MAX_WAIT_FOR_CHAIN_HEIGHT: Duration = Duration::from_secs(60);
Expand Down
2 changes: 1 addition & 1 deletion tools/integration-test/src/tests/ics31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TestOverrides for ICS31Test {
*duration = serde_json::Value::String("20s".to_owned());
}
}
set_voting_period(genesis, "20s")?;
set_voting_period(genesis, 20)?;
set_staking_max_entries(genesis, "10")?;
set_staking_bond_denom(genesis, "stake")?;
set_mint_mint_denom(genesis, "stake")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl TestOverrides for InterchainSecurityIcqTest {
*duration = serde_json::Value::String("20s".to_owned());
}
}
set_voting_period(genesis, "10s")?;
set_voting_period(genesis, 10)?;
set_staking_max_entries(genesis, "10")?;
set_staking_bond_denom(genesis, "stake")?;
set_mint_mint_denom(genesis, "stake")?;
Expand Down
23 changes: 20 additions & 3 deletions tools/test-framework/src/chain/cli/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn query_recipient_transactions(
rpc_listen_address: &str,
recipient_address: &str,
) -> Result<json::Value, Error> {
let res = simple_exec(
let res = match simple_exec(
chain_id,
command_path,
&[
Expand All @@ -122,8 +122,25 @@ pub fn query_recipient_transactions(
"--events",
&format!("transfer.recipient={recipient_address}"),
],
)?
.stdout;
) {
Ok(output) => output.stdout,
// Cosmos SDK v0.50.1 changed the `query txs` CLI flag from `--events` to `--query`
Err(_) => {
simple_exec(
chain_id,
command_path,
&[
"--node",
rpc_listen_address,
"query",
"txs",
"--query",
&format!("transfer.recipient='{recipient_address}'"),
],
)?
.stdout
}
};

tracing::debug!("parsing tx result: {}", res);

Expand Down
32 changes: 30 additions & 2 deletions tools/test-framework/src/chain/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use core::time::Duration;
use eyre::{eyre, Report as Error};
use toml::Value;
use tracing::debug;

/// Set the `rpc` field in the full node config.
pub fn set_rpc_port(config: &mut Value, port: u16) -> Result<(), Error> {
Expand Down Expand Up @@ -253,7 +254,10 @@ pub fn set_crisis_denom(genesis: &mut serde_json::Value, crisis_denom: &str) ->
Ok(())
}

pub fn set_voting_period(genesis: &mut serde_json::Value, period: &str) -> Result<(), Error> {
pub fn set_voting_period(genesis: &mut serde_json::Value, period: u64) -> Result<(), Error> {
// Expedited voting period must be strictly less that the regular voting period
let regular_period = format!("{period}s");
let expedited_period = format!("{}s", period - 1);
let voting_period = genesis
.get_mut("app_state")
.and_then(|app_state| app_state.get_mut("gov"))
Expand All @@ -264,10 +268,34 @@ pub fn set_voting_period(genesis: &mut serde_json::Value, period: &str) -> Resul
voting_period
.insert(
"voting_period".to_owned(),
serde_json::Value::String(period.to_string()),
serde_json::Value::String(regular_period),
)
.ok_or_else(|| eyre!("failed to update voting_period in genesis file"))?;

let maybe_expedited_voting_period = genesis
.get_mut("app_state")
.and_then(|app_state| app_state.get_mut("gov"))
.and_then(|gov| get_mut_with_fallback(gov, "params", "expedited_voting_period"));

if let Some(expedited_voting_period) = maybe_expedited_voting_period {
let expedited_voting_period = expedited_voting_period
.as_object_mut()
.ok_or_else(|| eyre!("failed to get voting_params in genesis file"))?;

// Only insert `expedited_voting_period` if it already exists in order to avoid adding an unknown configuration in
// chains using Cosmos SDK pre v0.50
match expedited_voting_period.get("expedited_voting_period") {
Some(_) => {
expedited_voting_period
.insert(
"expedited_voting_period".to_owned(),
serde_json::Value::String(expedited_period),
).ok_or_else(|| eyre!("failed to update expedited_voting_period in genesis file"))?;
},
None => debug!("`expedited_voting_period` was not updated, this configuration was introduced in Cosmos SDK v0.50"),
}
}

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion tools/test-framework/src/util/interchain_security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn update_genesis_for_consumer_chain(genesis: &mut serde_json::Value) -> Res
.and_then(|app_state| app_state.get("gov"))
.is_some()
{
set_voting_period(genesis, "10s")?;
set_voting_period(genesis, 10)?;
}
Ok(())
}
Expand Down

0 comments on commit d57911e

Please sign in to comment.