-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: define Setup struct to streamline test setups
- Loading branch information
1 parent
22c13b2
commit 09f2032
Showing
12 changed files
with
145 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use openzeppelin_testing::declare_class; | ||
use snforge_std::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_core::tests::CLIENT_TYPE; | ||
|
||
#[derive(Drop, Serde)] | ||
pub struct Setup { | ||
pub owner: ContractAddress, | ||
pub erc20_contract_class: ContractClass | ||
} | ||
|
||
#[generate_trait] | ||
pub impl SetupImpl of SetupTrait { | ||
/// Initializes the test setup with default values. | ||
fn default() -> Setup { | ||
Setup { owner: OWNER(), erc20_contract_class: declare_class("ERC20Mintable"), } | ||
} | ||
|
||
/// Deploys an instance of IBC core contract. | ||
fn deploy_core(self: @Setup) -> CoreContract { | ||
CoreHandle::deploy() | ||
} | ||
|
||
/// Deploys an instance of CometBFT client contract. | ||
fn deploy_cometbft(self: @Setup, ref core: CoreContract) -> ClientContract { | ||
// Deploy a Comet client contract. | ||
let comet = ClientHandle::deploy_cometbft(); | ||
|
||
// Register the Comet client into the IBC core contract. | ||
core.register_client(CLIENT_TYPE(), comet.address); | ||
|
||
comet | ||
} | ||
|
||
/// Deploys an instance of ERC20 contract. | ||
fn deploy_erc20(self: @Setup) -> ERC20Contract { | ||
ERC20Handle::deploy(*self.erc20_contract_class) | ||
} | ||
|
||
/// Deploys an instance of ICS-20 Token Transfer contract. | ||
fn deploy_trasnfer(self: @Setup) -> AppContract { | ||
AppHandle::deploy_transfer(self.owner.clone(), *self.erc20_contract_class) | ||
} | ||
} | ||
|
61 changes: 28 additions & 33 deletions
61
cairo-contracts/packages/contracts/src/tests/test_channel.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
use openzeppelin_testing::declare_class; | ||
use starknet_ibc_apps::tests::{TransferAppConfigTrait, OWNER}; | ||
use starknet_ibc_apps::transfer::ERC20Contract; | ||
use starknet_ibc_contracts::tests::{ | ||
ClientHandle, ERC20Handle, AppHandle, AppContract, CoreContract, CoreHandle | ||
}; | ||
use starknet_ibc_core::client::ClientContract; | ||
|
||
// Deploys an instance of IBC core, Cometbft ligth client, and Token Transfer | ||
// applicaiton contracts, and registers the client and application into the core | ||
// contract. | ||
fn setup_contracts( | ||
client_type: felt252 | ||
) -> (CoreContract, ClientContract, AppContract, ERC20Contract) { | ||
// Deploy an IBC core contract. | ||
let mut core = CoreHandle::setup(); | ||
|
||
// Deploy a Comet client contract. | ||
let comet = ClientHandle::setup_cometbft(); | ||
|
||
// Register the Comet client into the IBC core contract. | ||
core.register_client(client_type, comet.address); | ||
|
||
// Declare the ERC20 contract class. | ||
let erc20_contract_class = declare_class("ERC20Mintable"); | ||
|
||
// Deploy an ERC20 contract. | ||
let mut erc20 = ERC20Handle::setup(erc20_contract_class); | ||
|
||
// Deploy an ICS20 Token Transfer contract. | ||
let mut ics20 = AppHandle::setup_transfer(OWNER(), erc20_contract_class); | ||
|
||
(core, comet, ics20, erc20) | ||
use starknet_ibc_apps::tests::{TransferAppConfigTrait, COSMOS, STARKNET}; | ||
use starknet_ibc_contracts::tests::{SetupImpl, CoreHandle}; | ||
|
||
#[test] | ||
#[should_panic] | ||
fn test_recv_packet_ok() { | ||
// ----------------------------------------------------------- | ||
// Setup Essentials | ||
// ----------------------------------------------------------- | ||
|
||
let mut transfer_cfg = TransferAppConfigTrait::default(); | ||
|
||
let setup = SetupImpl::default(); | ||
|
||
let mut core = setup.deploy_core(); | ||
|
||
let _comet = setup.deploy_cometbft(ref core); | ||
|
||
let _ics20 = setup.deploy_trasnfer(); | ||
|
||
// ----------------------------------------------------------- | ||
// Receive Packet | ||
// ----------------------------------------------------------- | ||
|
||
let msg = transfer_cfg | ||
.dummy_msg_recv_packet(transfer_cfg.hosted_denom.clone(), COSMOS(), STARKNET()); | ||
|
||
core.recv_packet(msg); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.