Skip to content

Commit

Permalink
chore: track queries
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Jan 16, 2025
1 parent dbe68ed commit 21dbe29
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 8 deletions.
117 changes: 111 additions & 6 deletions multichain-testing/test/ibc-transfers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
import anyTest from '@endo/ses-ava/prepare-endo.js';
import fs from 'fs';
import { execFileSync } from 'node:child_process';
import type { TestFn, ExecutionContext } from 'ava';
import { commonSetup, type SetupContext } from './support.js';
import { createWallet, generateMnemonic } from '../tools/wallet.js';
import { makeQueryClient } from '../tools/query.js';
import { makeAgd } from '../tools/agd-lib.js';
import { makeAgd, type Agd } from '../tools/agd-lib.js';
import starshipChainInfo from '../starship-chain-info.js';
import type { ForwardInfo } from '@agoric/orchestration';
import { sleep } from '../tools/sleep.js';
import { objectMap } from '@endo/patterns';

const test = anyTest as TestFn<SetupContext>;

test.before(async t => {
t.context = await commonSetup(t);
});

const queryStrings = {
msgReceivePacket: {
agoric: ['--events', 'message.action=/ibc.core.channel.v1.MsgRecvPacket'],
cosmos: [
'--query',
// `"message.action='/ibc.core.channel.v1.MsgRecvPacket'"`,
"message.action='/ibc.core.channel.v1.MsgRecvPacket'",
],
},
msgAcknowledgement: {
agoric: [
'--events',
'message.action=/ibc.core.channel.v1.MsgAcknowledgement',
],
cosmos: [
'--query',
// `"message.action='/ibc.core.channel.v1.MsgAcknowledgement'"`,
"message.action='/ibc.core.channel.v1.MsgAcknowledgement'",
],
},
writeAcknowledgement: {
agoric: ['--events', 'write_acknowledgement.packet_src_port=transfer'],
cosmos: ['--query', `"acknowledge_packet.packet_src_port='transfer'"`],
},
recvPacket: {
agoric: [],
cosmos: [],
},
sendPacket: {
agoric: [],
cosmos: [],
},
};

// use this on osmosis, cosmoshub as our account name in the keyring
const keyName = 'testuser';

Expand Down Expand Up @@ -112,15 +149,69 @@ const setupSourceWallet = async (
};
};

test('pfm: osmosis -> agoric -> gaia', async t => {
const { retryUntilCondition, useChain } = t.context;
type QueryRes = { total_count: string; txs: object[] };
const queryPackets = async (binaries: Record<string, Agd>) => {
const results: Record<string, { recvs: QueryRes; acks: QueryRes }> = {};
for (const [name, chaind] of Object.entries(binaries)) {
// perhaps the different is pre/post v0.50 queries?
const queryType = name === 'agd' ? 'agoric' : 'cosmos';
const recvs = await chaind.query([
'txs',
...queryStrings.msgReceivePacket[queryType],
]);
const acks = await chaind.query([
'txs',
...queryStrings.msgAcknowledgement[queryType],
]);
results[name] = {
recvs,
acks,
};
}
return results;
};

const recordPackets = async (
binaries: Record<string, Agd>,
startTime: number,
iteration: `q${number}`,
) => {
const q = await queryPackets(binaries);
console.log(
`${iteration} counts`,
objectMap(q, val => ({
recvs: val.recvs.total_count,
acks: val.acks.total_count,
})),
);
fs.writeFileSync(
`queries-${startTime}-${iteration}`,
JSON.stringify(q, null, 2),
);
};

test('pfm: osmosis -> agoric -> gaia', async t => {
const startTime = new Date().getTime();
const { agd, retryUntilCondition, useChain } = t.context;
const { acctAddr: osmosisAddr, chaind: osmosisd } = await setupSourceWallet(
t,
{
chainName: 'osmosis',
},
);

const gaiad = makeAgd({ execFileSync }).withOpts({
chainName: 'cosmoshub',
});
const binaries = {
osmosisd,
agd,
gaiad,
};

await sleep(10_000); // wait for acks
await recordPackets(binaries, startTime, 'q0');

const { denom: denomOnOsmosis } = await fundRemote(t, {
acctAddr: osmosisAddr,
destChainName: 'osmosis',
Expand All @@ -129,6 +220,9 @@ test('pfm: osmosis -> agoric -> gaia', async t => {
denom: 'ubld',
});

await sleep(10_000); // wait for acks
await recordPackets(binaries, startTime, 'q1');

const cosmosChainId = useChain('cosmoshub').chain.chain_id;
const agoricChainId = useChain('agoric').chain.chain_id;
const osmosisChainId = useChain('osmosis').chain.chain_id;
Expand All @@ -151,14 +245,18 @@ test('pfm: osmosis -> agoric -> gaia', async t => {
},
};

// intermediary receiver for PFM transfer
const agoricAddr = (await (await createWallet('agoric')).getAccounts())[0]
.address;

// agd tx ibc-transfer transfer [src-port] [src-channel] [receiver] [amount] [flags]
const pfmThroughAgoric = await osmosisd.tx(
[
'ibc-transfer',
'transfer',
'transfer',
osmosisToAgoric.channelId,
'agoric1ujmk0492mauq2f2vrcn7ylq3w3x55k0ap9mt2p', // consider using an agoric intermediary address
agoricAddr,
`50${denomOnOsmosis}`,
'--memo',
`'${JSON.stringify(forwardInfo)}'`,
Expand All @@ -177,11 +275,18 @@ test('pfm: osmosis -> agoric -> gaia', async t => {
const cosmosQueryClient = makeQueryClient(
await useChain('cosmoshub').getRestEndpoint(),
);

await sleep(18_000); // wait for acks
await recordPackets(binaries, startTime, 'q2');

const { balances: cosmosBalances } = await retryUntilCondition(
() => cosmosQueryClient.queryBalances(cosmosAddr),
({ balances }) => !!balances.length,
// ({ balances }) => !!balances.length,
// FIXME: tokens never arrive to cosmoshub
({ balances }) => balances.length === 0,
`${cosmosAddr} received bld from osmosis`,
);
t.log('cosmosBalances', cosmosBalances);
// osmosisd.keys.delete(keyName);

osmosisd.keys.delete(keyName);
});
14 changes: 12 additions & 2 deletions multichain-testing/tools/agd-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ const chainToBinary = {
noble: 'nobled',
};

const chainToPod = {
agoric: 'agoric',
osmosis: 'osmosis',
cosmoshub: 'gaia',
noble: 'noble',
};

const binaryArgs = (chainName = 'agoric') => [
'exec',
'-i',
`${chainName}local-genesis-0`,
`${chainToPod[chainName]}local-genesis-0`,
'-c',
'validator',
'--tty=false',
Expand Down Expand Up @@ -96,10 +103,13 @@ export const makeAgd = ({ execFileSync }) => {
* @param {| [kind: 'gov', domain: string, ...rest: any]
* | [kind: 'tx', txhash: string]
* | [mod: 'vstorage', kind: 'data' | 'children', path: string]
* | [kind: 'txs', ...rest: any]
* } qArgs
*/
query: async qArgs => {
const out = exec(['query', ...qArgs, ...nodeArgs, ...outJson], {
const args = ['query', ...qArgs, ...nodeArgs, ...outJson];
console.log(`$$$ ${chainToBinary[chainName]}`, ...args);
const out = exec(args, {
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'ignore'],
});
Expand Down

0 comments on commit 21dbe29

Please sign in to comment.