From cfb707eaee2c3cd8e04378ba3eee033ec73fd4f9 Mon Sep 17 00:00:00 2001 From: Vitalii Kryvenko Date: Wed, 25 Sep 2024 13:22:46 +0300 Subject: [PATCH] refactor(ibc-testkit): use `bon` instead of `typed-builder` (#1326) * refactor(ibc-testkit): use `bon` instead of `typed-builder` * Bump `bon` requirement * Bump `bon` requirement * Fix some places that I missed to update * Update `LightClientBuilder` to `dummy_light_client()` * Remove dummy line comments from function args * default tags at function args * revert builder pattern * nits * pass required args in start_fn * fix docs build * use default call instead of build --------- Co-authored-by: Ranadeep Biswas Co-authored-by: Rano | Ranadeep --- ibc-testkit/Cargo.toml | 2 +- ibc-testkit/src/context.rs | 24 +- .../src/fixtures/applications/transfer.rs | 75 +++--- .../src/fixtures/clients/tendermint.rs | 4 +- .../src/fixtures/core/channel/packet.rs | 57 ++--- .../src/fixtures/core/connection/mod.rs | 24 -- ibc-testkit/src/fixtures/core/context.rs | 130 +++++------ ibc-testkit/src/hosts/mock.rs | 4 +- ibc-testkit/src/hosts/tendermint.rs | 6 +- ibc-testkit/src/relayer/utils.rs | 6 +- ibc-testkit/src/testapp/ibc/core/types.rs | 47 ++-- ibc-testkit/src/utils/mod.rs | 2 +- .../tests/core/ics02_client/create_client.rs | 14 +- .../tests/core/ics02_client/recover_client.rs | 10 +- .../tests/core/ics02_client/update_client.rs | 213 ++++++++---------- .../core/ics03_connection/conn_open_ack.rs | 6 +- .../core/ics03_connection/conn_open_try.rs | 6 +- tests-integration/tests/core/router.rs | 39 ++-- 18 files changed, 272 insertions(+), 397 deletions(-) diff --git a/ibc-testkit/Cargo.toml b/ibc-testkit/Cargo.toml index a9297d1f7..a44ccc00e 100644 --- a/ibc-testkit/Cargo.toml +++ b/ibc-testkit/Cargo.toml @@ -17,6 +17,7 @@ description = """ [dependencies] # external dependencies +bon = { version = "2.3.0" } borsh = { workspace = true, optional = true } derive_more = { workspace = true } displaydoc = { workspace = true } @@ -25,7 +26,6 @@ schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde-json = { workspace = true, optional = true } subtle-encoding = { workspace = true } -typed-builder = { version = "0.19.1" } # ibc dependencies ibc = { workspace = true, features = [ "std" ] } diff --git a/ibc-testkit/src/context.rs b/ibc-testkit/src/context.rs index 92986d14f..7ee1eb69a 100644 --- a/ibc-testkit/src/context.rs +++ b/ibc-testkit/src/context.rs @@ -23,7 +23,7 @@ use ibc::primitives::prelude::*; use ibc::primitives::Timestamp; use super::testapp::ibc::core::types::{LightClientState, MockIbcStore}; -use crate::fixtures::core::context::TestContextConfig; +use crate::fixtures::core::context::dummy_store_generic_test_context; use crate::hosts::{HostClientState, MockHost, TendermintHost, TestBlock, TestHeader, TestHost}; use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState}; use crate::testapp::ibc::core::router::MockRouter; @@ -70,7 +70,7 @@ where HostClientState: ClientStateValidation>, { fn default() -> Self { - TestContextConfig::builder().build() + dummy_store_generic_test_context().call() } } @@ -529,35 +529,35 @@ mod tests { let tests: Vec> = vec![ Test { name: "Empty history, small pruning window".to_string(), - ctx: TestContextConfig::builder() + ctx: dummy_store_generic_test_context() .latest_height(Height::new(cv, 1).expect("Never fails")) - .build(), + .call(), }, Test { name: "Large pruning window".to_string(), - ctx: TestContextConfig::builder() + ctx: dummy_store_generic_test_context() .latest_height(Height::new(cv, 2).expect("Never fails")) - .build(), + .call(), }, Test { name: "Small pruning window".to_string(), - ctx: TestContextConfig::builder() + ctx: dummy_store_generic_test_context() .latest_height(Height::new(cv, 30).expect("Never fails")) - .build(), + .call(), }, Test { name: "Small pruning window, small starting height".to_string(), - ctx: TestContextConfig::builder() + ctx: dummy_store_generic_test_context() .latest_height(Height::new(cv, 2).expect("Never fails")) - .build(), + .call(), }, // This is disabled, as now we generate all the blocks till latest_height // Generating 2000 Tendermint blocks is slow. // Test { // name: "Large pruning window, large starting height".to_string(), - // ctx: TestContextConfig::builder() + // ctx: dummy_store_generic_test_context() // .latest_height(Height::new(cv, 2000).expect("Never fails")) - // .build(), + // .call(), // }, ]; diff --git a/ibc-testkit/src/fixtures/applications/transfer.rs b/ibc-testkit/src/fixtures/applications/transfer.rs index 3a0bb44aa..d9bc19099 100644 --- a/ibc-testkit/src/fixtures/applications/transfer.rs +++ b/ibc-testkit/src/fixtures/applications/transfer.rs @@ -1,3 +1,4 @@ +use bon::builder; use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use ibc::apps::transfer::types::packet::PacketData; use ibc::apps::transfer::types::{Memo, PrefixedCoin}; @@ -5,34 +6,24 @@ use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence}; use ibc::core::primitives::Signer; -use typed_builder::TypedBuilder; use crate::fixtures::core::signer::dummy_account_id; -/// Configuration of the `MsgTransfer` message for building dummy messages. -#[derive(TypedBuilder, Debug)] -#[builder(build_method(into = MsgTransfer))] -pub struct MsgTransferConfig { - #[builder(default = PortId::transfer())] - pub port_id_on_a: PortId, - #[builder(default = ChannelId::zero())] - pub chan_id_on_a: ChannelId, - pub packet_data: PacketData, - #[builder(default = TimeoutHeight::Never)] - pub timeout_height_on_b: TimeoutHeight, - #[builder(default = TimeoutTimestamp::Never)] - pub timeout_timestamp_on_b: TimeoutTimestamp, -} - -impl From for MsgTransfer { - fn from(config: MsgTransferConfig) -> Self { - Self { - port_id_on_a: config.port_id_on_a, - chan_id_on_a: config.chan_id_on_a, - packet_data: config.packet_data, - timeout_height_on_b: config.timeout_height_on_b, - timeout_timestamp_on_b: config.timeout_timestamp_on_b, - } +/// Returns a dummy [`MsgTransfer`], for testing purposes only! +#[builder] +pub fn dummy_msg_transfer( + #[builder(start_fn)] packet_data: PacketData, + #[builder(default = PortId::transfer())] port_id_on_a: PortId, + #[builder(default = ChannelId::zero())] chan_id_on_a: ChannelId, + #[builder(default = TimeoutHeight::Never)] timeout_height_on_b: TimeoutHeight, + #[builder(default = TimeoutTimestamp::Never)] timeout_timestamp_on_b: TimeoutTimestamp, +) -> MsgTransfer { + MsgTransfer { + port_id_on_a, + chan_id_on_a, + packet_data, + timeout_height_on_b, + timeout_timestamp_on_b, } } @@ -52,26 +43,18 @@ pub fn extract_transfer_packet(msg: &MsgTransfer, sequence: Sequence) -> Packet } } -/// Configuration of the `PacketData` type for building dummy packets. -#[derive(TypedBuilder, Debug)] -#[builder(build_method(into = PacketData))] -pub struct PacketDataConfig { - pub token: PrefixedCoin, - #[builder(default = dummy_account_id())] - pub sender: Signer, - #[builder(default = dummy_account_id())] - pub receiver: Signer, - #[builder(default = "".into())] - pub memo: Memo, -} - -impl From for PacketData { - fn from(config: PacketDataConfig) -> Self { - Self { - token: config.token, - sender: config.sender, - receiver: config.receiver, - memo: config.memo, - } +/// Returns a dummy [`PacketData`], for testing purposes only! +#[builder] +pub fn dummy_packet_data( + #[builder(start_fn)] token: PrefixedCoin, + #[builder(default = dummy_account_id())] sender: Signer, + #[builder(default = dummy_account_id())] receiver: Signer, + #[builder(default = "".into())] memo: Memo, +) -> PacketData { + PacketData { + token, + sender, + receiver, + memo, } } diff --git a/ibc-testkit/src/fixtures/clients/tendermint.rs b/ibc-testkit/src/fixtures/clients/tendermint.rs index 3653c39ef..ff581ad8c 100644 --- a/ibc-testkit/src/fixtures/clients/tendermint.rs +++ b/ibc-testkit/src/fixtures/clients/tendermint.rs @@ -2,6 +2,7 @@ use core::str::FromStr; use core::time::Duration; use basecoin_store::avl::get_proof_spec as basecoin_proof_spec; +use bon::Builder; use ibc::clients::tendermint::client_state::ClientState as TmClientState; use ibc::clients::tendermint::types::error::TendermintClientError; use ibc::clients::tendermint::types::proto::v1::{ClientState as RawTmClientState, Fraction}; @@ -17,7 +18,6 @@ use ibc::core::host::types::error::DecodingError; use ibc::core::host::types::identifiers::ChainId; use ibc::core::primitives::prelude::*; use tendermint::block::Header as TmHeader; -use typed_builder::TypedBuilder; /// Returns a dummy tendermint `ClientState` by given `frozen_height`, for testing purposes only! pub fn dummy_tm_client_state_from_raw( @@ -69,7 +69,7 @@ pub fn dummy_raw_tm_client_state(frozen_height: RawHeight) -> RawTmClientState { } } -#[derive(TypedBuilder, Debug)] +#[derive(Debug, Builder)] pub struct ClientStateConfig { #[builder(default = TrustThreshold::ONE_THIRD)] pub trust_level: TrustThreshold, diff --git a/ibc-testkit/src/fixtures/core/channel/packet.rs b/ibc-testkit/src/fixtures/core/channel/packet.rs index 6d8503199..b44260da2 100644 --- a/ibc-testkit/src/fixtures/core/channel/packet.rs +++ b/ibc-testkit/src/fixtures/core/channel/packet.rs @@ -1,45 +1,32 @@ +use bon::builder; use ibc::core::channel::types::packet::Packet; use ibc::core::channel::types::proto::v1::Packet as RawPacket; use ibc::core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp}; use ibc::core::client::types::proto::v1::Height as RawHeight; use ibc::core::host::types::identifiers::{ChannelId, PortId, Sequence}; use ibc::core::primitives::prelude::*; -use typed_builder::TypedBuilder; -/// Configuration of the `PacketData` type for building dummy packets. -#[derive(TypedBuilder, Debug)] -#[builder(build_method(into = Packet))] -pub struct PacketConfig { - #[builder(default = Sequence::from(0))] - pub seq_on_a: Sequence, - #[builder(default = PortId::transfer())] - pub port_id_on_a: PortId, - #[builder(default = ChannelId::zero())] - pub chan_id_on_a: ChannelId, - #[builder(default = PortId::transfer())] - pub port_id_on_b: PortId, - #[builder(default = ChannelId::zero())] - pub chan_id_on_b: ChannelId, - #[builder(default)] - pub data: Vec, - #[builder(default = TimeoutHeight::Never)] - pub timeout_height_on_b: TimeoutHeight, - #[builder(default = TimeoutTimestamp::Never)] - pub timeout_timestamp_on_b: TimeoutTimestamp, -} - -impl From for Packet { - fn from(config: PacketConfig) -> Self { - Self { - seq_on_a: config.seq_on_a, - port_id_on_a: config.port_id_on_a, - chan_id_on_a: config.chan_id_on_a, - port_id_on_b: config.port_id_on_b, - chan_id_on_b: config.chan_id_on_b, - data: config.data, - timeout_height_on_b: config.timeout_height_on_b, - timeout_timestamp_on_b: config.timeout_timestamp_on_b, - } +/// Returns a dummy [`Packet`], for testing purposes only! +#[builder] +pub fn dummy_packet( + #[builder(default = Sequence::from(0))] seq_on_a: Sequence, + #[builder(default = PortId::transfer())] port_id_on_a: PortId, + #[builder(default = ChannelId::zero())] chan_id_on_a: ChannelId, + #[builder(default = PortId::transfer())] port_id_on_b: PortId, + #[builder(default = ChannelId::zero())] chan_id_on_b: ChannelId, + #[builder(default)] data: Vec, + #[builder(default = TimeoutHeight::Never)] timeout_height_on_b: TimeoutHeight, + #[builder(default = TimeoutTimestamp::Never)] timeout_timestamp_on_b: TimeoutTimestamp, +) -> Packet { + Packet { + seq_on_a, + port_id_on_a, + chan_id_on_a, + port_id_on_b, + chan_id_on_b, + data, + timeout_height_on_b, + timeout_timestamp_on_b, } } diff --git a/ibc-testkit/src/fixtures/core/connection/mod.rs b/ibc-testkit/src/fixtures/core/connection/mod.rs index 3460a3f10..714c18a2a 100644 --- a/ibc-testkit/src/fixtures/core/connection/mod.rs +++ b/ibc-testkit/src/fixtures/core/connection/mod.rs @@ -7,36 +7,12 @@ use ibc::core::commitment_types::proto::v1::MerklePrefix; use ibc::core::connection::types::proto::v1::Counterparty as RawCounterparty; use ibc::core::host::types::identifiers::ConnectionId; use ibc::core::primitives::prelude::*; -use typed_builder::TypedBuilder; pub use self::conn_open_ack::*; pub use self::conn_open_confirm::*; pub use self::conn_open_init::*; pub use self::conn_open_try::*; -#[derive(TypedBuilder, Debug)] -#[builder(build_method(into = RawCounterparty))] -pub struct CounterpartyConfig { - #[builder(default = "07-tendermint-0")] - client_id: &'static str, - #[builder(default = "connection-0")] - connection_id: &'static str, - #[builder(default = Some(MerklePrefix { - key_prefix: b"ibc".to_vec() - }))] - prefix: Option, -} - -impl From for RawCounterparty { - fn from(config: CounterpartyConfig) -> Self { - Self { - client_id: config.client_id.to_string(), - connection_id: config.connection_id.to_string(), - prefix: config.prefix, - } - } -} - pub fn dummy_raw_counterparty_conn(conn_id: Option) -> RawCounterparty { let connection_id = match conn_id { Some(id) => ConnectionId::new(id).to_string(), diff --git a/ibc-testkit/src/fixtures/core/context.rs b/ibc-testkit/src/fixtures/core/context.rs index 99304f0e0..59631b0c3 100644 --- a/ibc-testkit/src/fixtures/core/context.rs +++ b/ibc-testkit/src/fixtures/core/context.rs @@ -2,11 +2,11 @@ use alloc::fmt::Debug; use core::time::Duration; use basecoin_store::context::ProvableStore; +use bon::builder; use ibc::core::client::context::client_state::ClientStateValidation; use ibc::core::client::types::Height; use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; -use typed_builder::TypedBuilder; use crate::context::StoreGenericTestContext; use crate::hosts::{HostClientState, TestBlock, TestHost}; @@ -14,87 +14,65 @@ use crate::testapp::ibc::core::router::MockRouter; use crate::testapp::ibc::core::types::{MockIbcStore, DEFAULT_BLOCK_TIME_SECS}; use crate::utils::year_2023; -/// Configuration of the [`StoreGenericTestContext`] type for generating dummy contexts. -#[derive(Debug, TypedBuilder)] -#[builder(build_method(into))] -pub struct TestContextConfig -where - H: TestHost, -{ - #[builder(default)] - host: H, - - #[builder(default = Duration::from_secs(DEFAULT_BLOCK_TIME_SECS))] - block_time: Duration, - - #[builder(default = year_2023())] - latest_timestamp: Timestamp, - - #[builder(default)] - block_params_history: Vec, - - #[builder(default = Height::new(0, 5).expect("Never fails"))] - latest_height: Height, -} - -impl From> for StoreGenericTestContext +/// Returns a dummy [`StoreGenericTestContext`], for testing purposes only! +#[builder] +pub fn dummy_store_generic_test_context( + #[builder(default)] host: H, + #[builder(default = Duration::from_secs(DEFAULT_BLOCK_TIME_SECS))] block_time: Duration, + #[builder(default = year_2023())] latest_timestamp: Timestamp, + #[builder(default)] block_params_history: Vec, + #[builder(default = Height::new(0, 5).expect("Never fails"))] latest_height: Height, +) -> StoreGenericTestContext where S: ProvableStore + Debug + Default, H: TestHost, HostClientState: ClientStateValidation>, { - fn from(params: TestContextConfig) -> Self { - assert_ne!( - params.latest_height.revision_height(), - 0, - "The chain must have a non-zero revision_height" - ); - - // timestamp at height 1 - let genesis_timestamp = (params.latest_timestamp - - (params.block_time - * u32::try_from(params.latest_height.revision_height() - 1).expect("no overflow"))) - .expect("no underflow"); - - let mut context = Self { - multi_store: Default::default(), - host: params.host, - ibc_store: MockIbcStore::new( - params.latest_height.revision_number(), - Default::default(), - ), - ibc_router: MockRouter::new_with_transfer(), - }; - - // store is at height 0; no block - - context.advance_genesis_height(genesis_timestamp, &Default::default()); - - // store is at height 1; one block - - context = context.advance_block_up_to_height( - params - .latest_height - .sub(params.block_params_history.len() as u64) - .expect("no error"), - ); - - for block_params in params.block_params_history { - context.advance_block_height_with_params(params.block_time, &block_params); - } + assert_ne!( + latest_height.revision_height(), + 0, + "The chain must have a non-zero revision_height" + ); + + // timestamp at height 1 + let genesis_timestamp = (latest_timestamp + - (block_time * u32::try_from(latest_height.revision_height() - 1).expect("no overflow"))) + .expect("no underflow"); + + let mut context = StoreGenericTestContext { + multi_store: Default::default(), + host, + ibc_store: MockIbcStore::new(latest_height.revision_number(), Default::default()), + ibc_router: MockRouter::new_with_transfer(), + }; + + // store is at height 0; no block + + context.advance_genesis_height(genesis_timestamp, &Default::default()); + + // store is at height 1; one block + + context = context.advance_block_up_to_height( + latest_height + .sub(block_params_history.len() as u64) + .expect("no error"), + ); + + for block_params in block_params_history { + context.advance_block_height_with_params(block_time, &block_params); + } - assert_eq!( - context.host.latest_block().height(), - params.latest_height, - "The latest height in the host must match the latest height in the context" - ); + assert_eq!( + context.host.latest_block().height(), + latest_height, + "The latest height in the host must match the latest height in the context" + ); - assert_eq!( - context.host.latest_block().timestamp(), - params.latest_timestamp, - "The latest timestamp in the host must match the latest timestamp in the context" - ); + assert_eq!( + context.host.latest_block().timestamp(), + latest_timestamp, + "The latest timestamp in the host must match the latest timestamp in the context" + ); - context - } + context } diff --git a/ibc-testkit/src/hosts/mock.rs b/ibc-testkit/src/hosts/mock.rs index 266f69f53..04af7a282 100644 --- a/ibc-testkit/src/hosts/mock.rs +++ b/ibc-testkit/src/hosts/mock.rs @@ -1,16 +1,16 @@ use alloc::vec::Vec; +use bon::Builder; use ibc::core::client::types::Height; use ibc::core::host::types::identifiers::ChainId; use ibc::core::primitives::Timestamp; -use typed_builder::TypedBuilder; use super::{TestBlock, TestHeader, TestHost}; use crate::testapp::ibc::clients::mock::client_state::MockClientState; use crate::testapp::ibc::clients::mock::consensus_state::MockConsensusState; use crate::testapp::ibc::clients::mock::header::MockHeader; -#[derive(TypedBuilder, Debug)] +#[derive(Debug, Builder)] pub struct MockHost { /// Unique identifier for the chain. #[builder(default = ChainId::new("mock-0").expect("Never fails"))] diff --git a/ibc-testkit/src/hosts/tendermint.rs b/ibc-testkit/src/hosts/tendermint.rs index 360ca0b19..10ea12a16 100644 --- a/ibc-testkit/src/hosts/tendermint.rs +++ b/ibc-testkit/src/hosts/tendermint.rs @@ -1,5 +1,6 @@ use core::str::FromStr; +use bon::Builder; use ibc::clients::tendermint::client_state::ClientState; use ibc::clients::tendermint::consensus_state::ConsensusState; use ibc::clients::tendermint::types::proto::v1::Header as RawHeader; @@ -17,13 +18,12 @@ use tendermint_testgen::{ Generator, Header as TestgenHeader, LightBlock as TestgenLightBlock, Validator as TestgenValidator, }; -use typed_builder::TypedBuilder; use crate::fixtures::clients::tendermint::ClientStateConfig; use crate::hosts::{TestBlock, TestHeader, TestHost}; /// A host that produces Tendermint blocks and interfaces with Tendermint light clients. -#[derive(TypedBuilder, Debug)] +#[derive(Debug, Builder)] pub struct TendermintHost { /// Unique identifier for the chain. #[builder(default = ChainId::new("mock-0").expect("Never fails"))] @@ -128,7 +128,7 @@ impl TestBlock for TmLightBlock { } } -#[derive(Debug, TypedBuilder)] +#[derive(Debug, Builder)] pub struct BlockParams { pub validators: Vec, pub next_validators: Vec, diff --git a/ibc-testkit/src/relayer/utils.rs b/ibc-testkit/src/relayer/utils.rs index cd3c5f0a3..8fbbd56aa 100644 --- a/ibc-testkit/src/relayer/utils.rs +++ b/ibc-testkit/src/relayer/utils.rs @@ -34,7 +34,7 @@ use ibc_query::core::context::ProvableContext; use crate::context::TestContext; use crate::hosts::{HostClientState, TestBlock, TestHost}; -use crate::testapp::ibc::core::types::{DefaultIbcStore, LightClientBuilder, LightClientState}; +use crate::testapp::ibc::core::types::{dummy_light_client, DefaultIbcStore}; /// Implements IBC relayer functions for a pair of [`TestHost`] implementations: `A` and `B`. /// Note that, all the implementations are in one direction: from `A` to `B`. @@ -64,9 +64,7 @@ where ctx_b: &TestContext, signer: Signer, ) -> ClientId { - let light_client_of_b = LightClientBuilder::init() - .context(ctx_b) - .build::>(); + let light_client_of_b = dummy_light_client(ctx_b).call(); let msg_for_a = MsgEnvelope::Client(ClientMsg::CreateClient(MsgCreateClient { client_state: light_client_of_b.client_state.into(), diff --git a/ibc-testkit/src/testapp/ibc/core/types.rs b/ibc-testkit/src/testapp/ibc/core/types.rs index 9389d642c..a658cad91 100644 --- a/ibc-testkit/src/testapp/ibc/core/types.rs +++ b/ibc-testkit/src/testapp/ibc/core/types.rs @@ -6,6 +6,7 @@ use core::fmt::Debug; use basecoin_store::context::{ProvableStore, Store}; use basecoin_store::impls::SharedStore; use basecoin_store::types::{BinStore, JsonStore, ProtobufStore, TypedSet, TypedStore}; +use bon::builder; use ibc::core::channel::types::channel::ChannelEnd; use ibc::core::channel::types::commitment::{AcknowledgementCommitment, PacketCommitment}; use ibc::core::client::context::client_state::ClientStateValidation; @@ -27,10 +28,9 @@ use ibc_proto::ibc::core::client::v1::Height as RawHeight; use ibc_proto::ibc::core::connection::v1::ConnectionEnd as RawConnectionEnd; use ibc_proto::ics23::CommitmentProof; use parking_lot::Mutex; -use typed_builder::TypedBuilder; use crate::context::{MockStore, TestContext}; -use crate::fixtures::core::context::TestContextConfig; +use crate::fixtures::core::context::dummy_store_generic_test_context; use crate::hosts::{HostClientState, TestBlock, TestHeader, TestHost}; use crate::testapp::ibc::clients::mock::header::MockHeader; use crate::testapp::ibc::clients::{AnyClientState, AnyConsensusState}; @@ -215,7 +215,7 @@ mod tests { use ibc::core::router::types::module::{ModuleExtras, ModuleId}; use super::*; - use crate::fixtures::core::channel::PacketConfig; + use crate::fixtures::core::channel::dummy_packet; use crate::fixtures::core::signer::dummy_bech32_account; use crate::testapp::ibc::core::router::MockRouter; @@ -433,7 +433,7 @@ mod tests { let module_id = ModuleId::new(module_id.to_string()); let m = router.get_route_mut(&module_id).expect("Never fails"); - let packet = PacketConfig::builder().build(); + let packet = dummy_packet().call(); let result = m.on_recv_packet_execute(&packet, &dummy_bech32_account().into()); (module_id, result) @@ -459,7 +459,7 @@ where { fn default() -> Self { let context = TestContext::::default(); - LightClientBuilder::init().context(&context).build() + dummy_light_client(&context).call() } } @@ -469,39 +469,22 @@ where HostClientState: ClientStateValidation, { pub fn with_latest_height(height: Height) -> Self { - let context = TestContextConfig::builder() + let context: TestContext<_> = dummy_store_generic_test_context() .latest_height(height) - .build::>(); - LightClientBuilder::init().context(&context).build() + .call(); + dummy_light_client(&context).call() } } -#[derive(TypedBuilder)] -#[builder(builder_method(name = init), build_method(into))] -pub struct LightClientBuilder<'a, H> +#[builder] +pub fn dummy_light_client( + #[builder(start_fn)] context: &TestContext, + #[builder(default, into)] consensus_heights: Vec, + #[builder(default)] params: H::LightClientParams, +) -> LightClientState where H: TestHost, HostClientState: ClientStateValidation, { - context: &'a TestContext, - #[builder(default, setter(into))] - consensus_heights: Vec, - #[builder(default)] - params: H::LightClientParams, -} - -impl<'a, H> From> for LightClientState -where - H: TestHost, - HostClientState: ClientStateValidation, -{ - fn from(builder: LightClientBuilder<'a, H>) -> Self { - let LightClientBuilder { - context, - consensus_heights, - params, - } = builder; - - context.generate_light_client(consensus_heights, ¶ms) - } + context.generate_light_client(consensus_heights, ¶ms) } diff --git a/ibc-testkit/src/utils/mod.rs b/ibc-testkit/src/utils/mod.rs index 7f1a957c6..813145486 100644 --- a/ibc-testkit/src/utils/mod.rs +++ b/ibc-testkit/src/utils/mod.rs @@ -9,7 +9,7 @@ use serde::{de::DeserializeOwned, Serialize}; /// If two [`StoreGenericTestContext`](crate::context::StoreGenericTestContext) /// are initialized using [`Timestamp::now()`], the second one will have a greater timestamp than the first one. /// So, the latest header of the second context cannot be submitted to first one. -/// We can still set a custom timestamp via [`TestContextConfig`](crate::fixtures::core::context::TestContextConfig). +/// We can still set a custom timestamp via [`dummy_store_generic_test_context`](crate::fixtures::core::context::dummy_store_generic_test_context). pub fn year_2023() -> Timestamp { // Sun Jan 01 2023 00:00:00 GMT+0000 Timestamp::from_unix_timestamp(1_672_531_200, 0).expect("should be a valid time") diff --git a/tests-integration/tests/core/ics02_client/create_client.rs b/tests-integration/tests/core/ics02_client/create_client.rs index 852cdd273..6b3d7c5b2 100644 --- a/tests-integration/tests/core/ics02_client/create_client.rs +++ b/tests-integration/tests/core/ics02_client/create_client.rs @@ -21,7 +21,7 @@ use ibc_testkit::fixtures::clients::tendermint::dummy_tm_client_state_from_heade use ibc_testkit::fixtures::clients::tendermint::{ dummy_expired_tendermint_header, dummy_valid_tendermint_header, }; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::testapp::ibc::clients::mock::client_state::{ @@ -31,7 +31,7 @@ use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusStat use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; use ibc_testkit::testapp::ibc::clients::{AnyClientState, AnyConsensusState}; use ibc_testkit::testapp::ibc::core::router::MockRouter; -use ibc_testkit::testapp::ibc::core::types::{DefaultIbcStore, LightClientBuilder}; +use ibc_testkit::testapp::ibc::core::types::{dummy_light_client, DefaultIbcStore}; use ibc_testkit::utils::year_2023; use test_log::test; @@ -229,14 +229,12 @@ fn test_tm_create_client_proof_verification_ok() { let client_id = ClientId::new("07-tendermint", 0).expect("no error"); let client_height = Height::new(0, 10).expect("no error"); - let ctx_tm = TestContextConfig::builder() + let ctx_tm: TendermintContext = dummy_store_generic_test_context() .latest_height(client_height) - .build::(); + .call(); - let ctx_mk = MockContext::default().with_light_client( - &client_id, - LightClientBuilder::init().context(&ctx_tm).build(), - ); + let ctx_mk = + MockContext::default().with_light_client(&client_id, dummy_light_client(&ctx_tm).call()); let client_validation_ctx_mk = ctx_mk.ibc_store().get_client_validation_context(); diff --git a/tests-integration/tests/core/ics02_client/recover_client.rs b/tests-integration/tests/core/ics02_client/recover_client.rs index 0b6dffd6c..c42b603c6 100644 --- a/tests-integration/tests/core/ics02_client/recover_client.rs +++ b/tests-integration/tests/core/ics02_client/recover_client.rs @@ -12,7 +12,7 @@ use ibc::core::host::ValidationContext; use ibc::core::primitives::Signer; use ibc_primitives::Timestamp; use ibc_testkit::context::{MockContext, TendermintContext}; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::hosts::{TestBlock, TestHost}; use ibc_testkit::testapp::ibc::clients::mock::client_state::{ @@ -45,15 +45,15 @@ fn setup_client_recovery_fixture( ) -> Fixture { let latest_timestamp = Timestamp::now(); - let mut ctx_a: TendermintContext = TestContextConfig::builder() + let mut ctx_a: TendermintContext = dummy_store_generic_test_context() .latest_timestamp(latest_timestamp) - .build(); + .call(); // create a ctx_b - let ctx_b: MockContext = TestContextConfig::builder() + let ctx_b: MockContext = dummy_store_generic_test_context() .latest_height(substitute_height) .latest_timestamp(latest_timestamp) - .build(); + .call(); let signer = dummy_account_id(); diff --git a/tests-integration/tests/core/ics02_client/update_client.rs b/tests-integration/tests/core/ics02_client/update_client.rs index 6afa73cb9..89525bff5 100644 --- a/tests-integration/tests/core/ics02_client/update_client.rs +++ b/tests-integration/tests/core/ics02_client/update_client.rs @@ -26,7 +26,7 @@ use ibc::primitives::proto::Any; use ibc::primitives::ToVec; use ibc_testkit::context::{MockContext, TendermintContext, TestContext}; use ibc_testkit::fixtures::clients::tendermint::ClientStateConfig; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::hosts::tendermint::BlockParams; use ibc_testkit::hosts::{ @@ -40,7 +40,7 @@ use ibc_testkit::testapp::ibc::clients::mock::misbehaviour::Misbehaviour as Mock use ibc_testkit::testapp::ibc::clients::AnyConsensusState; use ibc_testkit::testapp::ibc::core::router::MockRouter; use ibc_testkit::testapp::ibc::core::types::{ - DefaultIbcStore, LightClientBuilder, LightClientState, MockIbcStore, + dummy_light_client, DefaultIbcStore, LightClientState, MockIbcStore, }; use rstest::*; use tendermint_testgen::Validator as TestgenValidator; @@ -128,20 +128,17 @@ fn test_update_client_with_prev_header() { let height_1 = Height::new(0, 43).unwrap(); let height_2 = Height::new(0, 44).unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host( TendermintHost::builder() .chain_id(chain_id_b.clone()) .build(), ) .latest_height(latest_height) - .build::(); + .call(); let mut ctx = MockContext::default() - .with_light_client( - &client_id, - LightClientBuilder::init().context(&ctx_b).build(), - ) + .with_light_client(&client_id, dummy_light_client(&ctx_b).call()) .ibc_store; let mut router = MockRouter::new_with_transfer(); @@ -225,26 +222,25 @@ fn test_consensus_state_pruning() { let client_id = tm_client_type().build_client_id(0); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id.clone()).build()) .latest_height(client_height) - .build::(); + .call(); - let mut ctx = TestContextConfig::builder() + let mut ctx: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id).build()) .latest_height(client_height) .latest_timestamp(Timestamp::now()) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .params( ClientStateConfig::builder() .trusting_period(Duration::from_secs(3)) .build(), ) - .build(), + .call(), ); let mut router = MockRouter::new_with_transfer(); @@ -343,25 +339,24 @@ fn test_update_synthetic_tendermint_client_adjacent_ok() { let update_height = Height::new(1, 21).unwrap(); let chain_id_b = ChainId::new("mockgaiaB-1").unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) - .build::(); + .call(); - let mut ctx = TestContextConfig::builder() + let mut ctx: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let mut router = MockRouter::new_with_transfer(); @@ -434,27 +429,26 @@ fn test_update_synthetic_tendermint_client_validator_change_ok() { assert_eq!(update_height.revision_height(), 22); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) .block_params_history(block_params) - .build::(); + .call(); - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, // remote light client initialized with client_height - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let mut router_a = MockRouter::new_with_transfer(); @@ -533,27 +527,26 @@ fn test_update_synthetic_tendermint_client_wrong_trusted_validator_change_fail() assert_eq!(update_height.revision_height(), 22); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) .block_params_history(block_params) - .build::(); + .call(); - let ctx_a = TestContextConfig::builder() + let ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, // remote light client initialized with client_height - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let router = MockRouter::new_with_transfer(); @@ -639,27 +632,26 @@ fn test_update_synthetic_tendermint_client_validator_change_fail() { assert_eq!(update_height.revision_height(), 22); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) .block_params_history(block_params) - .build::(); + .call(); - let ctx_a = TestContextConfig::builder() + let ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, // remote light client initialized with client_height - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let router_a = MockRouter::new_with_transfer(); @@ -733,27 +725,26 @@ fn test_update_synthetic_tendermint_client_malicious_validator_change_pass() { assert_eq!(update_height.revision_height(), 22); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) .block_params_history(block_params) - .build::(); + .call(); - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, // remote light client initialized with client_height - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let mut router_a = MockRouter::new_with_transfer(); @@ -829,27 +820,26 @@ fn test_update_synthetic_tendermint_client_adjacent_malicious_validator_change_f assert_eq!(update_height.revision_height(), 22); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) .block_params_history(block_params) - .build::(); + .call(); - let ctx_a = TestContextConfig::builder() + let ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, // remote light client initialized with client_height - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let router_a = MockRouter::new_with_transfer(); @@ -886,25 +876,24 @@ fn test_update_synthetic_tendermint_client_non_adjacent_ok() { let update_height = Height::new(1, 21).unwrap(); let chain_id_b = ChainId::new("mockgaiaB-1").unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(update_height) - .build::(); + .call(); - let mut ctx = TestContextConfig::builder() + let mut ctx: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height.sub(1).expect("no error"), client_height]) - .build(), + .call(), ); let mut router = MockRouter::new_with_transfer(); @@ -950,21 +939,20 @@ fn test_update_synthetic_tendermint_client_duplicate_ok() { let ctx_b_chain_id = ChainId::new("mockgaiaB-1").unwrap(); let start_height = Height::new(1, 11).unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(ctx_b_chain_id).build()) .latest_height(client_height) - .build::(); + .call(); - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host(MockHost::builder().chain_id(ctx_a_chain_id).build()) .latest_height(start_height) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([start_height]) - .build(), + .call(), ); let mut router_a = MockRouter::new_with_transfer(); @@ -1070,27 +1058,24 @@ fn test_update_synthetic_tendermint_client_lower_height() { let chain_start_height = Height::new(1, 11).unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host( TendermintHost::builder() .chain_id(ChainId::new("mockgaiaB-1").unwrap()) .build(), ) .latest_height(client_height) - .build::(); + .call(); - let ctx = TestContextConfig::builder() + let ctx: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(chain_start_height) - .build::() - .with_light_client( - &client_id, - LightClientBuilder::init().context(&ctx_b).build(), - ); + .call() + .with_light_client(&client_id, dummy_light_client(&ctx_b).call()); let router = MockRouter::new_with_transfer(); @@ -1240,30 +1225,29 @@ fn test_misbehaviour_synthetic_tendermint_equivocation() { let chain_id_b = ChainId::new("mockgaiaB-1").unwrap(); // Create a mock context for chain-B - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host( TendermintHost::builder() .chain_id(chain_id_b.clone()) .build(), ) .latest_height(misbehaviour_height) - .build::(); + .call(); // Create a mock context for chain-A with a synthetic tendermint light client for chain-B - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_height]) - .build(), + .call(), ); let mut router_a = MockRouter::new_with_transfer(); @@ -1313,28 +1297,25 @@ fn test_misbehaviour_synthetic_tendermint_bft_time() { let misbehaviour_height = Height::new(1, 21).unwrap(); let chain_id_b = ChainId::new("mockgaiaB-1").unwrap(); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host( TendermintHost::builder() .chain_id(chain_id_b.clone()) .build(), ) .latest_height(client_height) - .build::(); + .call(); // Create a mock context for chain-A with a synthetic tendermint light client for chain-B - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) .build(), ) .latest_height(Height::new(1, 1).unwrap()) - .build::() - .with_light_client( - &client_id, - LightClientBuilder::init().context(&ctx_b).build(), - ); + .call() + .with_light_client(&client_id, dummy_light_client(&ctx_b).call()); let mut router_a = MockRouter::new_with_transfer(); @@ -1401,13 +1382,13 @@ fn test_expired_client() { let trusting_period = Duration::from_secs(64); - let ctx_b = TestContextConfig::builder() + let ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(client_height) .latest_timestamp(timestamp) - .build::(); + .call(); - let mut ctx = TestContextConfig::builder() + let mut ctx: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) @@ -1415,17 +1396,16 @@ fn test_expired_client() { ) .latest_height(Height::new(1, 1).unwrap()) .latest_timestamp(timestamp) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .params( ClientStateConfig::builder() .trusting_period(trusting_period) .build(), ) - .build(), + .call(), ); while ctx.ibc_store.host_timestamp().expect("no error") @@ -1454,13 +1434,13 @@ fn test_client_update_max_clock_drift() { let max_clock_drift = Duration::from_secs(64); - let mut ctx_b = TestContextConfig::builder() + let mut ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(client_height) .latest_timestamp(timestamp) - .build::(); + .call(); - let ctx_a = TestContextConfig::builder() + let ctx_a: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id(ChainId::new("mockgaiaA-1").unwrap()) @@ -1468,17 +1448,16 @@ fn test_client_update_max_clock_drift() { ) .latest_height(Height::new(1, 1).unwrap()) .latest_timestamp(timestamp) - .build::() + .call() .with_light_client( &client_id, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .params( ClientStateConfig::builder() .max_clock_drift(max_clock_drift) .build(), ) - .build(), + .call(), ); let router_a = MockRouter::new_with_transfer(); @@ -1568,31 +1547,29 @@ fn client_update_ping_pong() { let chain_id_b = ChainId::new("mockgaiaB-1").unwrap(); // Create two mock contexts, one for each chain. - let mut ctx_a = TestContextConfig::builder() + let mut ctx_a: MockContext = dummy_store_generic_test_context() .host(MockHost::builder().chain_id(chain_id_a).build()) .latest_height(chain_a_start_height) - .build::(); + .call(); - let mut ctx_b = TestContextConfig::builder() + let mut ctx_b: TendermintContext = dummy_store_generic_test_context() .host(TendermintHost::builder().chain_id(chain_id_b).build()) .latest_height(chain_b_start_height) .latest_timestamp(ctx_a.timestamp_at(chain_a_start_height.decrement().unwrap())) // chain B is running slower than chain A - .build::(); + .call(); ctx_a = ctx_a.with_light_client( &client_on_a_for_b, - LightClientBuilder::init() - .context(&ctx_b) + dummy_light_client(&ctx_b) .consensus_heights([client_on_a_for_b_height]) - .build(), + .call(), ); ctx_b = ctx_b.with_light_client( &client_on_b_for_a, - LightClientBuilder::init() - .context(&ctx_a) + dummy_light_client(&ctx_a) .consensus_heights([client_on_b_for_a_height]) - .build(), + .call(), ); for _i in 0..num_iterations { diff --git a/tests-integration/tests/core/ics03_connection/conn_open_ack.rs b/tests-integration/tests/core/ics03_connection/conn_open_ack.rs index 7bab98ef4..7e8cd4155 100644 --- a/tests-integration/tests/core/ics03_connection/conn_open_ack.rs +++ b/tests-integration/tests/core/ics03_connection/conn_open_ack.rs @@ -16,7 +16,7 @@ use ibc::core::primitives::ZERO_DURATION; use ibc_core_host_types::error::HostError; use ibc_testkit::context::MockContext; use ibc_testkit::fixtures::core::connection::dummy_msg_conn_open_ack; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::hosts::MockHost; use ibc_testkit::testapp::ibc::core::router::MockRouter; @@ -61,7 +61,7 @@ fn conn_open_ack_fixture(ctx: Ctx) -> Fixture { conn_end_open.set_state(State::Open); // incorrect field let ctx_default = MockContext::default(); - let ctx_new = TestContextConfig::builder() + let ctx_new: MockContext = dummy_store_generic_test_context() .host( MockHost::builder() .chain_id( @@ -70,7 +70,7 @@ fn conn_open_ack_fixture(ctx: Ctx) -> Fixture { .build(), ) .latest_height(latest_height) - .build::(); + .call(); let ctx = match ctx { Ctx::New => ctx_new.ibc_store, Ctx::NewWithConnection => { diff --git a/tests-integration/tests/core/ics03_connection/conn_open_try.rs b/tests-integration/tests/core/ics03_connection/conn_open_try.rs index e466b403d..2d9642226 100644 --- a/tests-integration/tests/core/ics03_connection/conn_open_try.rs +++ b/tests-integration/tests/core/ics03_connection/conn_open_try.rs @@ -8,7 +8,7 @@ use ibc::core::host::ValidationContext; use ibc::core::primitives::prelude::*; use ibc_testkit::context::MockContext; use ibc_testkit::fixtures::core::connection::dummy_msg_conn_open_try; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::{Expect, Fixture}; use ibc_testkit::hosts::MockHost; use ibc_testkit::testapp::ibc::core::router::MockRouter; @@ -51,9 +51,9 @@ fn conn_open_try_fixture(ctx_variant: Ctx, msg_variant: Msg) -> Fixture(); + .call(); let ctx = match ctx_variant { Ctx::Default => DefaultIbcStore::default(), Ctx::WithClient => { diff --git a/tests-integration/tests/core/router.rs b/tests-integration/tests/core/router.rs index 5db8045ae..9bfdd06fb 100644 --- a/tests-integration/tests/core/router.rs +++ b/tests-integration/tests/core/router.rs @@ -23,7 +23,7 @@ use ibc::core::primitives::prelude::*; use ibc::core::primitives::Timestamp; use ibc_testkit::context::MockContext; use ibc_testkit::fixtures::applications::transfer::{ - extract_transfer_packet, MsgTransferConfig, PacketDataConfig, + dummy_msg_transfer, dummy_packet_data, extract_transfer_packet, }; use ibc_testkit::fixtures::core::channel::{ dummy_raw_msg_ack_with_packet, dummy_raw_msg_chan_close_confirm, dummy_raw_msg_chan_close_init, @@ -35,7 +35,7 @@ use ibc_testkit::fixtures::core::connection::{ dummy_msg_conn_open_ack, dummy_msg_conn_open_init, dummy_msg_conn_open_init_with_client_id, dummy_msg_conn_open_try, msg_conn_open_try_with_client_id, }; -use ibc_testkit::fixtures::core::context::TestContextConfig; +use ibc_testkit::fixtures::core::context::dummy_store_generic_test_context; use ibc_testkit::fixtures::core::signer::dummy_account_id; use ibc_testkit::testapp::ibc::applications::transfer::types::DummyTransferModule; use ibc_testkit::testapp::ibc::clients::mock::client_state::MockClientState; @@ -89,7 +89,7 @@ fn routing_module_and_keepers() { let upgrade_client_height_second = Height::new(1, 1).unwrap(); // We reuse this same context across all tests. Nothing in particular needs parametrizing. - let mut ctx = TestContextConfig::builder() + let mut ctx: MockContext = dummy_store_generic_test_context() // a future timestamp, so that submitted packets are considered from past // not more than 5 secs, as later dummy_raw_msg_timeout_on_close(*, 5) is used .latest_timestamp( @@ -97,7 +97,7 @@ fn routing_module_and_keepers() { .add(core::time::Duration::from_secs(4)) .unwrap(), ) - .build::(); + .call(); let mut router = MockRouter::new_with_transfer(); @@ -142,29 +142,24 @@ fn routing_module_and_keepers() { let msg_chan_close_confirm = MsgChannelCloseConfirm::try_from(dummy_raw_msg_chan_close_confirm(client_height)).unwrap(); - let packet_data = PacketDataConfig::builder() - .token( - BaseCoin { - denom: "uatom".parse().expect("parse denom"), - amount: U256::from(10).into(), - } - .into(), - ) - .build(); + let packet_data = dummy_packet_data( + BaseCoin { + denom: "uatom".parse().expect("parse denom"), + amount: U256::from(10).into(), + } + .into(), + ) + .call(); - let msg_transfer = MsgTransferConfig::builder() - .packet_data(packet_data.clone()) + let msg_transfer = dummy_msg_transfer(packet_data.clone()) .timeout_height_on_b(TimeoutHeight::At(Height::new(0, 35).unwrap())) - .build(); + .call(); - let msg_transfer_two = MsgTransferConfig::builder() - .packet_data(packet_data.clone()) + let msg_transfer_two = dummy_msg_transfer(packet_data.clone()) .timeout_height_on_b(TimeoutHeight::At(Height::new(0, 36).unwrap())) - .build(); + .call(); - let msg_transfer_no_timeout = MsgTransferConfig::builder() - .packet_data(packet_data.clone()) - .build(); + let msg_transfer_no_timeout = dummy_msg_transfer(packet_data.clone()).call(); let mut msg_to_on_close = MsgTimeoutOnClose::try_from(dummy_raw_msg_timeout_on_close(36, 5)).unwrap();