Skip to content

Commit e81f37a

Browse files
committed
chore: implement failing IBC msg test case
Refs: #8863
1 parent 4000599 commit e81f37a

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

multichain-testing/test/xcs-swap-anything/swap-anything.test.ts

+82
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
makeIBCTransferMsg,
1212
} from '../../tools/ibc-transfer.js';
1313
import { makeHttpClient } from '../../tools/makeHttpClient.js';
14+
import type { OfferStatus } from '@agoric/smart-wallet/src/offers.js';
1415
import {
1516
fundRemote,
1617
setupXcsContracts,
@@ -341,6 +342,87 @@ test.serial('BLD for OSMO, receiver on CosmosHub', async t => {
341342
);
342343
});
343344

345+
test.serial('BLD for OSMO, receiver chain not registered to XCS, should throw', async t => {
346+
const {
347+
wallets,
348+
provisionSmartWallet,
349+
vstorageClient,
350+
retryUntilCondition,
351+
useChain,
352+
} = t.context;
353+
354+
// Provision the Agoric smart wallet
355+
const agoricAddr = wallets.agoricSender;
356+
const wdUser = await provisionSmartWallet(agoricAddr, {
357+
BLD: 1000n,
358+
IST: 1000n,
359+
});
360+
t.log(`Provisioned Agoric smart wallet for ${agoricAddr}`);
361+
362+
const apiUrl = await useChain('agoric').getRestEndpoint();
363+
const queryClient = makeQueryClient(apiUrl);
364+
365+
const brands = await vstorageClient.queryData('published.agoricNames.brand');
366+
const bldBrand = Object.fromEntries(brands).BLD;
367+
const swapInAmount = AmountMath.make(bldBrand, 125n);
368+
const { balance: bldBalanceBefore } = await queryClient.queryBalance(
369+
agoricAddr,
370+
'ubld',
371+
);
372+
373+
// Send swap offer
374+
const makeAccountOfferId = `swap-ubld-uosmo-${Date.now()}`;
375+
const updates = wdUser.offers.executeOffer({
376+
id: makeAccountOfferId,
377+
invitationSpec: {
378+
source: 'agoricContract',
379+
instancePath: [contractName],
380+
callPipe: [['makeSendInvitation']],
381+
},
382+
offerArgs: {
383+
// TODO: get the contract address dynamically
384+
destAddr:
385+
'osmo17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs5yczr8',
386+
receiverAddr: 'noble/noble1foo',
387+
outDenom: 'uosmo',
388+
slippage: { slippagePercentage: '20', windowSeconds: 10 },
389+
onFailedDelivery: 'do_nothing',
390+
},
391+
proposal: { give: { Send: swapInAmount } },
392+
});
393+
394+
const {
395+
// @ts-expect-error types
396+
value: {
397+
status: { error: errorMsg },
398+
},
399+
} = await retryUntilCondition(
400+
// Prevent test from hanging when no new values are coming from updates.next()
401+
() =>
402+
Promise.race([
403+
updates.next(),
404+
new Promise(resolve =>
405+
setTimeout(async () => {
406+
await updates.return();
407+
resolve('Done');
408+
}, 5000),
409+
),
410+
]),
411+
(result: { value: { updated: string; status: OfferStatus } }) => {
412+
return result.value.status.error !== undefined;
413+
},
414+
'Offer result did not fail as expect ed',
415+
);
416+
417+
const { balance: bldBalanceAfter } = await queryClient.queryBalance(
418+
agoricAddr,
419+
'ubld',
420+
);
421+
422+
t.deepEqual(bldBalanceBefore, bldBalanceAfter);
423+
t.regex(errorMsg, /^Error: IBC Transfer failed/);
424+
});
425+
344426
/**
345427
* UNTIL https://github.com/Agoric/BytePitchPartnerEng/issues/51, we are skipping this
346428
* until the ticket above is done

packages/orchestration/src/examples/swap-anything.contract.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const contract = async (
5151
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9066
5252
const logNode = E(privateArgs.storageNode).makeChildNode('log');
5353
/** @type {(msg: string) => Vow<void>} */
54-
const log = msg =>
55-
vowTools.watch(E(logNode).setValue(JSON.stringify({ msg })));
54+
const log = (msg, level = 'info') =>
55+
vowTools.watch(E(logNode).setValue(JSON.stringify({ msg, level })));
5656

5757
const makeLocalAccount = orchestrate(
5858
'makeLocalAccount',

packages/orchestration/src/examples/swap-anything.flows.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const buildXCSMemo = swapInfo => {
7070
* @param {GuestInterface<ChainHub>} ctx.chainHub
7171
* @param {Promise<GuestInterface<LocalOrchestrationAccountKit['holder']>>} ctx.sharedLocalAccountP
7272
* @param {GuestInterface<ZoeTools>} ctx.zoeTools
73-
* @param {GuestOf<(msg: string) => Vow<void>>} ctx.log
73+
* @param {GuestOf<(msg: string, level?: string) => Vow<void>>} ctx.log
7474
* @param {ZCFSeat} seat
7575
* @param {SwapInfo} offerArgs
7676
*/
@@ -124,6 +124,7 @@ export const swapIt = async (
124124
await withdrawToSeat(sharedLocalAccount, seat, give);
125125
const errorMsg = `IBC Transfer failed ${q(e)}`;
126126
trace(`ERROR: ${errorMsg}`);
127+
void log(errorMsg, 'error');
127128
seat.fail(errorMsg);
128129
throw makeError(errorMsg);
129130
};
@@ -142,6 +143,7 @@ export const swapIt = async (
142143
try {
143144
const memo = buildXCSMemo(offerArgs);
144145
trace(memo);
146+
void log(`sending transfer with ${q(memo)}`);
145147

146148
await sharedLocalAccount.transfer(
147149
{
@@ -154,6 +156,7 @@ export const swapIt = async (
154156
);
155157
trace(`completed transfer to ${destAddr}`);
156158
} catch (e) {
159+
void log(`transfer error ${q(e)}`, 'error');
157160
return recoverFailedTransfer(e);
158161
}
159162

0 commit comments

Comments
 (0)