diff --git a/packages/smart-wallet/package.json b/packages/smart-wallet/package.json index 1c968855f6f..4548fbcdb9b 100644 --- a/packages/smart-wallet/package.json +++ b/packages/smart-wallet/package.json @@ -18,6 +18,7 @@ "devDependencies": { "@agoric/cosmic-proto": "^0.4.0", "@agoric/swingset-vat": "^0.32.2", + "@agoric/zone": "^0.2.2", "@endo/bundle-source": "^3.2.2", "@endo/captp": "^4.1.1", "@endo/init": "^1.1.1", diff --git a/packages/smart-wallet/src/smartWallet.js b/packages/smart-wallet/src/smartWallet.js index 7a1f7334335..dbd3fc91c3a 100644 --- a/packages/smart-wallet/src/smartWallet.js +++ b/packages/smart-wallet/src/smartWallet.js @@ -972,22 +972,23 @@ export const prepareSmartWallet = (baggage, shared) => { const invitation = invitationFromSpec(offerSpec.invitationSpec); - const [paymentKeywordRecord, invitationAmount] = await Promise.all([ - proposal?.give && - deeplyFulfilledObject( - facets.payments.withdrawGive(proposal.give, offerSpec.id), - ), - E(invitationIssuer).getAmountOf(invitation), - ]); + const invitationAmount = + await E(invitationIssuer).getAmountOf(invitation); // 2. Begin executing offer // No explicit signal to user that we reached here but if anything above // failed they'd get an 'error' status update. + const withdrawnPayments = + proposal?.give && + (await deeplyFulfilledObject( + facets.payments.withdrawGive(proposal.give, offerSpec.id), + )); + seatRef = await E(zoe).offer( invitation, proposal, - paymentKeywordRecord, + withdrawnPayments, offerSpec.offerArgs, ); facets.helper.logWalletInfo(offerSpec.id, 'seated'); diff --git a/packages/smart-wallet/test/test-invitation1.js b/packages/smart-wallet/test/test-invitation1.js index 3f9f88bad67..93808a1154a 100644 --- a/packages/smart-wallet/test/test-invitation1.js +++ b/packages/smart-wallet/test/test-invitation1.js @@ -33,6 +33,7 @@ const mockBootstrapPowers = async ( log, spaceNames = ['installation', 'instance', 'issuer', 'brand'], ) => { + /** @type {import('@agoric/vat-data').Baggage} */ const baggage = makeScalarMapStore('bootstrap'); const zone = makeDurableZone(baggage); const { produce, consume } = makePromiseSpace(); @@ -82,7 +83,9 @@ const makeTestContext = async t => { const makeSpendableAsset = () => { const tok1 = makeIssuerKit('Tok1'); const { issuer, brand } = bootKit.powers; + // @ts-expect-error new symbol issuer.produce.Token1.resolve(tok1.issuer); + // @ts-expect-error new symbol brand.produce.Token1.resolve(tok1.brand); return tok1; }; @@ -114,6 +117,7 @@ const makeTestContext = async t => { /** @type {import('../src/smartWallet.js').BrandDescriptorRegistry} */ const registry = await makeRegistry(); + /** @type {import('@agoric/vat-data').Baggage} */ const swBaggage = makeScalarMapStore('smart-wallet'); const secretWalletFactoryKey = Far('Key', {}); @@ -151,6 +155,7 @@ test.serial('handle failure to create invitation', async t => { const invitationIssuer = powers.issuer.consume.Invitation; const address = 'agoric1234'; + // @ts-expect-error Test setup ensures that chainStorage resolution is not undefined. (see #8247) const walletsStorage = E(chainStorage).makeChildNode('wallet'); const walletStorageNode = await E(walletsStorage).makeChildNode(address); @@ -167,7 +172,6 @@ test.serial('handle failure to create invitation', async t => { const amt = AmountMath.make(spendable.brand, 100n); const pmt = await E(spendable.mint).mintPayment(amt); await E(purse).deposit(pmt); - shared.thePurse = purse; const slowWithdrawPurse = { ...purse, withdraw: async a => { @@ -175,6 +179,7 @@ test.serial('handle failure to create invitation', async t => { console.log('@@slow withdraw', a); return E(purse).withdraw(a); }, + getCurrentAmount: () => purse.getCurrentAmount(), }; return slowWithdrawPurse; }, @@ -183,10 +188,13 @@ test.serial('handle failure to create invitation', async t => { }, }); + const theBank = makeBank(); + shared.thePurse = await theBank.getPurse(spendable.brand); + const smartWallet = await makeSmartWallet({ address, walletStorageNode, - bank: makeBank(), + bank: theBank, invitationPurse, }); shared.theWallet = smartWallet; @@ -216,7 +224,7 @@ test.serial('handle failure to create invitation', async t => { await delay(200); }); -test.serial.failing('funds should be back in the purse', async t => { +test.serial('funds should be back in the purse', async t => { t.like(t.context.shared.thePurse.getCurrentAmount(), { value: 100n }); });