Skip to content

Commit

Permalink
Added support for Evmos in integration tests (#2606)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 authored Sep 7, 2022
1 parent c64d9c1 commit d474c24
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added Evmos compatible integration tests
([#2442](https://github.com/informalsystems/ibc-rs/issues/2442))
3 changes: 3 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
- package: wasmd
command: wasmd
account_prefix: wasm
- package: evmos
command: evmosd
account_prefix: evmos
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v15
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
ibc-go-v4-simapp
ibc-go-v5-simapp
apalache
evmos
;

python = nixpkgs.python3.withPackages (p: [
Expand Down
2 changes: 1 addition & 1 deletion tools/integration-test/src/tests/client_refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl BinaryChainTest for ClientFailsTest {
let mut client_b_to_a = chains2.foreign_clients.client_b_to_a;

// Wait for elapsed > refresh_window
std::thread::sleep(core::time::Duration::from_secs(40));
std::thread::sleep(core::time::Duration::from_secs(45));

let res = client_a_to_b.refresh();
// Assert that `refresh()` returns an error as the update client will fail due to the low `gas_multiplier`.
Expand Down
2 changes: 1 addition & 1 deletion tools/test-framework/src/bootstrap/binary/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn new_registry(config: Config) -> SharedRegistry<CountingAndCachingChainHan
[`FullNode`] and add it to the relayer's [`Config`].
*/
pub fn add_chain_config(config: &mut Config, running_node: &FullNode) -> Result<(), Error> {
let chain_config = running_node.generate_chain_config()?;
let chain_config = running_node.generate_chain_config(&running_node.chain_driver.chain_type)?;

config.chains.push(chain_config);
Ok(())
Expand Down
5 changes: 4 additions & 1 deletion tools/test-framework/src/bootstrap/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub fn bootstrap_single_node(
Denom::base("samoleans")
};

let initial_amount = random_u64_range(1_000_000_000_000, 9_000_000_000_000);
// Evmos requires of at least 1_000_000_000_000_000_000 or else there will be the
// error `error during handshake: error on replay: validator set is nil in genesis and still empty after InitChain`
// when running `evmosd start`.
let initial_amount = random_u64_range(1_000_000_000_000_000_000, u64::MAX);

let chain_driver = builder.new_chain(prefix, use_random_id)?;

Expand Down
16 changes: 9 additions & 7 deletions tools/test-framework/src/chain/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
Builder construct that spawn new chains with some common parameters.
*/

use std::str::FromStr;

use alloc::sync::Arc;
use ibc::core::ics24_host::identifier::ChainId;
use tokio::runtime::Runtime;

use crate::chain::driver::ChainDriver;
use crate::error::Error;
use crate::types::config::TestConfig;
use crate::util::random::{random_u32, random_unused_tcp_port};
use crate::util::random::random_unused_tcp_port;

use super::chain_type::ChainType;

/**
Used for holding common configuration needed to create new `ChainDriver`s.
Expand Down Expand Up @@ -84,11 +87,9 @@ impl ChainBuilder {
`"ibc-alpha-f5a2a988"`.
*/
pub fn new_chain(&self, prefix: &str, use_random_id: bool) -> Result<ChainDriver, Error> {
let chain_id = if use_random_id {
ChainId::from_string(&format!("ibc-{}-{:x}", prefix, random_u32()))
} else {
ChainId::from_string(&format!("ibc-{}", prefix))
};
let chain_type = ChainType::from_str(&self.command_path[..])?;

let chain_id = chain_type.chain_id(prefix, use_random_id);

let rpc_port = random_unused_tcp_port();
let grpc_port = random_unused_tcp_port();
Expand All @@ -98,6 +99,7 @@ impl ChainBuilder {
let home_path = format!("{}/{}", self.base_store_dir, chain_id);

let driver = ChainDriver::create(
chain_type,
self.command_path.clone(),
chain_id,
home_path,
Expand Down
75 changes: 75 additions & 0 deletions tools/test-framework/src/chain/chain_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use core::str::FromStr;
use ibc::core::ics24_host::identifier::ChainId;
use ibc_relayer::config::AddressType;

use crate::error::Error;
use crate::util::random::{random_u32, random_unused_tcp_port};

const COSMOS_HD_PATH: &str = "m/44'/118'/0'/0/0";
const EVMOS_HD_PATH: &str = "m/44'/60'/0'/0/0";

#[derive(Clone, Debug)]
pub enum ChainType {
Cosmos,
Evmos,
}

impl ChainType {
pub fn hd_path(&self) -> &str {
match self {
Self::Cosmos => COSMOS_HD_PATH,
Self::Evmos => EVMOS_HD_PATH,
}
}

pub fn chain_id(&self, prefix: &str, use_random_id: bool) -> ChainId {
match self {
Self::Cosmos => {
if use_random_id {
ChainId::from_string(&format!("ibc-{}-{:x}", prefix, random_u32()))
} else {
ChainId::from_string(&format!("ibc-{}", prefix))
}
}
Self::Evmos => ChainId::from_string(&format!("evmos_9000-{}", prefix)),
}
}

// Extra arguments required to run `<chain binary> start`
pub fn extra_start_args(&self) -> Vec<String> {
let mut res = vec![];
let json_rpc_port = random_unused_tcp_port();
match self {
Self::Cosmos => {}
Self::Evmos => {
res.push("--json-rpc.address".to_owned());
res.push(format!("localhost:{}", json_rpc_port));
}
}
res
}

pub fn address_type(&self) -> AddressType {
match self {
Self::Cosmos => AddressType::default(),
Self::Evmos => AddressType::Ethermint {
pk_type: "/ethermint.crypto.v1.ethsecp256k1.PubKey".to_string(),
},
}
}
}

impl FromStr for ChainType {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
name if name.contains("gaiad") => Ok(ChainType::Cosmos),
name if name.contains("simd") => Ok(ChainType::Cosmos),
name if name.contains("wasmd") => Ok(ChainType::Cosmos),
name if name.contains("icad") => Ok(ChainType::Cosmos),
name if name.contains("evmosd") => Ok(ChainType::Evmos),
_ => Ok(ChainType::Cosmos),
}
}
}
15 changes: 11 additions & 4 deletions tools/test-framework/src/chain/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use crate::types::wallet::{Wallet, WalletAddress, WalletId};
use crate::util::file::pipe_to_file;
use crate::util::retry::assert_eventually_succeed;

use super::chain_type::ChainType;

pub mod interchain;
pub mod query_txs;
pub mod transfer;
Expand All @@ -49,8 +51,6 @@ pub mod transfer;
*/
const WAIT_WALLET_AMOUNT_ATTEMPTS: u16 = 90;

const COSMOS_HD_PATH: &str = "m/44'/118'/0'/0/0";

/**
A driver for interacting with a chain full nodes through command line.
Expand All @@ -68,6 +68,7 @@ const COSMOS_HD_PATH: &str = "m/44'/118'/0'/0/0";

#[derive(Debug, Clone)]
pub struct ChainDriver {
pub chain_type: ChainType,
/**
The filesystem path to the Gaia CLI. Defaults to `gaiad`.
*/
Expand Down Expand Up @@ -119,6 +120,7 @@ impl ExportEnv for ChainDriver {
impl ChainDriver {
/// Create a new [`ChainDriver`]
pub fn create(
chain_type: ChainType,
command_path: String,
chain_id: ChainId,
home_path: String,
Expand All @@ -133,9 +135,11 @@ impl ChainDriver {
chain_id.clone(),
format!("http://localhost:{}", rpc_port),
format!("http://localhost:{}", grpc_port),
chain_type.address_type(),
)?;

Ok(Self {
chain_type,
command_path,
chain_id,
home_path,
Expand Down Expand Up @@ -303,7 +307,7 @@ impl ChainDriver {
let seed_path = format!("{}-seed.json", wallet_id);
self.write_file(&seed_path, &seed_content)?;

let hd_path = HDPath::from_str(COSMOS_HD_PATH)
let hd_path = HDPath::from_str(self.chain_type.hd_path())
.map_err(|e| eyre!("failed to create HDPath: {:?}", e))?;

let key_file: KeyFile = json::from_str(&seed_content).map_err(handle_generic_error)?;
Expand Down Expand Up @@ -418,7 +422,10 @@ impl ChainDriver {
&self.rpc_listen_address(),
];

let args: Vec<&str> = base_args.to_vec();
let mut args: Vec<&str> = base_args.to_vec();

let extra_start_args = self.chain_type.extra_start_args();
args.append(&mut extra_start_args.iter().map(|s| s.as_ref()).collect());

let mut child = Command::new(&self.command_path)
.args(&args)
Expand Down
1 change: 1 addition & 0 deletions tools/test-framework/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

pub mod builder;
pub mod chain_type;
pub mod config;
pub mod driver;
pub mod exec;
Expand Down
6 changes: 3 additions & 3 deletions tools/test-framework/src/framework/binary/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ where
fn run(&self, config: &TestConfig, builder: &ChainBuilder) -> Result<(), Error> {
let node_a = bootstrap_single_node(
builder,
"0",
"1",
config.bootstrap_with_random_ids,
|config| self.test.get_overrides().modify_node_config(config),
|genesis| self.test.get_overrides().modify_genesis_file(genesis),
)?;

let node_b = bootstrap_single_node(
builder,
"1",
"2",
config.bootstrap_with_random_ids,
|config| self.test.get_overrides().modify_node_config(config),
|genesis| self.test.get_overrides().modify_genesis_file(genesis),
Expand All @@ -144,7 +144,7 @@ where
fn run(&self, config: &TestConfig, builder: &ChainBuilder) -> Result<(), Error> {
let node = bootstrap_single_node(
builder,
"alpha",
"1",
config.bootstrap_with_random_ids,
|config| self.test.get_overrides().modify_node_config(config),
|genesis| self.test.get_overrides().modify_genesis_file(genesis),
Expand Down
2 changes: 1 addition & 1 deletion tools/test-framework/src/framework/nary/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
for i in 0..SIZE {
let node = bootstrap_single_node(
builder,
&format!("{}", i),
&format!("{}", i + 1),
config.bootstrap_with_random_ids,
|config| self.test.get_overrides().modify_node_config(config),
|genesis| self.test.get_overrides().modify_genesis_file(genesis),
Expand Down
5 changes: 2 additions & 3 deletions tools/test-framework/src/relayer/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ibc_relayer::chain::cosmos::types::config::TxConfig;
use ibc_relayer::chain::cosmos::types::gas::GasConfig;
use ibc_relayer::chain::cosmos::types::tx::{TxStatus, TxSyncResult};
use ibc_relayer::chain::cosmos::wait::wait_for_block_commits;
use ibc_relayer::config::GasPrice;
use ibc_relayer::config::{AddressType, GasPrice};
use ibc_relayer::keyring::KeyEntry;
use tendermint_rpc::{HttpClient, Url};

Expand Down Expand Up @@ -48,6 +48,7 @@ pub fn new_tx_config_for_test(
chain_id: ChainId,
raw_rpc_address: String,
raw_grpc_address: String,
address_type: AddressType,
) -> Result<TxConfig, Error> {
let rpc_address = Url::from_str(&raw_rpc_address).map_err(handle_generic_error)?;

Expand All @@ -59,8 +60,6 @@ pub fn new_tx_config_for_test(

let rpc_timeout = Duration::from_secs(30);

let address_type = Default::default();

let extension_options = Default::default();

Ok(TxConfig {
Expand Down
8 changes: 6 additions & 2 deletions tools/test-framework/src/types/single/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ibc_relayer::keyring::Store;
use std::sync::{Arc, RwLock};
use tendermint_rpc::Url;

use crate::chain::chain_type::ChainType as TestedChainType;
use crate::chain::driver::ChainDriver;
use crate::ibc::denom::Denom;
use crate::types::env::{prefix_writer, EnvWriter, ExportEnv};
Expand Down Expand Up @@ -118,7 +119,10 @@ impl FullNode {
Generate the relayer's chain config based on the configuration of
the full node.
*/
pub fn generate_chain_config(&self) -> Result<config::ChainConfig, Error> {
pub fn generate_chain_config(
&self,
chain_type: &TestedChainType,
) -> Result<config::ChainConfig, Error> {
Ok(config::ChainConfig {
id: self.chain_driver.chain_id.clone(),
r#type: ChainType::CosmosSdk,
Expand Down Expand Up @@ -148,7 +152,7 @@ impl FullNode {
trust_threshold: Default::default(),
gas_price: config::GasPrice::new(0.001, "stake".to_string()),
packet_filter: Default::default(),
address_type: Default::default(),
address_type: chain_type.address_type(),
memo_prefix: Default::default(),
proof_specs: Default::default(),
extension_options: Default::default(),
Expand Down

0 comments on commit d474c24

Please sign in to comment.