Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement execute and query handlers #16

Merged
merged 9 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.60.0
toolchain: 1.71.1
override: true
components: rustfmt, clippy

Expand All @@ -31,13 +31,3 @@ jobs:
with:
command: clippy
args: -- -D warnings

- name: Generate Schema
uses: actions-rs/cargo@v1
with:
command: schema
args: --locked

- name: Schema Changes
# fails if any changes not committed
run: git diff --exit-code schema
17 changes: 2 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,9 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.60.0
toolchain: 1.71.1
target: wasm32-unknown-unknown
override: true

- name: Run unit tests
uses: actions-rs/cargo@v1
with:
command: unit-test
args: --locked
env:
RUST_BACKTRACE: 1

- name: Compile WASM contract
uses: actions-rs/cargo@v1
with:
command: wasm
args: --locked
env:
RUSTFLAGS: "-C link-arg=-s"
run: make test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to install cargo-nextest.

      - name: Install cargo-nextest
        uses: actions-rs/cargo@v1
        with:
          command: install
          args: cargo-nextest

Or use cargo test in the test rule in Makefile.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ cosmwasm-std = { version = "1.5.0", features = [
cw-storage-plus = "1.1.0"
cw2 = "1.1.1"
derive_more = "0.99.17"
ibc-core = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0"
ibc-clients = { git = "https://github.com/cosmos/ibc-rs", rev = "1410bb03fdba930abd31c0941a5fd7f43d13ec96", default-features = false, features = ["schema"] } # "0.50.0"
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.0"
ibc-core = { version = "0.51.0", default-features = false, features = ["schema"] }
ibc-clients = { version = "0.51.0", default-features = false, features = ["schema"] }
ibc-proto = { version = "0.42.2", default-features = false }
prost = "0.12.3"
schemars = "0.8.15"
serde = { version = "1.0", features = ["derive", "rc"] }
tendermint = "0.34.1"
tendermint-light-client-verifier = "0.34.1"
thiserror = { version = "1.0.49" }

[patch.crates-io]
ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", rev = "6cbe4c7ace5a688bc98831fa9c1cc2dabf3b2976", default-features = false } # "0.42.2"

[dev-dependencies]
cw-multi-test = "0.17.0"
21 changes: 14 additions & 7 deletions src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult};

// use cw2::set_contract_version;

Expand Down Expand Up @@ -33,17 +33,24 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<'_>,
_env: Env,
deps: DepsMut<'_>,
env: Env,
_info: MessageInfo,
_msg: SudoMsg,
msg: SudoMsg,
) -> Result<Response, ContractError> {
unimplemented!()
let mut ctx = RollkitContext::new_mut(deps, env)?;

let data = ctx.sudo(msg)?;

Ok(Response::default().set_data(data))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
unimplemented!()
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> StdResult<Binary> {
let ctx = RollkitContext::new_ref(deps, env)?;

ctx.query(msg)
.map_err(|e| StdError::generic_err(e.to_string()))
}

#[cfg(test)]
Expand Down
16 changes: 14 additions & 2 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{

impl<'a, C: ClientType<'a>> Context<'a, C> {
pub fn instantiate(&mut self, msg: InstantiateMsg) -> Result<Binary, ContractError> {
let any = Any::decode(&mut msg.client_state.as_slice())?;
let any_client_state = Any::decode(&mut msg.client_state.as_slice())?;

let client_state = C::ClientState::try_from(any)?;
let client_state = C::ClientState::try_from(any_client_state)?;

let any_consensus_state = Any::decode(&mut msg.consensus_state.as_slice())?;

Expand Down Expand Up @@ -58,9 +58,14 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {

client_state.update_state_on_misbehaviour(self, &client_id, any_client_msg)?;

// TODO: delete consensus state at misbehaviour height

ContractResult::success()
}
SudoMsg::VerifyMembership(msg) => {
// TODO: check DA light client is active
// TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp())

let msg = VerifyMembershipMsg::try_from(msg)?;

let client_cons_state_path = ClientConsensusStatePath::new(
Expand All @@ -82,6 +87,9 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {
ContractResult::success()
}
SudoMsg::VerifyNonMembership(msg) => {
// TODO: check DA light client is active
// TODO: assert(processedTime + clientState.fraudPeriod > currentTimestamp())

let msg = VerifyNonMembershipMsg::try_from(msg)?;

let client_cons_state_path = ClientConsensusStatePath::new(
Expand Down Expand Up @@ -172,6 +180,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {

client_state.verify_client_message(self, &client_id, any_client_msg)?;

// TODO: in case client message is a header, verify header proof and block data proof on the DA light client

QueryResponse::success()
}
QueryMsg::CheckForMisbehaviour(msg) => {
Expand All @@ -185,6 +195,8 @@ impl<'a, C: ClientType<'a>> Context<'a, C> {
let result =
client_state.check_for_misbehaviour(self, &client_id, any_client_msg)?;

// TODO: handle fraud proofs

QueryResponse::success().misbehaviour(result)
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use cosmwasm_schema::cw_serde;
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

//use ibc_clients::wasm_types::client_message::ClientMessage;

use ibc_core::client::types::error::ClientError;
use ibc_core::client::types::proto::v1::Height as RawHeight;
use ibc_core::client::types::Height;
Expand Down
Loading