Skip to content

Commit

Permalink
Add source callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Feb 19, 2024
1 parent 51a7a9e commit d3b960e
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion packages/vm/src/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,8 @@ mod tests {
Empty, Event, IbcAcknowledgement, IbcOrder, Reply, ReplyOn, SubMsgResponse,
SubMsgResult,
};
static CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
const CONTRACT: &[u8] = include_bytes!("../testdata/ibc_reflect.wasm");
const IBC_CALLBACKS: &[u8] = include_bytes!("../testdata/ibc_callbacks.wasm");
const IBC_VERSION: &str = "ibc-reflect-v1";
fn setup(
instance: &mut Instance<MockApi, MockStorage, MockQuerier>,
Expand Down Expand Up @@ -1020,5 +1021,58 @@ mod tests {
.unwrap()
.unwrap();
}
#[test]
fn call_ibc_source_chain_callback_works() {
let mut instance = mock_instance(IBC_CALLBACKS, &[]);

// init
let creator = instance.api().addr_make("creator");
let info = mock_info(&creator, &[]);
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, br#"{}"#)
.unwrap()
.unwrap();

/// Response type for the `callback_stats` query
#[derive(serde::Serialize, serde::Deserialize)]
struct CallbackStats {
pub ibc_ack_callbacks: Vec<IbcPacketAckMsg>,
pub ibc_timeout_callbacks: Vec<IbcPacketTimeoutMsg>,
}

// send ack callback
let ack = IbcAcknowledgement::new(br#"{}"#);
let msg = IbcSourceChainCallbackMsg::Acknowledgement(
mock_ibc_packet_ack(CHANNEL_ID, br#"{}"#, ack).unwrap(),
);
call_ibc_source_chain_callback::<_, _, _, Empty>(&mut instance, &mock_env(), &msg)
.unwrap()
.unwrap();
// query the CallbackStats
let stats: CallbackStats = serde_json::from_slice(
&call_query::<_, _, _>(&mut instance, &mock_env(), br#"{"callback_stats":{}}"#)
.unwrap()
.unwrap(),
)
.unwrap();
assert_eq!(1, stats.ibc_ack_callbacks.len());
assert_eq!(0, stats.ibc_timeout_callbacks.len());

// send timeout callback
let msg = IbcSourceChainCallbackMsg::Timeout(
mock_ibc_packet_timeout(CHANNEL_ID, br#"{}"#).unwrap(),
);
call_ibc_source_chain_callback::<_, _, _, Empty>(&mut instance, &mock_env(), &msg)
.unwrap()
.unwrap();
// query the CallbackStats
let stats: CallbackStats = serde_json::from_slice(
&call_query::<_, _, _>(&mut instance, &mock_env(), br#"{"callback_stats":{}}"#)
.unwrap()
.unwrap(),
)
.unwrap();
assert_eq!(1, stats.ibc_ack_callbacks.len());
assert_eq!(1, stats.ibc_timeout_callbacks.len());
}
}
}

0 comments on commit d3b960e

Please sign in to comment.