Skip to content

Commit

Permalink
Clean up and get basic test case working
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Aug 6, 2022
1 parent 03db894 commit 4d490f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
1 change: 1 addition & 0 deletions contracts/cw-ibc-queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn execute(
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
cw_utils::nonpayable(&info)?;
match msg {
ExecuteMsg::IbcQuery {
channel_id,
Expand Down
5 changes: 4 additions & 1 deletion contracts/cw-ibc-queries/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thiserror::Error;

use cosmwasm_std::StdError;
use cw_utils::ParseReplyError;
use cw_utils::{ParseReplyError, PaymentError};

use cw_ibc_query::SimpleIcaError;

Expand All @@ -13,6 +13,9 @@ pub enum ContractError {
#[error("{0}")]
ParseReply(#[from] ParseReplyError),

#[error("{0}")]
Payment(#[from] PaymentError),

#[error("{0}")]
SimpleIca(#[from] SimpleIcaError),

Expand Down
4 changes: 0 additions & 4 deletions contracts/cw-ibc-queries/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ pub fn ibc_channel_close(
}

#[entry_point]
/// we look for a the proper reflect contract to relay to and send the message
/// We cannot return any meaningful response value as we do not know the response value
/// of execution. We just return ok if we dispatched, error if we failed to dispatch
pub fn ibc_packet_receive(
deps: DepsMut,
_env: Env,
Expand Down Expand Up @@ -125,7 +122,6 @@ pub fn ibc_packet_ack(
}

#[entry_point]
/// never should be called as we do not send packets
pub fn ibc_packet_timeout(
_deps: DepsMut,
_env: Env,
Expand Down
70 changes: 59 additions & 11 deletions tests/src/cosmwasm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CosmWasmSigner, Link, testutils } from "@confio/relayer";
import { toBase64, toUtf8 } from "@cosmjs/encoding";
// import { toBase64, toUtf8 } from "@cosmjs/encoding";
import { fromBase64, fromUtf8 } from "@cosmjs/encoding";
import { assert } from "@cosmjs/utils";
import test from "ava";
import { Order } from "cosmjs-types/ibc/core/channel/v1/channel";

const { osmosis: oldOsmo, setup, wasmd } = testutils;
const osmosis = { ...oldOsmo, minFee: "0.025uosmo" };

import { assertPacketsFromA, IbcVersion, setupContracts, setupOsmosisClient, setupWasmClient } from "./utils";
import { IbcVersion, setupContracts, setupOsmosisClient, setupWasmClient } from "./utils";

let wasmIds: Record<string, number> = {};
let osmosisIds: Record<string, number> = {};
Expand Down Expand Up @@ -74,6 +75,10 @@ interface SetupInfo {
wasm: string;
osmo: string;
};
channelIds: {
wasm: string;
osmo: string;
};
}

async function demoSetup(): Promise<SetupInfo> {
Expand Down Expand Up @@ -104,16 +109,19 @@ async function demoSetup(): Promise<SetupInfo> {
// create a connection and channel for simple-ica
const [src, dest] = await setup(wasmd, osmosis);
const link = await Link.createWithNewConnections(src, dest);
await link.createChannel("A", controllerPort, hostPort, Order.ORDER_UNORDERED, IbcVersion);
const channelInfo = await link.createChannel("A", controllerPort, hostPort, Order.ORDER_UNORDERED, IbcVersion);
const channelIds = {
wasm: channelInfo.src.channelId,
osmo: channelInfo.src.channelId,
};

// also create a ics20 channel on this connection
const ics20Info = await link.createChannel("A", wasmd.ics20Port, osmosis.ics20Port, Order.ORDER_UNORDERED, "ics20-1");
const ics20 = {
wasm: ics20Info.src.channelId,
osmo: ics20Info.dest.channelId,
};

console.log(ics20);
console.log(ics20Info);

return {
wasmClient,
Expand All @@ -122,23 +130,26 @@ async function demoSetup(): Promise<SetupInfo> {
osmoHost,
link,
ics20,
channelIds,
};
}

test.serial("query remote chain", async () => {
const { wasmClient, wasmController, osmoHost, ics20, link } = await demoSetup();
test.serial("query remote chain", async (t) => {
const { osmoClient, wasmClient, wasmController, link, channelIds } = await demoSetup();

// Use IBC queries to query info from the remote contract
const ibcQuery = await wasmClient.sign.execute(
wasmClient.senderAddress,
wasmController,
{
ibc_query: {
channel_id: ics20.osmo,
channel_id: channelIds.wasm,
msgs: [
{
wasm: {
smart: { msg: toBase64(toUtf8(JSON.stringify({ latest_query_result: {} }))), contract_addr: osmoHost },
bank: {
all_balances: {
address: osmoClient.senderAddress,
},
},
},
],
Expand All @@ -150,5 +161,42 @@ test.serial("query remote chain", async () => {

// relay this over
const info = await link.relayAll();
assertPacketsFromA(info, 1, true);
console.log(info);
console.log(fromUtf8(info.acksFromB[0].acknowledgement));
// assertPacketsFromA(info1, 1, true);

const result = await wasmClient.sign.queryContractSmart(wasmController, {
latest_query_result: {
channel_id: channelIds.wasm,
},
});

console.log(result);
console.log(fromUtf8(fromBase64(result.response.acknowledgement.data)));
t.truthy(result);

// // Use IBC queries to query info from the remote contract
// const ibcQuery = await wasmClient.sign.execute(
// wasmClient.senderAddress,
// wasmController,
// {
// ibc_query: {
// channel_id: channelIds.wasm,
// msgs: [
// {
// wasm: {
// smart: {
// msg: toBase64(toUtf8(JSON.stringify({ latest_query_result: { channel_id: channelIds.osmo } }))),
// contract_addr: osmoHost,
// },
// },
// },
// ],
// },
// },
// "auto"
// );
// // relay this over
// const info = await link.relayAll();
// assertPacketsFromA(info, 1, true);
});

0 comments on commit 4d490f8

Please sign in to comment.