Skip to content

Commit 63d7b44

Browse files
committed
test: Advancer contract test
1 parent e4e66a7 commit 63d7b44

File tree

3 files changed

+97
-26
lines changed

3 files changed

+97
-26
lines changed

packages/fast-usdc/src/fast-usdc.contract.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
118118
* @param {{ USDC: Amount<'nat'>}} amounts
119119
*/
120120
testBorrow(amounts) {
121-
console.log('🚧🚧 UNTIL: borrow is integrated 🚧🚧', amounts);
121+
console.log('🚧🚧 UNTIL: borrow is integrated (#10388) 🚧🚧', amounts);
122122
const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit();
123123
// eslint-disable-next-line no-use-before-define
124124
poolKit.borrower.borrow(tmpAssetManagerSeat, amounts);
@@ -131,7 +131,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
131131
* @returns {Promise<AmountKeywordRecord>}
132132
*/
133133
async testRepay(amounts, payments) {
134-
console.log('🚧🚧 UNTIL: repay is integrated 🚧🚧', amounts);
134+
console.log('🚧🚧 UNTIL: repay is integrated (#10388) 🚧🚧', amounts);
135135
const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit();
136136
await depositToSeat(
137137
zcf,

packages/fast-usdc/test/fast-usdc.contract.test.ts

+91-20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { commonSetup } from './supports.js';
2323
import type { FastUsdcTerms } from '../src/fast-usdc.contract.js';
2424
import { makeFeeTools } from '../src/utils/fees.js';
2525
import type { PoolMetrics } from '../src/types.js';
26+
import { addressTools } from '../src/utils/address.js';
2627

2728
const dirname = path.dirname(new URL(import.meta.url).pathname);
2829

@@ -52,6 +53,14 @@ const startContract = async (
5253
const { zoe, bundleAndInstall } = await setUpZoeForTest({
5354
setJig: jig => {
5455
jig.chainHub.registerChain('osmosis', fetchedChainInfo.osmosis);
56+
jig.chainHub.registerChain('agoric', fetchedChainInfo.agoric);
57+
// TODO #10445 register noble<>agoric and noble<>osmosis instead
58+
// for PFM routing. also will need to call `registerAsset`
59+
jig.chainHub.registerConnection(
60+
fetchedChainInfo.agoric.chainId,
61+
fetchedChainInfo.osmosis.chainId,
62+
fetchedChainInfo.agoric.connections['osmosis-1'],
63+
);
5564
},
5665
});
5766
const installation: Installation<StartFn> =
@@ -69,26 +78,6 @@ const startContract = async (
6978
return { ...startKit, zoe };
7079
};
7180

72-
// FIXME this makeTestPushInvitation forces evidence, which triggers advancing,
73-
// which doesn't yet work
74-
test.skip('advancing', async t => {
75-
const common = await commonSetup(t);
76-
77-
const { publicFacet, zoe } = await startContract(common);
78-
79-
const e1 = await E(MockCctpTxEvidences.AGORIC_PLUS_DYDX)();
80-
81-
const inv = await E(publicFacet).makeTestPushInvitation(e1);
82-
// the invitation maker itself pushes the evidence
83-
84-
// the offer is still safe to make
85-
const seat = await E(zoe).offer(inv);
86-
t.is(
87-
await E(seat).getOfferResult(),
88-
'inert; nothing should be expected from this offer',
89-
);
90-
});
91-
9281
test('oracle operators have closely-held rights to submit evidence of CCTP transactions', async t => {
9382
const common = await commonSetup(t);
9483
const { creatorFacet, zoe } = await startContract(common);
@@ -551,3 +540,85 @@ test('baggage', async t => {
551540
const tree = inspectMapStore(contractBaggage);
552541
t.snapshot(tree, 'contract baggage after start');
553542
});
543+
544+
test('advancing happy path', async t => {
545+
const common = await commonSetup(t);
546+
const {
547+
brands: { usdc },
548+
commonPrivateArgs,
549+
utils: { inspectLocalBridge, inspectBankBridge, transmitTransferAck },
550+
} = common;
551+
552+
const { instance, publicFacet, zoe } = await startContract(common);
553+
const terms = await E(zoe).getTerms(instance);
554+
const { subscriber } = E.get(
555+
E.get(E(publicFacet).getPublicTopics()).poolMetrics,
556+
);
557+
const feeTools = makeFeeTools(commonPrivateArgs.feeConfig);
558+
const { makeLP, purseOf } = makeLpTools(t, common, {
559+
publicFacet,
560+
subscriber,
561+
terms,
562+
zoe,
563+
});
564+
565+
const evidence = await E(MockCctpTxEvidences.AGORIC_PLUS_OSMO)();
566+
567+
// seed pool with funds
568+
const alice = makeLP('Alice', purseOf(evidence.tx.amount));
569+
await alice.deposit(evidence.tx.amount);
570+
571+
// the invitation maker itself pushes the evidence
572+
const inv = await E(publicFacet).makeTestPushInvitation(evidence);
573+
const seat = await E(zoe).offer(inv);
574+
t.is(
575+
await E(seat).getOfferResult(),
576+
'inert; nothing should be expected from this offer',
577+
);
578+
579+
// calculate advance net of fees
580+
const expectedAdvance = feeTools.calculateAdvance(
581+
usdc.make(evidence.tx.amount),
582+
);
583+
t.log('Expecting to observe advance of', expectedAdvance);
584+
585+
await eventLoopIteration(); // let Advancer do work
586+
587+
// advance sent from PoolSeat to PoolAccount
588+
t.deepEqual(inspectBankBridge().at(-1), {
589+
amount: String(expectedAdvance.value),
590+
denom: 'ibc/usdconagoric',
591+
recipient: 'agoric1fakeLCAAddress',
592+
type: 'VBANK_GIVE',
593+
});
594+
595+
// ibc transfer sent over localChain bridge
596+
const localBridgeMsg = inspectLocalBridge().at(-1);
597+
const ibcTransferMsg = localBridgeMsg.messages[0];
598+
t.is(ibcTransferMsg['@type'], '/ibc.applications.transfer.v1.MsgTransfer');
599+
600+
const expectedReceiver = addressTools.getQueryParams(
601+
evidence.aux.recipientAddress,
602+
).EUD;
603+
t.is(ibcTransferMsg.receiver, expectedReceiver, 'sent to correct address');
604+
t.deepEqual(ibcTransferMsg.token, {
605+
amount: String(expectedAdvance.value),
606+
denom: 'ibc/usdconagoric',
607+
});
608+
609+
// TODO #10445 expect PFM memo
610+
t.is(ibcTransferMsg.memo, '', 'TODO expecting PFM memo');
611+
612+
// TODO #10445 expect routing through noble, not osmosis
613+
t.is(
614+
ibcTransferMsg.sourceChannel,
615+
fetchedChainInfo.agoric.connections['osmosis-1'].transferChannel.channelId,
616+
'TODO expecting routing through Noble',
617+
);
618+
619+
await transmitTransferAck();
620+
// Nothing we can check here, unless we want to inspect calls to `trace`.
621+
// `test/exos/advancer.test.ts` covers calls to `log: LogFn` with mocks.
622+
// This is still helpful to call, so we can observe "Advance transfer
623+
// fulfilled" in the test output.
624+
});

packages/fast-usdc/test/supports.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
5252
onToBridge: obj => bankBridgeMessages.push(obj),
5353
});
5454
await E(bankManager).addAsset(
55-
'uusdc',
55+
'ibc/usdconagoric',
5656
'USDC',
5757
'USD Circle Stablecoin',
5858
usdc.issuerKit,
@@ -64,13 +64,13 @@ export const commonSetup = async (t: ExecutionContext<any>) => {
6464
// TODO https://github.com/Agoric/agoric-sdk/issues/9966
6565
await makeWellKnownSpaces(agoricNamesAdmin, t.log, ['vbankAsset']);
6666
await E(E(agoricNamesAdmin).lookupAdmin('vbankAsset')).update(
67-
'uusdc',
67+
'ibc/usdconagoric',
6868
/** @type {AssetInfo} */ harden({
6969
brand: usdc.brand,
7070
issuer: usdc.issuer,
71-
issuerName: 'IST',
71+
issuerName: 'USDC',
7272
denom: 'uusdc',
73-
proposedName: 'IST',
73+
proposedName: 'USDC',
7474
displayInfo: { IOU: true },
7575
}),
7676
);

0 commit comments

Comments
 (0)