From ff13029a0fa8333722488cfe518f90e09224b90e Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 23 Oct 2024 08:51:45 -0700 Subject: [PATCH] imp: introduce `starknet_ibc_testkit` for shared testing utilities across IBC packages (#95) * imp: introduce starknet_ibc_testkit * nitpicking --- cairo-contracts/Scarb.lock | 17 +++++++ cairo-contracts/Scarb.toml | 2 + cairo-contracts/packages/apps/Scarb.toml | 4 ++ cairo-contracts/packages/apps/src/lib.cairo | 21 ++------ .../{test_transfer.cairo => transfer.cairo} | 3 +- cairo-contracts/packages/clients/Scarb.toml | 3 ++ .../packages/clients/src/lib.cairo | 14 ++---- .../{test_cometbft.cairo => cometbft.cairo} | 5 +- cairo-contracts/packages/contracts/Scarb.toml | 4 ++ .../packages/contracts/src/lib.cairo | 24 ++------- .../{test_channel.cairo => channel.cairo} | 10 ++-- .../tests/{test_client.cairo => client.cairo} | 8 +-- .../{test_transfer.cairo => transfer.cairo} | 12 ++--- cairo-contracts/packages/core/Scarb.toml | 12 +++-- .../core/src/channel/components/handler.cairo | 29 ++++++++++- cairo-contracts/packages/core/src/lib.cairo | 25 ++-------- .../{test_channel.cairo => channel.cairo} | 3 +- .../tests/{test_client.cairo => client.cairo} | 6 +-- cairo-contracts/packages/testkit/Scarb.toml | 35 +++++++++++++ .../src/configs/cometbft.cairo} | 3 +- .../src/configs/transfer.cairo} | 3 +- .../src/dummies/core.cairo} | 0 .../src/dummies/transfer.cairo} | 0 .../src/event_spy/client.cairo} | 0 .../src/event_spy/transfer.cairo} | 2 +- .../tests => testkit/src}/handles/app.cairo | 0 .../src}/handles/client.cairo | 0 .../tests => testkit/src}/handles/core.cairo | 0 .../tests => testkit/src}/handles/erc20.cairo | 2 +- .../packages/testkit/src/lib.cairo | 49 +++++++++++++++++++ .../src/mocks/channel.cairo} | 2 +- .../src/mocks/client.cairo} | 2 +- .../src/mocks/cometbft.cairo} | 2 +- .../src/mocks/transfer.cairo} | 2 +- .../src/tests => testkit/src}/setup.cairo | 8 +-- 35 files changed, 201 insertions(+), 111 deletions(-) rename cairo-contracts/packages/apps/src/tests/{test_transfer.cairo => transfer.cairo} (86%) rename cairo-contracts/packages/clients/src/tests/{test_cometbft.cairo => cometbft.cairo} (93%) rename cairo-contracts/packages/contracts/src/tests/{test_channel.cairo => channel.cairo} (89%) rename cairo-contracts/packages/contracts/src/tests/{test_client.cairo => client.cairo} (92%) rename cairo-contracts/packages/contracts/src/tests/{test_transfer.cairo => transfer.cairo} (94%) rename cairo-contracts/packages/core/src/tests/{test_channel.cairo => channel.cairo} (91%) rename cairo-contracts/packages/core/src/tests/{test_client.cairo => client.cairo} (91%) create mode 100644 cairo-contracts/packages/testkit/Scarb.toml rename cairo-contracts/packages/{clients/src/tests/config.cairo => testkit/src/configs/cometbft.cairo} (97%) rename cairo-contracts/packages/{apps/src/tests/config.cairo => testkit/src/configs/transfer.cairo} (96%) rename cairo-contracts/packages/{core/src/tests/dummy.cairo => testkit/src/dummies/core.cairo} (100%) rename cairo-contracts/packages/{apps/src/tests/dummy.cairo => testkit/src/dummies/transfer.cairo} (100%) rename cairo-contracts/packages/{core/src/tests/extend_spy.cairo => testkit/src/event_spy/client.cairo} (100%) rename cairo-contracts/packages/{apps/src/tests/extend_spy.cairo => testkit/src/event_spy/transfer.cairo} (97%) rename cairo-contracts/packages/{contracts/src/tests => testkit/src}/handles/app.cairo (100%) rename cairo-contracts/packages/{contracts/src/tests => testkit/src}/handles/client.cairo (100%) rename cairo-contracts/packages/{contracts/src/tests => testkit/src}/handles/core.cairo (100%) rename cairo-contracts/packages/{contracts/src/tests => testkit/src}/handles/erc20.cairo (95%) create mode 100644 cairo-contracts/packages/testkit/src/lib.cairo rename cairo-contracts/packages/{core/src/tests/mocks/mock_channel.cairo => testkit/src/mocks/channel.cairo} (96%) rename cairo-contracts/packages/{core/src/tests/mocks/mock_client.cairo => testkit/src/mocks/client.cairo} (96%) rename cairo-contracts/packages/{clients/src/tests/mocks/mock_cometbft.cairo => testkit/src/mocks/cometbft.cairo} (96%) rename cairo-contracts/packages/{apps/src/tests/mocks/mock_transfer.cairo => testkit/src/mocks/transfer.cairo} (99%) rename cairo-contracts/packages/{contracts/src/tests => testkit/src}/setup.cairo (92%) diff --git a/cairo-contracts/Scarb.lock b/cairo-contracts/Scarb.lock index 20edf02a..901b3b99 100644 --- a/cairo-contracts/Scarb.lock +++ b/cairo-contracts/Scarb.lock @@ -89,6 +89,7 @@ dependencies = [ "openzeppelin_utils", "snforge_std", "starknet_ibc_core", + "starknet_ibc_testkit", "starknet_ibc_utils", ] @@ -97,6 +98,7 @@ name = "starknet_ibc_clients" version = "0.1.0" dependencies = [ "starknet_ibc_core", + "starknet_ibc_testkit", ] [[package]] @@ -105,9 +107,11 @@ version = "0.1.0" dependencies = [ "openzeppelin_access", "openzeppelin_token", + "snforge_std", "starknet_ibc_apps", "starknet_ibc_clients", "starknet_ibc_core", + "starknet_ibc_testkit", "starknet_ibc_utils", ] @@ -117,9 +121,22 @@ version = "0.1.0" dependencies = [ "openzeppelin_testing", "snforge_std", + "starknet_ibc_testkit", "starknet_ibc_utils", ] +[[package]] +name = "starknet_ibc_testkit" +version = "0.1.0" +dependencies = [ + "openzeppelin_access", + "openzeppelin_testing", + "openzeppelin_utils", + "starknet_ibc_apps", + "starknet_ibc_clients", + "starknet_ibc_core", +] + [[package]] name = "starknet_ibc_utils" version = "0.1.0" diff --git a/cairo-contracts/Scarb.toml b/cairo-contracts/Scarb.toml index 999d5a16..91dd36b5 100644 --- a/cairo-contracts/Scarb.toml +++ b/cairo-contracts/Scarb.toml @@ -4,6 +4,7 @@ members = [ "packages/clients", "packages/contracts", "packages/core", + "packages/testkit", "packages/utils", ] @@ -37,6 +38,7 @@ starknet_ibc_apps = { path = "packages/apps" } starknet_ibc_clients = { path = "packages/clients" } starknet_ibc_contracts = { path = "packages/contracts" } starknet_ibc_core = { path = "packages/core" } +starknet_ibc_testkit = { path = "packages/testkit" } starknet_ibc_utils = { path = "packages/utils" } [workspace.tool.fmt] diff --git a/cairo-contracts/packages/apps/Scarb.toml b/cairo-contracts/packages/apps/Scarb.toml index f739e246..bc6d614b 100644 --- a/cairo-contracts/packages/apps/Scarb.toml +++ b/cairo-contracts/packages/apps/Scarb.toml @@ -34,5 +34,9 @@ starknet_ibc_core = { workspace = true } starknet_ibc_utils = { workspace = true } [dev-dependencies] +# external dependencies openzeppelin_testing = { workspace = true } snforge_std = { workspace = true } + +# ibc dependencies +starknet_ibc_testkit = { workspace = true } diff --git a/cairo-contracts/packages/apps/src/lib.cairo b/cairo-contracts/packages/apps/src/lib.cairo index 2ec9c281..b58a503b 100644 --- a/cairo-contracts/packages/apps/src/lib.cairo +++ b/cairo-contracts/packages/apps/src/lib.cairo @@ -31,23 +31,8 @@ pub mod transfer { "transfer" } } -pub mod tests { - mod config; - mod dummy; - mod extend_spy; - #[cfg(test)] - mod test_transfer; - #[cfg(test)] - pub use mocks::mock_transfer::MockTransferApp; - pub use config::{TransferAppConfig, TransferAppConfigImpl, TransferAppConfigTrait}; - pub use dummy::{ - NAME, SYMBOL, PUBKEY, AMOUNT, SUPPLY, OWNER, STARKNET, COSMOS, SALT, DECIMALS, CLASS_HASH, - EMPTY_MEMO - }; - pub use extend_spy::{TransferEventSpyExtImpl, TransferEventSpyExt}; - #[cfg(test)] - mod mocks { - pub mod mock_transfer; - } +#[cfg(test)] +mod tests { + mod transfer; } diff --git a/cairo-contracts/packages/apps/src/tests/test_transfer.cairo b/cairo-contracts/packages/apps/src/tests/transfer.cairo similarity index 86% rename from cairo-contracts/packages/apps/src/tests/test_transfer.cairo rename to cairo-contracts/packages/apps/src/tests/transfer.cairo index 6b7f09f4..fa3470b2 100644 --- a/cairo-contracts/packages/apps/src/tests/test_transfer.cairo +++ b/cairo-contracts/packages/apps/src/tests/transfer.cairo @@ -1,8 +1,9 @@ -use starknet_ibc_apps::tests::{MockTransferApp, CLASS_HASH}; use starknet_ibc_apps::transfer::TokenTransferComponent::{ TransferInitializerImpl, TransferReaderImpl }; use starknet_ibc_apps::transfer::TokenTransferComponent; +use starknet_ibc_testkit::dummies::CLASS_HASH; +use starknet_ibc_testkit::mocks::MockTransferApp; type ComponentState = TokenTransferComponent::ComponentState; diff --git a/cairo-contracts/packages/clients/Scarb.toml b/cairo-contracts/packages/clients/Scarb.toml index 364d38b0..cf3e24fe 100644 --- a/cairo-contracts/packages/clients/Scarb.toml +++ b/cairo-contracts/packages/clients/Scarb.toml @@ -28,3 +28,6 @@ starknet = { workspace = true } # ibc dependencies starknet_ibc_core = { workspace = true } + +[dev-dependencies] +starknet_ibc_testkit = { workspace = true } diff --git a/cairo-contracts/packages/clients/src/lib.cairo b/cairo-contracts/packages/clients/src/lib.cairo index 49d2154b..e18dbe7b 100644 --- a/cairo-contracts/packages/clients/src/lib.cairo +++ b/cairo-contracts/packages/clients/src/lib.cairo @@ -15,16 +15,8 @@ pub mod cometbft { CometHeader, CometHeaderImpl, CometHeaderIntoConsensusState, CometHeaderTrait, SignedHeader }; } -pub mod tests { - mod config; - #[cfg(test)] - mod test_cometbft; - #[cfg(test)] - pub use mocks::mock_cometbft::MockCometClient; - pub use config::{CometClientConfig, CometClientConfigImpl, CometClientConfigTrait}; - #[cfg(test)] - mod mocks { - pub mod mock_cometbft; - } +#[cfg(test)] +mod tests { + mod cometbft; } diff --git a/cairo-contracts/packages/clients/src/tests/test_cometbft.cairo b/cairo-contracts/packages/clients/src/tests/cometbft.cairo similarity index 93% rename from cairo-contracts/packages/clients/src/tests/test_cometbft.cairo rename to cairo-contracts/packages/clients/src/tests/cometbft.cairo index 40c7fdd0..43849f83 100644 --- a/cairo-contracts/packages/clients/src/tests/test_cometbft.cairo +++ b/cairo-contracts/packages/clients/src/tests/cometbft.cairo @@ -3,9 +3,10 @@ use starknet_ibc_clients::cometbft::CometClientComponent::{ CometClientHandler, CometClientQuery, ClientReaderImpl }; use starknet_ibc_clients::cometbft::CometClientComponent; -use starknet_ibc_clients::tests::{MockCometClient, CometClientConfigTrait}; use starknet_ibc_core::client::StatusTrait; -use starknet_ibc_core::tests::HEIGHT; +use starknet_ibc_testkit::configs::CometClientConfigTrait; +use starknet_ibc_testkit::dummies::HEIGHT; +use starknet_ibc_testkit::mocks::MockCometClient; type ComponentState = CometClientComponent::ComponentState; diff --git a/cairo-contracts/packages/contracts/Scarb.toml b/cairo-contracts/packages/contracts/Scarb.toml index 394ba66a..c92f14b6 100644 --- a/cairo-contracts/packages/contracts/Scarb.toml +++ b/cairo-contracts/packages/contracts/Scarb.toml @@ -34,6 +34,10 @@ starknet_ibc_core = { workspace = true } starknet_ibc_clients = { workspace = true } starknet_ibc_utils = { workspace = true } +[dev-dependencies] +snforge_std = { workspace = true } +starknet_ibc_testkit = { workspace = true } + [[target.starknet-contract]] allowed-libfuncs-list.name = "experimental" sierra = true diff --git a/cairo-contracts/packages/contracts/src/lib.cairo b/cairo-contracts/packages/contracts/src/lib.cairo index e7237e6d..3ab270f8 100644 --- a/cairo-contracts/packages/contracts/src/lib.cairo +++ b/cairo-contracts/packages/contracts/src/lib.cairo @@ -8,25 +8,9 @@ pub mod clients { mod cometbft; pub use cometbft::CometClient; } +#[cfg(test)] mod tests { - mod setup; - #[cfg(test)] - mod test_channel; - #[cfg(test)] - mod test_client; - #[cfg(test)] - mod test_transfer; - - pub use handles::app::{AppContract, AppHandleImpl, AppHandle}; - pub use handles::client::{ClientHandleImpl, ClientHandle}; - pub use handles::core::{CoreContract, CoreHandleImpl, CoreHandle}; - pub use handles::erc20::{ERC20HandleImpl, ERC20Handle}; - pub use setup::{Setup, SetupImpl, SetupTrait}; - - mod handles { - pub mod app; - pub mod client; - pub mod core; - pub mod erc20; - } + mod channel; + mod client; + mod transfer; } diff --git a/cairo-contracts/packages/contracts/src/tests/test_channel.cairo b/cairo-contracts/packages/contracts/src/tests/channel.cairo similarity index 89% rename from cairo-contracts/packages/contracts/src/tests/test_channel.cairo rename to cairo-contracts/packages/contracts/src/tests/channel.cairo index 5112fcf7..43c02ced 100644 --- a/cairo-contracts/packages/contracts/src/tests/test_channel.cairo +++ b/cairo-contracts/packages/contracts/src/tests/channel.cairo @@ -1,12 +1,12 @@ use snforge_std::spy_events; -use starknet_ibc_apps::tests::TransferEventSpyExt; -use starknet_ibc_apps::tests::{TransferAppConfigTrait, COSMOS, STARKNET, OWNER}; use starknet_ibc_apps::transfer::ERC20Contract; use starknet_ibc_apps::transfer::TRANSFER_PORT_ID; -use starknet_ibc_clients::tests::CometClientConfigTrait; -use starknet_ibc_contracts::tests::{SetupImpl, CoreHandle, AppHandle, ERC20Handle}; use starknet_ibc_core::channel::ChannelEndTrait; -use starknet_ibc_core::tests::CLIENT_TYPE; +use starknet_ibc_testkit::configs::{TransferAppConfigTrait, CometClientConfigTrait}; +use starknet_ibc_testkit::dummies::{COSMOS, STARKNET, OWNER, CLIENT_TYPE}; +use starknet_ibc_testkit::event_spy::TransferEventSpyExt; +use starknet_ibc_testkit::handles::{CoreHandle, AppHandle, ERC20Handle}; +use starknet_ibc_testkit::setup::SetupImpl; use starknet_ibc_utils::ComputeKey; #[test] diff --git a/cairo-contracts/packages/contracts/src/tests/test_client.cairo b/cairo-contracts/packages/contracts/src/tests/client.cairo similarity index 92% rename from cairo-contracts/packages/contracts/src/tests/test_client.cairo rename to cairo-contracts/packages/contracts/src/tests/client.cairo index 0705bbe5..11c5e16b 100644 --- a/cairo-contracts/packages/contracts/src/tests/test_client.cairo +++ b/cairo-contracts/packages/contracts/src/tests/client.cairo @@ -1,9 +1,11 @@ use openzeppelin_testing::events::EventSpyExt; use snforge_std::spy_events; -use starknet_ibc_clients::tests::CometClientConfigTrait; -use starknet_ibc_contracts::tests::{CoreHandle, SetupImpl}; use starknet_ibc_core::client::{UpdateResponse, StatusTrait, ClientContractTrait}; -use starknet_ibc_core::tests::{ClientEventSpyExt, HEIGHT, CLIENT_TYPE}; +use starknet_ibc_testkit::configs::CometClientConfigTrait; +use starknet_ibc_testkit::dummies::{HEIGHT, CLIENT_TYPE}; +use starknet_ibc_testkit::event_spy::ClientEventSpyExt; +use starknet_ibc_testkit::handles::CoreHandle; +use starknet_ibc_testkit::setup::SetupImpl; #[test] fn test_create_comet_client_ok() { diff --git a/cairo-contracts/packages/contracts/src/tests/test_transfer.cairo b/cairo-contracts/packages/contracts/src/tests/transfer.cairo similarity index 94% rename from cairo-contracts/packages/contracts/src/tests/test_transfer.cairo rename to cairo-contracts/packages/contracts/src/tests/transfer.cairo index ba3eca94..e4b6cf62 100644 --- a/cairo-contracts/packages/contracts/src/tests/test_transfer.cairo +++ b/cairo-contracts/packages/contracts/src/tests/transfer.cairo @@ -1,13 +1,11 @@ use openzeppelin_testing::events::EventSpyExt; use snforge_std::{start_cheat_caller_address, spy_events}; -use starknet_ibc_apps::tests::TransferEventSpyExt; -use starknet_ibc_apps::tests::{ - TransferAppConfigTrait, NAME, SYMBOL, SUPPLY, OWNER, COSMOS, STARKNET -}; use starknet_ibc_apps::transfer::{ERC20Contract, TRANSFER_PORT_ID}; -use starknet_ibc_clients::tests::CometClientConfigTrait; -use starknet_ibc_contracts::tests::{SetupImpl, CoreHandle, ERC20Handle, AppHandle}; -use starknet_ibc_core::tests::CLIENT_TYPE; +use starknet_ibc_testkit::configs::{TransferAppConfigTrait, CometClientConfigTrait}; +use starknet_ibc_testkit::dummies::{NAME, SYMBOL, SUPPLY, OWNER, COSMOS, STARKNET, CLIENT_TYPE}; +use starknet_ibc_testkit::event_spy::TransferEventSpyExt; +use starknet_ibc_testkit::handles::{CoreHandle, AppHandle, ERC20Handle}; +use starknet_ibc_testkit::setup::SetupImpl; use starknet_ibc_utils::ComputeKey; #[test] diff --git a/cairo-contracts/packages/core/Scarb.toml b/cairo-contracts/packages/core/Scarb.toml index c6be3b3d..6ccfe7ef 100644 --- a/cairo-contracts/packages/core/Scarb.toml +++ b/cairo-contracts/packages/core/Scarb.toml @@ -24,12 +24,16 @@ fmt = { workspace = true } [dependencies] # external dependencies -openzeppelin_testing = { workspace = true } -starknet = { workspace = true } +starknet = { workspace = true } # ibc dependencies starknet_ibc_utils = { workspace = true } [dev-dependencies] -cairo_test = { workspace = true } -snforge_std = { workspace = true } +# external dependencies +openzeppelin_testing = { workspace = true } +cairo_test = { workspace = true } +snforge_std = { workspace = true } + +# ibc dependencies +starknet_ibc_testkit = { workspace = true } diff --git a/cairo-contracts/packages/core/src/channel/components/handler.cairo b/cairo-contracts/packages/core/src/channel/components/handler.cairo index f8caacbf..347103a8 100644 --- a/cairo-contracts/packages/core/src/channel/components/handler.cairo +++ b/cairo-contracts/packages/core/src/channel/components/handler.cairo @@ -1,3 +1,6 @@ +use starknet_ibc_core::channel::{ChannelEnd, ChannelState, ChannelOrdering, Counterparty}; +use starknet_ibc_core::host::{ClientId, PortId, ChannelId, SequencePartialOrd, SequenceZero}; + #[starknet::component] pub mod ChannelHandlerComponent { use ChannelEventEmitterComponent::ChannelEventEmitterTrait; @@ -23,8 +26,8 @@ pub mod ChannelHandlerComponent { use starknet_ibc_core::router::{ RouterHandlerComponent, ApplicationContractTrait, ApplicationContract }; - use starknet_ibc_core::tests::{PORT_ID, CHANNEL_ID, CHANNEL_END}; use starknet_ibc_utils::ValidateBasic; + use super::{PORT_ID, CHANNEL_ID, CHANNEL_END}; #[storage] pub struct Storage { @@ -580,3 +583,27 @@ pub mod ChannelHandlerComponent { } } } + +// ----------------- Temporary until handshakes are implemented --------------- +pub(crate) fn CLIENT_ID() -> ClientId { + ClientId { client_type: '07-cometbft', sequence: 0 } +} + +pub(crate) fn PORT_ID() -> PortId { + PortId { port_id: "transfer" } +} + +pub(crate) fn CHANNEL_ID(sequence: u64) -> ChannelId { + ChannelId { channel_id: format!("channel-{sequence}") } +} + +pub(crate) fn CHANNEL_END(counterparty_channel_sequence: u64) -> ChannelEnd { + ChannelEnd { + state: ChannelState::Open, + ordering: ChannelOrdering::Unordered, + remote: Counterparty { + port_id: PORT_ID(), channel_id: CHANNEL_ID(counterparty_channel_sequence), + }, + client_id: CLIENT_ID(), + } +} diff --git a/cairo-contracts/packages/core/src/lib.cairo b/cairo-contracts/packages/core/src/lib.cairo index 8fa8db54..1e5ef0b3 100644 --- a/cairo-contracts/packages/core/src/lib.cairo +++ b/cairo-contracts/packages/core/src/lib.cairo @@ -1,24 +1,7 @@ -pub mod tests { - mod dummy; - mod extend_spy; - #[cfg(test)] - mod test_channel; - #[cfg(test)] - mod test_client; - #[cfg(test)] - pub use mocks::mock_channel::MockChannelHandler; - #[cfg(test)] - pub use mocks::mock_client::MockClientHandler; - - pub use dummy::{ - HEIGHT, CLIENT, CLIENT_TYPE, CLIENT_ID, PORT_ID, CHANNEL_ID, SEQUENCE, CHANNEL_END - }; - pub use extend_spy::ClientEventSpyExt; - #[cfg(test)] - pub mod mocks { - pub mod mock_channel; - pub mod mock_client; - } +#[cfg(test)] +mod tests { + mod channel; + mod client; } pub mod router { mod app_call; diff --git a/cairo-contracts/packages/core/src/tests/test_channel.cairo b/cairo-contracts/packages/core/src/tests/channel.cairo similarity index 91% rename from cairo-contracts/packages/core/src/tests/test_channel.cairo rename to cairo-contracts/packages/core/src/tests/channel.cairo index 03029710..d3d35932 100644 --- a/cairo-contracts/packages/core/src/tests/test_channel.cairo +++ b/cairo-contracts/packages/core/src/tests/channel.cairo @@ -4,7 +4,8 @@ use starknet_ibc_core::channel::ChannelHandlerComponent::{ ChannelInitializerImpl, ChannelWriterTrait }; use starknet_ibc_core::channel::ChannelHandlerComponent; -use starknet_ibc_core::tests::{CHANNEL_END, CHANNEL_ID, PORT_ID, SEQUENCE, MockChannelHandler}; +use starknet_ibc_testkit::dummies::{CHANNEL_END, CHANNEL_ID, PORT_ID, SEQUENCE}; +use starknet_ibc_testkit::mocks::MockChannelHandler; type ComponentState = ChannelHandlerComponent::ComponentState; diff --git a/cairo-contracts/packages/core/src/tests/test_client.cairo b/cairo-contracts/packages/core/src/tests/client.cairo similarity index 91% rename from cairo-contracts/packages/core/src/tests/test_client.cairo rename to cairo-contracts/packages/core/src/tests/client.cairo index 2b2a03d1..893048d3 100644 --- a/cairo-contracts/packages/core/src/tests/test_client.cairo +++ b/cairo-contracts/packages/core/src/tests/client.cairo @@ -6,9 +6,9 @@ use starknet_ibc_core::client::ClientHandlerComponent::{ ClientInternalImpl }; use starknet_ibc_core::client::{ClientHandlerComponent, CreateResponse}; -use starknet_ibc_core::tests::{ - CLIENT, CLIENT_TYPE, CLIENT_ID, HEIGHT, ClientEventSpyExt, MockClientHandler -}; +use starknet_ibc_testkit::dummies::{CLIENT, CLIENT_TYPE, CLIENT_ID, HEIGHT}; +use starknet_ibc_testkit::event_spy::ClientEventSpyExt; +use starknet_ibc_testkit::mocks::MockClientHandler; type ComponentState = ClientHandlerComponent::ComponentState; diff --git a/cairo-contracts/packages/testkit/Scarb.toml b/cairo-contracts/packages/testkit/Scarb.toml new file mode 100644 index 00000000..d2988dec --- /dev/null +++ b/cairo-contracts/packages/testkit/Scarb.toml @@ -0,0 +1,35 @@ +[package] +name = "starknet_ibc_testkit" +version = { workspace = true } +edition = { workspace = true } +cairo-version = { workspace = true } +scarb-version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +license = { workspace = true } +Readme = { workspace = true } +keywords = { workspace = true } + +description = """ + Provides a set of common artifacts used for testing different IBC packages. +""" + +[lib] + +[scripts] +test = { workspace = true } + +[tool] +fmt = { workspace = true } + +[dependencies] +# external dependencies +openzeppelin_access = { workspace = true } +openzeppelin_testing = { workspace = true } +openzeppelin_utils = { workspace = true } +starknet = { workspace = true } + +# ibc dependencies +starknet_ibc_core = { workspace = true } +starknet_ibc_clients = { workspace = true } +starknet_ibc_apps = { workspace = true } diff --git a/cairo-contracts/packages/clients/src/tests/config.cairo b/cairo-contracts/packages/testkit/src/configs/cometbft.cairo similarity index 97% rename from cairo-contracts/packages/clients/src/tests/config.cairo rename to cairo-contracts/packages/testkit/src/configs/cometbft.cairo index 124541ae..c96c5438 100644 --- a/cairo-contracts/packages/clients/src/tests/config.cairo +++ b/cairo-contracts/packages/testkit/src/configs/cometbft.cairo @@ -1,10 +1,9 @@ use starknet_ibc_clients::cometbft::{ CometClientState, CometConsensusState, CometHeader, SignedHeader }; - use starknet_ibc_core::client::{MsgCreateClient, MsgUpdateClient, Height, Status}; use starknet_ibc_core::host::ClientId; -use starknet_ibc_core::tests::{HEIGHT, CLIENT_TYPE}; +use starknet_ibc_testkit::dummies::{HEIGHT, CLIENT_TYPE}; #[derive(Clone, Debug, Drop, Serde)] pub struct CometClientConfig { diff --git a/cairo-contracts/packages/apps/src/tests/config.cairo b/cairo-contracts/packages/testkit/src/configs/transfer.cairo similarity index 96% rename from cairo-contracts/packages/apps/src/tests/config.cairo rename to cairo-contracts/packages/testkit/src/configs/transfer.cairo index dd2580ca..46fd197f 100644 --- a/cairo-contracts/packages/apps/src/tests/config.cairo +++ b/cairo-contracts/packages/testkit/src/configs/transfer.cairo @@ -1,5 +1,4 @@ use starknet::ContractAddress; -use starknet_ibc_apps::tests::{PUBKEY, NAME, AMOUNT, EMPTY_MEMO}; use starknet_ibc_apps::transfer::types::PrefixedDenomTrait; use starknet_ibc_apps::transfer::types::{ MsgTransfer, PacketData, PrefixedDenom, Denom, TracePrefixTrait, Participant @@ -7,7 +6,7 @@ use starknet_ibc_apps::transfer::types::{ use starknet_ibc_core::channel::{Packet, MsgRecvPacket}; use starknet_ibc_core::client::Timestamp; use starknet_ibc_core::host::{ChannelId, Sequence}; -use starknet_ibc_core::tests::{PORT_ID, CHANNEL_ID, HEIGHT}; +use starknet_ibc_testkit::dummies::{PUBKEY, NAME, AMOUNT, EMPTY_MEMO, PORT_ID, CHANNEL_ID, HEIGHT}; #[derive(Clone, Debug, Drop, Serde)] pub struct TransferAppConfig { diff --git a/cairo-contracts/packages/core/src/tests/dummy.cairo b/cairo-contracts/packages/testkit/src/dummies/core.cairo similarity index 100% rename from cairo-contracts/packages/core/src/tests/dummy.cairo rename to cairo-contracts/packages/testkit/src/dummies/core.cairo diff --git a/cairo-contracts/packages/apps/src/tests/dummy.cairo b/cairo-contracts/packages/testkit/src/dummies/transfer.cairo similarity index 100% rename from cairo-contracts/packages/apps/src/tests/dummy.cairo rename to cairo-contracts/packages/testkit/src/dummies/transfer.cairo diff --git a/cairo-contracts/packages/core/src/tests/extend_spy.cairo b/cairo-contracts/packages/testkit/src/event_spy/client.cairo similarity index 100% rename from cairo-contracts/packages/core/src/tests/extend_spy.cairo rename to cairo-contracts/packages/testkit/src/event_spy/client.cairo diff --git a/cairo-contracts/packages/apps/src/tests/extend_spy.cairo b/cairo-contracts/packages/testkit/src/event_spy/transfer.cairo similarity index 97% rename from cairo-contracts/packages/apps/src/tests/extend_spy.cairo rename to cairo-contracts/packages/testkit/src/event_spy/transfer.cairo index 61965901..a34b7a0b 100644 --- a/cairo-contracts/packages/apps/src/tests/extend_spy.cairo +++ b/cairo-contracts/packages/testkit/src/event_spy/transfer.cairo @@ -1,11 +1,11 @@ use openzeppelin_testing::events::{EventSpyExt, EventSpyExtImpl}; use snforge_std::EventSpy; use starknet::ContractAddress; -use starknet_ibc_apps::tests::EMPTY_MEMO; use starknet_ibc_apps::transfer::TokenTransferComponent::{ Event, SendEvent, RecvEvent, CreateTokenEvent }; use starknet_ibc_apps::transfer::types::{Participant, PrefixedDenom}; +use starknet_ibc_testkit::dummies::EMPTY_MEMO; #[generate_trait] pub impl TransferEventSpyExtImpl of TransferEventSpyExt { diff --git a/cairo-contracts/packages/contracts/src/tests/handles/app.cairo b/cairo-contracts/packages/testkit/src/handles/app.cairo similarity index 100% rename from cairo-contracts/packages/contracts/src/tests/handles/app.cairo rename to cairo-contracts/packages/testkit/src/handles/app.cairo diff --git a/cairo-contracts/packages/contracts/src/tests/handles/client.cairo b/cairo-contracts/packages/testkit/src/handles/client.cairo similarity index 100% rename from cairo-contracts/packages/contracts/src/tests/handles/client.cairo rename to cairo-contracts/packages/testkit/src/handles/client.cairo diff --git a/cairo-contracts/packages/contracts/src/tests/handles/core.cairo b/cairo-contracts/packages/testkit/src/handles/core.cairo similarity index 100% rename from cairo-contracts/packages/contracts/src/tests/handles/core.cairo rename to cairo-contracts/packages/testkit/src/handles/core.cairo diff --git a/cairo-contracts/packages/contracts/src/tests/handles/erc20.cairo b/cairo-contracts/packages/testkit/src/handles/erc20.cairo similarity index 95% rename from cairo-contracts/packages/contracts/src/tests/handles/erc20.cairo rename to cairo-contracts/packages/testkit/src/handles/erc20.cairo index e49b1989..960d0d4e 100644 --- a/cairo-contracts/packages/contracts/src/tests/handles/erc20.cairo +++ b/cairo-contracts/packages/testkit/src/handles/erc20.cairo @@ -2,8 +2,8 @@ use openzeppelin_testing::deploy; use openzeppelin_token::erc20::ERC20ABIDispatcherTrait; use snforge_std::{ContractClass, start_cheat_caller_address}; use starknet::ContractAddress; -use starknet_ibc_apps::tests::{NAME, SYMBOL, SUPPLY, OWNER}; use starknet_ibc_apps::transfer::{ERC20Contract, ERC20ContractTrait}; +use starknet_ibc_testkit::dummies::{NAME, SYMBOL, SUPPLY, OWNER}; #[generate_trait] pub impl ERC20HandleImpl of ERC20Handle { diff --git a/cairo-contracts/packages/testkit/src/lib.cairo b/cairo-contracts/packages/testkit/src/lib.cairo new file mode 100644 index 00000000..f38872db --- /dev/null +++ b/cairo-contracts/packages/testkit/src/lib.cairo @@ -0,0 +1,49 @@ +pub mod setup; +pub mod mocks { + mod channel; + mod client; + mod cometbft; + mod transfer; + + pub use channel::MockChannelHandler; + pub use client::MockClientHandler; + pub use cometbft::MockCometClient; + pub use transfer::MockTransferApp; +} +pub mod configs { + mod cometbft; + mod transfer; + + pub use cometbft::{CometClientConfig, CometClientConfigImpl, CometClientConfigTrait}; + pub use transfer::{TransferAppConfig, TransferAppConfigImpl, TransferAppConfigTrait}; +} +pub mod dummies { + mod core; + mod transfer; + + pub use core::{ + HEIGHT, CLIENT, CLIENT_TYPE, CLIENT_ID, PORT_ID, CHANNEL_ID, SEQUENCE, CHANNEL_END + }; + pub use transfer::{ + NAME, SYMBOL, PUBKEY, AMOUNT, SUPPLY, OWNER, STARKNET, COSMOS, SALT, DECIMALS, CLASS_HASH, + EMPTY_MEMO + }; +} +pub mod event_spy { + mod client; + mod transfer; + + pub use client::ClientEventSpyExt; + pub use transfer::{TransferEventSpyExtImpl, TransferEventSpyExt}; +} +pub mod handles { + mod app; + mod client; + mod core; + mod erc20; + + pub use app::{AppContract, AppHandleImpl, AppHandle}; + pub use client::{ClientHandleImpl, ClientHandle}; + pub use core::{CoreContract, CoreHandleImpl, CoreHandle}; + pub use erc20::{ERC20HandleImpl, ERC20Handle}; +} diff --git a/cairo-contracts/packages/core/src/tests/mocks/mock_channel.cairo b/cairo-contracts/packages/testkit/src/mocks/channel.cairo similarity index 96% rename from cairo-contracts/packages/core/src/tests/mocks/mock_channel.cairo rename to cairo-contracts/packages/testkit/src/mocks/channel.cairo index 23af99ee..1ec0527d 100644 --- a/cairo-contracts/packages/core/src/tests/mocks/mock_channel.cairo +++ b/cairo-contracts/packages/testkit/src/mocks/channel.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -pub(crate) mod MockChannelHandler { +pub mod MockChannelHandler { use starknet_ibc_core::channel::{ChannelHandlerComponent, ChannelEventEmitterComponent}; component!( diff --git a/cairo-contracts/packages/core/src/tests/mocks/mock_client.cairo b/cairo-contracts/packages/testkit/src/mocks/client.cairo similarity index 96% rename from cairo-contracts/packages/core/src/tests/mocks/mock_client.cairo rename to cairo-contracts/packages/testkit/src/mocks/client.cairo index 107b1676..7def7501 100644 --- a/cairo-contracts/packages/core/src/tests/mocks/mock_client.cairo +++ b/cairo-contracts/packages/testkit/src/mocks/client.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -pub(crate) mod MockClientHandler { +pub mod MockClientHandler { use starknet_ibc_core::client::{ClientHandlerComponent, ClientEventEmitterComponent}; component!( diff --git a/cairo-contracts/packages/clients/src/tests/mocks/mock_cometbft.cairo b/cairo-contracts/packages/testkit/src/mocks/cometbft.cairo similarity index 96% rename from cairo-contracts/packages/clients/src/tests/mocks/mock_cometbft.cairo rename to cairo-contracts/packages/testkit/src/mocks/cometbft.cairo index 595677e2..ec7d7302 100644 --- a/cairo-contracts/packages/clients/src/tests/mocks/mock_cometbft.cairo +++ b/cairo-contracts/packages/testkit/src/mocks/cometbft.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -pub(crate) mod MockCometClient { +pub mod MockCometClient { use starknet_ibc_clients::cometbft::CometClientComponent; component!(path: CometClientComponent, storage: client, event: CometClientEvent); diff --git a/cairo-contracts/packages/apps/src/tests/mocks/mock_transfer.cairo b/cairo-contracts/packages/testkit/src/mocks/transfer.cairo similarity index 99% rename from cairo-contracts/packages/apps/src/tests/mocks/mock_transfer.cairo rename to cairo-contracts/packages/testkit/src/mocks/transfer.cairo index 4fbef450..2582e0d9 100644 --- a/cairo-contracts/packages/apps/src/tests/mocks/mock_transfer.cairo +++ b/cairo-contracts/packages/testkit/src/mocks/transfer.cairo @@ -1,5 +1,5 @@ #[starknet::contract] -pub(crate) mod MockTransferApp { +pub mod MockTransferApp { use openzeppelin_access::ownable::OwnableComponent; use starknet::ClassHash; use starknet::ContractAddress; diff --git a/cairo-contracts/packages/contracts/src/tests/setup.cairo b/cairo-contracts/packages/testkit/src/setup.cairo similarity index 92% rename from cairo-contracts/packages/contracts/src/tests/setup.cairo rename to cairo-contracts/packages/testkit/src/setup.cairo index 7b52e156..16357490 100644 --- a/cairo-contracts/packages/contracts/src/tests/setup.cairo +++ b/cairo-contracts/packages/testkit/src/setup.cairo @@ -3,12 +3,12 @@ use snforge_std::{ start_cheat_block_timestamp_global, start_cheat_block_number_global, ContractClass }; use starknet::ContractAddress; -use starknet_ibc_apps::tests::OWNER; use starknet_ibc_apps::transfer::ERC20Contract; -use starknet_ibc_contracts::tests::{ - AppContract, CoreContract, CoreHandle, ClientHandle, ERC20Handle, AppHandle -}; use starknet_ibc_core::client::ClientContract; +use starknet_ibc_testkit::dummies::OWNER; +use starknet_ibc_testkit::handles::{ + AppContract, CoreContract, CoreHandle, AppHandle, ERC20Handle, ClientHandle +}; #[derive(Drop, Serde)] pub struct Setup {