-
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.
feat: scaffold connection handshake module (#110)
- Loading branch information
1 parent
c6d149f
commit a0af556
Showing
17 changed files
with
400 additions
and
8 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
71 changes: 71 additions & 0 deletions
71
cairo-contracts/packages/contracts/src/tests/connection.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use starknet_ibc_contracts::tests::channel::setup; | ||
use starknet_ibc_testkit::configs::CoreConfigTrait; | ||
use starknet_ibc_testkit::handles::CoreHandle; | ||
|
||
#[test] | ||
fn test_conn_open_init_ok() { | ||
// ----------------------------------------------------------- | ||
// Setup Essentials | ||
// ----------------------------------------------------------- | ||
|
||
let (core, _, _, core_cfg, _, _, _) = setup(); | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Open Init | ||
// ----------------------------------------------------------- | ||
|
||
let msg = core_cfg.dummy_msg_conn_open_init(); | ||
|
||
core.conn_open_init(msg.clone()); | ||
} | ||
|
||
#[test] | ||
fn test_conn_open_try_ok() { | ||
// ----------------------------------------------------------- | ||
// Setup Essentials | ||
// ----------------------------------------------------------- | ||
|
||
let (core, _, _, core_cfg, _, _, _) = setup(); | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Open Try | ||
// ----------------------------------------------------------- | ||
|
||
let msg = core_cfg.dummy_msg_conn_open_try(); | ||
|
||
core.conn_open_try(msg.clone()); | ||
} | ||
|
||
#[test] | ||
fn test_conn_open_ack_ok() { | ||
// ----------------------------------------------------------- | ||
// Setup Essentials | ||
// ----------------------------------------------------------- | ||
|
||
let (core, _, _, core_cfg, _, _, _) = setup(); | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Open Ack | ||
// ----------------------------------------------------------- | ||
|
||
let msg = core_cfg.dummy_msg_conn_open_ack(); | ||
|
||
core.conn_open_ack(msg.clone()); | ||
} | ||
|
||
#[test] | ||
fn test_conn_open_confirm_ok() { | ||
// ----------------------------------------------------------- | ||
// Setup Essentials | ||
// ----------------------------------------------------------- | ||
|
||
let (core, _, _, core_cfg, _, _, _) = setup(); | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Open Confirm | ||
// ----------------------------------------------------------- | ||
|
||
let msg = core_cfg.dummy_msg_conn_open_confirm(); | ||
|
||
core.conn_open_confirm(msg.clone()); | ||
} |
32 changes: 32 additions & 0 deletions
32
cairo-contracts/packages/core/src/connection/components/events.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[starknet::component] | ||
pub mod ConnectionEventEmitterComponent { | ||
#[storage] | ||
pub struct Storage {} | ||
|
||
#[event] | ||
#[derive(Debug, Drop, starknet::Event)] | ||
pub enum Event { | ||
ConnOpenInitEvent: ConnOpenInitEvent, | ||
ConnOpenTryEvent: ConnOpenTryEvent, | ||
ConnOpenAckEvent: ConnOpenAckEvent, | ||
ConnOpenConfirmEvent: ConnOpenConfirmEvent, | ||
} | ||
|
||
#[derive(Debug, Drop, starknet::Event)] | ||
pub struct ConnOpenInitEvent {} | ||
|
||
#[derive(Debug, Drop, starknet::Event)] | ||
pub struct ConnOpenTryEvent {} | ||
|
||
#[derive(Debug, Drop, starknet::Event)] | ||
pub struct ConnOpenAckEvent {} | ||
|
||
#[derive(Debug, Drop, starknet::Event)] | ||
pub struct ConnOpenConfirmEvent {} | ||
|
||
#[generate_trait] | ||
pub impl ConnectionEventEmitterImpl< | ||
TContractState, +HasComponent<TContractState>, +Drop<TContractState> | ||
> of ConnectinoEventEmitterTrait<TContractState> {} | ||
} | ||
|
79 changes: 79 additions & 0 deletions
79
cairo-contracts/packages/core/src/connection/components/handler.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#[starknet::component] | ||
pub mod ConnectionHandlerComponent { | ||
use starknet_ibc_core::connection::{ | ||
ConnectionEventEmitterComponent, IConnectionHandler, IConnectionQuery, MsgConnOpenAck, | ||
MsgConnOpenConfirm, MsgConnOpenInit, MsgConnOpenTry | ||
}; | ||
|
||
#[storage] | ||
pub struct Storage {} | ||
|
||
#[event] | ||
#[derive(Debug, Drop, starknet::Event)] | ||
pub enum Event {} | ||
|
||
// ----------------------------------------------------------- | ||
// IConnectionHandler | ||
// ----------------------------------------------------------- | ||
|
||
#[embeddable_as(CoreConnectionHandler)] | ||
pub impl CoreConnectionHandlerImpl< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
impl EventEmitter: ConnectionEventEmitterComponent::HasComponent<TContractState> | ||
> of IConnectionHandler<ComponentState<TContractState>> { | ||
fn conn_open_init(ref self: ComponentState<TContractState>, msg: MsgConnOpenInit) {} | ||
|
||
fn conn_open_try(ref self: ComponentState<TContractState>, msg: MsgConnOpenTry) {} | ||
|
||
fn conn_open_ack(ref self: ComponentState<TContractState>, msg: MsgConnOpenAck) {} | ||
|
||
fn conn_open_confirm(ref self: ComponentState<TContractState>, msg: MsgConnOpenConfirm) {} | ||
} | ||
|
||
// ----------------------------------------------------------- | ||
// IConnectionQuery | ||
// ----------------------------------------------------------- | ||
|
||
#[embeddable_as(CoreConnectionQuery)] | ||
impl CoreConnectionQueryImpl< | ||
TContractState, +HasComponent<TContractState>, +Drop<TContractState>, | ||
> of IConnectionQuery<ComponentState<TContractState>> {} | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Internal | ||
// ----------------------------------------------------------- | ||
|
||
#[generate_trait] | ||
pub(crate) impl ConnectionInternalImpl< | ||
TContractState, +HasComponent<TContractState>, +Drop<TContractState> | ||
> of ConnectionInternalTrait<TContractState> {} | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Reader/Writer | ||
// ----------------------------------------------------------- | ||
|
||
#[generate_trait] | ||
pub(crate) impl ConnectionReaderImpl< | ||
TContractState, +HasComponent<TContractState>, +Drop<TContractState> | ||
> of ConnectionReaderTrait<TContractState> {} | ||
|
||
#[generate_trait] | ||
pub(crate) impl ConnectionWriterImpl< | ||
TContractState, +HasComponent<TContractState>, +Drop<TContractState> | ||
> of ConnectionWriterTrait<TContractState> {} | ||
|
||
// ----------------------------------------------------------- | ||
// Connection Event Emitter | ||
// ----------------------------------------------------------- | ||
|
||
#[generate_trait] | ||
pub(crate) impl EventEmitterImpl< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
impl EventEmitter: ConnectionEventEmitterComponent::HasComponent<TContractState> | ||
> of EventEmitterTrait<TContractState> {} | ||
} | ||
|
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 @@ | ||
pub mod ConnectionErrors {} |
17 changes: 17 additions & 0 deletions
17
cairo-contracts/packages/core/src/connection/interface.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use starknet_ibc_core::connection::{ | ||
MsgConnOpenAck, MsgConnOpenConfirm, MsgConnOpenInit, MsgConnOpenTry | ||
}; | ||
|
||
#[starknet::interface] | ||
pub trait IConnectionHandler<TContractState> { | ||
fn conn_open_init(ref self: TContractState, msg: MsgConnOpenInit); | ||
|
||
fn conn_open_try(ref self: TContractState, msg: MsgConnOpenTry); | ||
|
||
fn conn_open_ack(ref self: TContractState, msg: MsgConnOpenAck); | ||
|
||
fn conn_open_confirm(ref self: TContractState, msg: MsgConnOpenConfirm); | ||
} | ||
|
||
#[starknet::interface] | ||
pub trait IConnectionQuery<TContractState> {} |
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,29 @@ | ||
use starknet_ibc_utils::ValidateBasic; | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct MsgConnOpenInit {} | ||
|
||
impl MsgConnOpenInitValidateBasic of ValidateBasic<MsgConnOpenInit> { | ||
fn validate_basic(self: @MsgConnOpenInit) {} | ||
} | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct MsgConnOpenTry {} | ||
|
||
impl MsgConnOpenTryValidateBasic of ValidateBasic<MsgConnOpenTry> { | ||
fn validate_basic(self: @MsgConnOpenTry) {} | ||
} | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct MsgConnOpenAck {} | ||
|
||
impl MsgConnOpenAckValidateBasic of ValidateBasic<MsgConnOpenAck> { | ||
fn validate_basic(self: @MsgConnOpenAck) {} | ||
} | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct MsgConnOpenConfirm {} | ||
|
||
impl MsgConnOpenConfirmValidateBasic of ValidateBasic<MsgConnOpenConfirm> { | ||
fn validate_basic(self: @MsgConnOpenConfirm) {} | ||
} |
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,14 @@ | ||
use starknet_ibc_core::host::{ClientId, ConnectionId, PathPrefix}; | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct Counterparty { | ||
pub client_id: ClientId, | ||
pub connection_id: ConnectionId, | ||
pub prefix: PathPrefix, | ||
} | ||
|
||
#[derive(Clone, Debug, Drop, PartialEq, Serde)] | ||
pub struct Version { | ||
pub identifier: ByteArray, | ||
pub features: Array<ByteArray>, | ||
} |
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.