Skip to content

Commit

Permalink
feat: return failed transfer from contract localOrchAccount to seat
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Sep 17, 2024
1 parent d63f3a2 commit 92821e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export const depositAndDelegate = async (
try {
await contractState.localAccount.transfer(give.Stake, address);
} catch (cause) {
// TODO, put funds back on user seat and exit
// https://github.com/Agoric/agoric-sdk/issues/9925
throw makeError('ibc transfer failed', undefined, { cause });
await zoeTools.withdrawToSeat(contractState.localAccount, seat, give);
throw seat.fail(makeError('ibc transfer failed', undefined, { cause }));
}
seat.exit();
await account.delegate(validator, give.Stake);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Generated by [AVA](https://avajs.dev).
zoeTools: {
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
withdrawToSeat_kindHandle: 'Alleged: kind',
withdrawToSeat_singleton: 'Alleged: withdrawToSeat',
},
},
},
Expand All @@ -76,6 +78,8 @@ Generated by [AVA](https://avajs.dev).
zoeTools: {
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
withdrawToSeat_kindHandle: 'Alleged: kind',
withdrawToSeat_singleton: 'Alleged: withdrawToSeat',
},
},
},
Expand All @@ -101,6 +105,8 @@ Generated by [AVA](https://avajs.dev).
zoeTools: {
localTransfer_kindHandle: 'Alleged: kind',
localTransfer_singleton: 'Alleged: localTransfer',
withdrawToSeat_kindHandle: 'Alleged: kind',
withdrawToSeat_singleton: 'Alleged: withdrawToSeat',
},
},
},
Expand Down
Binary file not shown.
34 changes: 34 additions & 0 deletions packages/orchestration/test/examples/staking-combinations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MsgTransferResponse,
} from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
import { IBCMethod } from '@agoric/vats';
import { SIMULATED_ERRORS } from '@agoric/vats/tools/fake-bridge.js';
import { protoMsgMocks, UNBOND_PERIOD_SECONDS } from '../ibc-mocks.js';
import { commonSetup } from '../supports.js';
import {
Expand Down Expand Up @@ -205,4 +206,37 @@ test('start', async t => {
// snapshot the resulting contract baggage
const tree = inspectMapStore(contractBaggage);
t.snapshot(tree, 'contract baggage after start');

{
t.log('payments from failed transfers are returned');
const bldAmt = bld.make(SIMULATED_ERRORS.TIMEOUT);

const seat = await E(zoe).offer(
await E(result.invitationMakers).DepositAndDelegate(),
{
give: { Stake: bldAmt },
exit: { waived: null },
},
{
Stake: await pourPayment(bldAmt),
},
{
validator: {
chainId: 'cosmoshub',
value: 'cosmosvaloper1test',
encoding: 'bech32',
},
},
);
await t.throwsAsync(vt.when(E(seat).getOfferResult()), {
message: 'ibc transfer failed',
});
await vt.when(E(seat).hasExited());
const payouts = await E(seat).getPayouts();
t.deepEqual(
await bld.issuer.getAmountOf(payouts.Stake),
bldAmt,
'Stake is returned',
);
}
});

0 comments on commit 92821e9

Please sign in to comment.