-
Notifications
You must be signed in to change notification settings - Fork 371
Add new entrypoint for IBCv2 Timeout #2435
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
Open
vishalmaurya850
wants to merge
10
commits into
CosmWasm:main
Choose a base branch
from
vishalmaurya850:add-ibcv2-timeout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52be1ad
Add new entrypoint for IBCv2 Timeout
vishalmaurya850 005250d
Add test for `ibc2_timeout` entry point function
vishalmaurya850 145d277
Add `do_ibc2_timeout` function to imports in `contracts/ibc2/src/cont…
vishalmaurya850 5117405
Add `do_ibc2_timeout` function to handle IBCv2 timeouts
vishalmaurya850 15e9379
Add `ibc2_timeout` entry point function to handle IBCv2 timeouts
vishalmaurya850 1e47fef
Add `ibc2_timeout` entry point and tests
vishalmaurya850 f7210ad
Add `ibc2_timeout` entry point function and update imports in `contra…
vishalmaurya850 2e28e24
Add `do_ibc2_timeout` function to imports in `contract.rs`
vishalmaurya850 d1d8bee
Add `ibc2_timeout` entry point function to handle IBCv2 timeouts
vishalmaurya850 f7c1627
Add `ibc2_timeout` entry point function and update `State` struct
vishalmaurya850 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,16 @@ use serde::{Deserialize, Serialize}; | |
#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
pub struct State { | ||
ibc2_packet_receive_counter: u32, | ||
ibc2_timeout_counter: u32, | ||
} | ||
|
||
#[cw_serde] | ||
#[derive(QueryResponses)] | ||
pub enum QueryMsg { | ||
#[returns(State)] | ||
QueryState {}, | ||
#[returns(u32)] | ||
QueryTimeoutCounter {}, | ||
} | ||
|
||
const STATE_KEY: &[u8] = b"state"; | ||
|
@@ -43,6 +46,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<QueryResponse> { | |
.ok_or_else(|| StdError::generic_err("State not found."))?; | ||
Ok(Binary::from(data)) | ||
} | ||
QueryMsg::QueryTimeoutCounter {} => { | ||
let data = deps | ||
.storage | ||
.get(STATE_KEY) | ||
.ok_or_else(|| StdError::generic_err("State not found."))?; | ||
let state: State = from_json(data)?; | ||
Ok(to_json_vec(&state.ibc2_timeout_counter)?.into()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -61,6 +72,29 @@ pub fn ibc2_packet_receive( | |
STATE_KEY, | ||
&to_json_vec(&State { | ||
ibc2_packet_receive_counter: state.ibc2_packet_receive_counter + 1, | ||
ibc2_timeout_counter: state.ibc2_timeout_counter, | ||
})?, | ||
); | ||
|
||
Ok(IbcReceiveResponse::new([1, 2, 3])) | ||
} | ||
|
||
#[entry_point] | ||
pub fn ibc2_timeout( | ||
deps: DepsMut, | ||
_env: Env, | ||
_msg: Ibc2PacketReceiveMsg, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs its own type. |
||
) -> StdResult<IbcReceiveResponse> { | ||
let data = deps | ||
.storage | ||
.get(STATE_KEY) | ||
.ok_or_else(|| StdError::generic_err("State not found."))?; | ||
let state: State = from_json(data)?; | ||
deps.storage.set( | ||
STATE_KEY, | ||
&to_json_vec(&State { | ||
ibc2_packet_receive_counter: state.ibc2_packet_receive_counter, | ||
ibc2_timeout_counter: state.ibc2_timeout_counter + 1, | ||
})?, | ||
); | ||
|
||
|
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 +1,32 @@ | ||
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; | ||
use cosmwasm_std::{ | ||
from_binary, Empty, Ibc2PacketReceiveMsg, IbcReceiveResponse, Response, StdError, | ||
}; | ||
|
||
use crate::contract::{ibc2_packet_receive, ibc2_timeout, instantiate, query}; | ||
use crate::contract::{QueryMsg, State}; | ||
|
||
#[test] | ||
fn test_ibc2_timeout() { | ||
let mut deps = mock_dependencies(); | ||
let env = mock_env(); | ||
let info = mock_info("sender", &[]); | ||
|
||
// Instantiate the contract | ||
let msg = Empty {}; | ||
let res = instantiate(deps.as_mut(), env.clone(), info, msg).unwrap(); | ||
assert_eq!(res, Response::new()); | ||
|
||
// Call ibc2_timeout multiple times and verify the timeout counter increments correctly | ||
let msg = Ibc2PacketReceiveMsg::default(); | ||
for i in 1..=3 { | ||
let res: IbcReceiveResponse = | ||
ibc2_timeout(deps.as_mut(), env.clone(), msg.clone()).unwrap(); | ||
assert_eq!(res, IbcReceiveResponse::new([1, 2, 3])); | ||
|
||
let query_msg = QueryMsg::QueryTimeoutCounter {}; | ||
let query_res = query(deps.as_ref(), env.clone(), query_msg).unwrap(); | ||
let timeout_counter: u32 = from_binary(&query_res).unwrap(); | ||
assert_eq!(timeout_counter, i); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't really a need for this query, since the
QueryState
already contains the timeout counter.