Skip to content

Commit 1f0314a

Browse files
committed
fixup! feat: integrate advancer in StartFn
1 parent e2cedd0 commit 1f0314a

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

packages/fast-usdc/src/exos/advancer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const AdvancerKitI = harden({
4343
handleTransactionEvent: M.callWhen(CctpTxEvidenceShape).returns(),
4444
}),
4545
depositHandler: M.interface('DepositHandlerI', {
46-
onFulfilled: M.call(AmountShape, {
46+
onFulfilled: M.call(M.undefined(), {
4747
amount: AmountShape,
4848
destination: ChainAddressShape,
4949
tmpSeat: M.remotable(),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
123123
*
124124
* @param {{ Principal: Amount<'nat'>; PoolFee: Amount<'nat'>; ContractFee: Amount<'nat'> }} amounts
125125
* @param {{ Principal: Payment<'nat'>; PoolFee: Payment<'nat'>; ContractFee: Payment<'nat'> }} payments
126-
* @returns
126+
* @returns {Promise<AmountKeywordRecord>}
127127
*/
128128
async testRepay(amounts, payments) {
129129
console.log('🚧🚧 UNTIL: repay is integrated 🚧🚧', amounts);

packages/fast-usdc/test/exos/advancer.test.ts

+32-11
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const createTestExtensions = (t, common: CommonSetup) => {
5656
});
5757

5858
const localTransferVK = vowTools.makeVowKit<void>();
59+
const resolveLocalTransferV = () => {
60+
// pretend funds move from tmpSeat to poolAccount
61+
localTransferVK.resolver.resolve();
62+
};
5963
const mockZoeTools = Far('MockZoeTools', {
6064
localTransfer(...args: Parameters<ZoeTools['localTransfer']>) {
6165
console.log('ZoeTools.localTransfer called with', args);
@@ -91,7 +95,7 @@ const createTestExtensions = (t, common: CommonSetup) => {
9195
};
9296

9397
const borrowUnderlyingPK = makePromiseKit<void>();
94-
const resolveBorrowUnderlyingP = async () => {
98+
const resolveBorrowUnderlyingP = () => {
9599
// pretend funds are allocated to tmpSeat provided to borrow
96100
return borrowUnderlyingPK.resolve();
97101
};
@@ -123,6 +127,7 @@ const createTestExtensions = (t, common: CommonSetup) => {
123127
setMockPoolBalance,
124128
resolveBorrowUnderlyingP,
125129
rejectBorrowUnderlyingP,
130+
resolveLocalTransferV,
126131
},
127132
services: {
128133
advancer,
@@ -151,15 +156,20 @@ test('updates status to ADVANCED in happy path', async t => {
151156
extensions: {
152157
services: { advancer, statusManager },
153158
helpers: { inspectLogs },
154-
mocks: { mockPoolAccount, resolveBorrowUnderlyingP },
159+
mocks: {
160+
mockPoolAccount,
161+
resolveBorrowUnderlyingP,
162+
resolveLocalTransferV,
163+
},
155164
},
156165
brands: { usdc },
157166
} = t.context;
158167

159168
const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_OSMO();
160169
const handleTxP = advancer.handleTransactionEvent(mockEvidence);
161170

162-
await resolveBorrowUnderlyingP(usdc.make(mockEvidence.tx.amount));
171+
resolveBorrowUnderlyingP();
172+
resolveLocalTransferV();
163173
await eventLoopIteration();
164174
mockPoolAccount.transferVResolver.resolve();
165175

@@ -179,7 +189,7 @@ test('updates status to ADVANCED in happy path', async t => {
179189

180190
t.deepEqual(inspectLogs(0), [
181191
'Advance transfer fulfilled',
182-
'{"amount":{"brand":"[Alleged: USDC brand]","value":"[150000000n]"},"destination":{"chainId":"osmosis-1","encoding":"bech32","value":"osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men"},"result":"[undefined]"}',
192+
'{"amount":{"brand":"[Alleged: USDC brand]","value":"[149999899n]"},"destination":{"chainId":"osmosis-1","encoding":"bech32","value":"osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men"},"result":"[undefined]"}',
183193
]);
184194
});
185195

@@ -211,7 +221,7 @@ test('updates status to OBSERVED on insufficient pool funds', async t => {
211221

212222
t.deepEqual(inspectLogs(0), [
213223
'Insufficient pool funds',
214-
'Requested {"brand":"[Alleged: USDC brand]","value":"[195000000n]"} but only have {"brand":"[Alleged: USDC brand]","value":"[1n]"}',
224+
'Requested {"brand":"[Alleged: USDC brand]","value":"[199999899n]"} but only have {"brand":"[Alleged: USDC brand]","value":"[1n]"}',
215225
]);
216226
});
217227

@@ -290,15 +300,20 @@ test('does not update status on failed transfer', async t => {
290300
extensions: {
291301
services: { advancer, statusManager },
292302
helpers: { inspectLogs },
293-
mocks: { mockPoolAccount, resolveBorrowUnderlyingP },
303+
mocks: {
304+
mockPoolAccount,
305+
resolveBorrowUnderlyingP,
306+
resolveLocalTransferV,
307+
},
294308
},
295309
brands: { usdc },
296310
} = t.context;
297311

298312
const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_DYDX();
299313
const handleTxP = advancer.handleTransactionEvent(mockEvidence);
300314

301-
await resolveBorrowUnderlyingP(usdc.make(mockEvidence.tx.amount));
315+
resolveBorrowUnderlyingP();
316+
resolveLocalTransferV();
302317
mockPoolAccount.transferVResolver.reject(new Error('simulated error'));
303318

304319
await handleTxP;
@@ -357,23 +372,27 @@ test('will not advance same txHash:chainId evidence twice', async t => {
357372
extensions: {
358373
services: { advancer },
359374
helpers: { inspectLogs },
360-
mocks: { mockPoolAccount, resolveBorrowUnderlyingP },
375+
mocks: {
376+
mockPoolAccount,
377+
resolveBorrowUnderlyingP,
378+
resolveLocalTransferV,
379+
},
361380
},
362-
brands: { usdc },
363381
} = t.context;
364382

365383
const mockEvidence = MockCctpTxEvidences.AGORIC_PLUS_OSMO();
366384

367385
// First attempt
368386
const handleTxP = advancer.handleTransactionEvent(mockEvidence);
369-
await resolveBorrowUnderlyingP(usdc.make(mockEvidence.tx.amount));
387+
resolveBorrowUnderlyingP();
388+
resolveLocalTransferV();
370389
mockPoolAccount.transferVResolver.resolve();
371390
await handleTxP;
372391
await eventLoopIteration();
373392

374393
t.deepEqual(inspectLogs(0), [
375394
'Advance transfer fulfilled',
376-
'{"amount":{"brand":"[Alleged: USDC brand]","value":"[150000000n]"},"destination":{"chainId":"osmosis-1","encoding":"bech32","value":"osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men"},"result":"[undefined]"}',
395+
'{"amount":{"brand":"[Alleged: USDC brand]","value":"[149999899n]"},"destination":{"chainId":"osmosis-1","encoding":"bech32","value":"osmo183dejcnmkka5dzcu9xw6mywq0p2m5peks28men"},"result":"[undefined]"}',
377396
]);
378397

379398
// Second attempt
@@ -384,3 +403,5 @@ test('will not advance same txHash:chainId evidence twice', async t => {
384403
'"[Error: Transaction already seen: \\"seenTx:[\\\\\\"0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761702\\\\\\",1]\\"]"',
385404
]);
386405
});
406+
407+
test.todo('zoeTools.localTransfer fails to deposit borrowed USDC to LOA');

0 commit comments

Comments
 (0)