From 8159c667316b5ba6c87ad0f8004ee947662c452b Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Thu, 12 Sep 2024 12:27:21 -0400 Subject: [PATCH] feat: return failed transfer from contract localOrchAccount to seat --- .../examples/staking-combinations.flows.js | 5 ++- .../snapshots/staking-combinations.test.ts.md | 6 ++++ .../staking-combinations.test.ts.snap | Bin 1624 -> 1672 bytes .../examples/staking-combinations.test.ts | 34 ++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/orchestration/src/examples/staking-combinations.flows.js b/packages/orchestration/src/examples/staking-combinations.flows.js index 2961ee96dac..c7ab71afc32 100644 --- a/packages/orchestration/src/examples/staking-combinations.flows.js +++ b/packages/orchestration/src/examples/staking-combinations.flows.js @@ -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); diff --git a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md index 8fa76401b61..5b0b7e27271 100644 --- a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.md @@ -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', }, }, }, @@ -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', }, }, }, @@ -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', }, }, }, diff --git a/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.snap b/packages/orchestration/test/examples/snapshots/staking-combinations.test.ts.snap index 0419690848faed7bf50e70dc8e24ce45df0f447f..baa5d7049abe11fd6ccbe8934889dc42429bdf0e 100644 GIT binary patch literal 1672 zcmV;326y>ERzV$x2o=y96{o_1OQl`_K}CfS z@+Nk6XObuzp!ATOoPFQ>=Iy-iy*FcDm@gY#U9`_$WRC6_jM)yg9Nji)&0gS+efFZJ zQHLHH$%WB@<{wdrG67&OfY$(A1@IGqzW@vo;4uPZNi0KR)8*q#bqHyH?C$OcNrH5M zq>&||90`L&Gh}#I-J)fKmG;%khHfvEp4XjYi@K>zQd2Wn3zi%+3|3*CU&;K=T0 zDz`LdZNM=_$Rq(;<~X%and*eW8?NcR$E2v-bS$bmuI0MNlH``Uz--5&j?PWjoDZ#- zBPV#nURufXG<=$~<_31nhX5l4d>8_L4FL~_0Uib}hk@V2z~d3%NCY?&0WL&@4GsA> zR3Xau5#UAy7>WWc3Va*|LNQ=l3^*DS++(79{M{Jvehl~{2JGnoUhV+C>;U2lutNc! zRs@QEks@+L0jL7JrvN{S@PYvMTZ@uD5<+hCV_H==$68qmDvbfb-PX;D!5nV30R3%m zKT_by?bMr5>f8((L2;sPx{e3ThDB?&4XM<}P>>m<*BERQNMNy8_VUV%!z~sxjQos4 z9Twy*QiK%ZD;1DisWwZm}iE0WW0U;Ef4xP1hZj zSJ|ADt$5vya*EbkPkP&-H5gr-qBVC5R_#dn@dc`zllAhFA_6N;a9>Apex$&&eVkXz zy2-RX<_X<#JI$24V?hIYWX7S3x>;G`bBXLtaHa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Y$qMldp2H(kd==8{EgwRNe~$54rV5 zLmd|6Es}&3V(kvdF85m9RQJ#dvyRY3W-a&0a~@Q>g_@+gQMcGKtesamnR8|4hGHJ=Q$LR(^Vafa616m;B?@)HYGH>c|5Wkm#5oZ!BO;`~T~XX^y7 zmUWY9)8;ANad(;-H)BBqdV0>Gi@I4^=5vYc4R9t2v16<6fxaaNYmLoZoun!YyqOPp zeWm1OTdp3MTSi5E?FnvIxm}#~##t<>DzBSPaf%!3n-@OL?fbY&ja4W&Ft`dXpDTk& zs!}a*PY$(1;ep>~x^eyQImwwFh{z2bk#rPWA|swOfRT-|hh}_5e3UXij3z$APgppv8f! zaRHte;h|sSz&#N*EDi6lTk4&??Naw^tj2BKDVf@CX0Qr%mW4t+n0S>gvXw4!jc`9l5Zvfyk0yZ=A}lGvtR!$+gk_{c5I3whJYkU?9>e#m z8PX}gK_Rh&Dd3e9@J&ZG0i{0Ry*}VhA25{`qUn+DJ>@j8kOr=$fjem++z-t5 z1E2H*5Bh<_8G#}tQPeWPsSNOG26&JG(plhm7Wgs?C3Yv~rfS_A%(uQN!&`H9RCWj14~eYS=rtsfLH6h6|n5 zppfp52Z7H9f%}8N^bl}i2)Ho>Byz%#iA#qiH3#T9;C&I=D?+<}$pLqBz|K7IY99D1 z4@8E6y~BcQpR~%QVc^;@a9f0?rB${UfE@+EE&yK_fWHesX#{v}L~tFDR{3!R_;~~v z9~Gd3(rk?i)f$zrB7twr9Vnzy7g`LR?mqtSNjx{7z?W37?;78e_%2sIhGNI7RnR!b zIMaMi-#Gs%#70`%@bI$Oe+;y WVMRLcFstbPJo^td|1&qW9RL6d>i?nu diff --git a/packages/orchestration/test/examples/staking-combinations.test.ts b/packages/orchestration/test/examples/staking-combinations.test.ts index a7540dd8a0c..7a9c61ac010 100644 --- a/packages/orchestration/test/examples/staking-combinations.test.ts +++ b/packages/orchestration/test/examples/staking-combinations.test.ts @@ -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 { @@ -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', + ); + } });