From 21dbe292169e70b4752e0237012f2fc0898a3fbf Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Thu, 16 Jan 2025 13:27:22 -0500 Subject: [PATCH] chore: track queries --- multichain-testing/test/ibc-transfers.ts | 117 +++++++++++++++++++++-- multichain-testing/tools/agd-lib.js | 14 ++- 2 files changed, 123 insertions(+), 8 deletions(-) diff --git a/multichain-testing/test/ibc-transfers.ts b/multichain-testing/test/ibc-transfers.ts index a1530be4c33..d49f2deec70 100644 --- a/multichain-testing/test/ibc-transfers.ts +++ b/multichain-testing/test/ibc-transfers.ts @@ -1,12 +1,15 @@ 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; @@ -14,6 +17,40 @@ 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'; @@ -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) => { + const results: Record = {}; + 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, + 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', @@ -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; @@ -151,6 +245,10 @@ 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( [ @@ -158,7 +256,7 @@ test('pfm: osmosis -> agoric -> gaia', async t => { 'transfer', 'transfer', osmosisToAgoric.channelId, - 'agoric1ujmk0492mauq2f2vrcn7ylq3w3x55k0ap9mt2p', // consider using an agoric intermediary address + agoricAddr, `50${denomOnOsmosis}`, '--memo', `'${JSON.stringify(forwardInfo)}'`, @@ -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); }); diff --git a/multichain-testing/tools/agd-lib.js b/multichain-testing/tools/agd-lib.js index 68221d8b32f..f9bc2931460 100644 --- a/multichain-testing/tools/agd-lib.js +++ b/multichain-testing/tools/agd-lib.js @@ -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', @@ -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'], });