Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Sep 22, 2022
1 parent 1f8fd95 commit 51daa15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
6 changes: 2 additions & 4 deletions contracts/cw20-ics20/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ beforeAll(async () => {
contracts.ics20.address = MsgInstantiateContractResponse.decode(tx.data[0]).address;
contracts.ics20.ibcPortId = "wasm." + contracts.ics20.address;

console.log("Waiting IBC connection...");
console.log("Waiting for IBC connection...");
const link = await linkPromise;

console.log("Creating IBC channel...");
Expand Down Expand Up @@ -281,9 +281,7 @@ test(
address: accounts2[1].address,
});

if (balance) {
expect(balance.amount).toBe("1");
expect(balance.denom).toBe(expectedIbcDenom);
if (balance?.amount === "1") {
break;
}

Expand Down
45 changes: 20 additions & 25 deletions contracts/cw20-ics20/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ export async function createIbcConnection(): Promise<Link> {
prefix: "secret",
gasPrice: GasPrice.fromString("0.25uscrt"),
estimatedBlockTime: 5750,
estimatedIndexerTime: 1000,
estimatedIndexerTime: 500,
});
console.group("IBC client for chain A");
console.log(JSON.stringify(clientA));
console.groupEnd();
// console.group("IBC client for chain A");
// console.log(JSON.stringify(clientA));
// console.groupEnd();

// Create IBC Client for chain A
const clientB = await IbcClient.connectWithSigner("http://localhost:36657", signerB, signerB.address, {
Expand All @@ -123,50 +123,45 @@ export async function createIbcConnection(): Promise<Link> {
estimatedBlockTime: 5750,
estimatedIndexerTime: 500,
});
console.group("IBC client for chain B");
console.log(JSON.stringify(clientB));
console.groupEnd();
// console.group("IBC client for chain B");
// console.log(JSON.stringify(clientB));
// console.groupEnd();

// Create new connectiosn for the 2 clients
const link = await Link.createWithNewConnections(clientA, clientB);

console.group("IBC link details");
console.log(JSON.stringify(link));
console.groupEnd();
// console.group("IBC link details");
// console.log(JSON.stringify(link));
// console.groupEnd();

return link;
}
export async function createIbcChannel(link: Link, contractPort: string): Promise<ChannelPair> {
const options = { poll: 5000, maxAgeDest: 86400, maxAgeSrc: 86400 };

await link.updateClientIfStale("A", options.maxAgeDest);
await link.updateClientIfStale("B", options.maxAgeSrc);
await Promise.all([link.updateClient("A"), link.updateClient("B")]);

// Create a channel for the connections
const channels = await link.createChannel("A", contractPort, "transfer", Order.ORDER_UNORDERED, "ics20-1");

console.group("IBC channel details");
console.log(JSON.stringify(channels));
console.groupEnd();
// console.group("IBC channel details");
// console.log(JSON.stringify(channels));
// console.groupEnd();

return channels;
}

export async function loopRelayer(link: Link) {
const options = { poll: 5000, maxAgeDest: 86400, maxAgeSrc: 86400 };
let nextRelay = {};
while (this.running) {
while (true) {
try {
nextRelay = await link.checkAndRelayPacketsAndAcks(nextRelay, 2, 6);
console.group("Next Relay:");
console.log(JSON.stringify(nextRelay));
nextRelay = await link.relayAll();
console.group("Next relay:");
console.log(nextRelay);
console.groupEnd();

await link.updateClientIfStale("A", options.maxAgeDest);
await link.updateClientIfStale("B", options.maxAgeSrc);
await Promise.all([link.updateClient("A"), link.updateClient("B")]);
} catch (e) {
console.error(`Caught error: `, e);
}
await sleep(options.poll);
await sleep(5000);
}
}

0 comments on commit 51daa15

Please sign in to comment.