Skip to content

Commit

Permalink
test: smart wallet recovers when only some withdrawals succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Feb 10, 2023
1 parent 3b01ed0 commit f77e3a5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/inter-protocol/test/smartWallet/test-psm-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,57 @@ test.failing('deposit > 1 payment to unknown brand #6961', async t => {
}
});

// XXX belongs in smart-wallet package, but needs lots of set-up that's handy here.
test('recover when some withdrawals succeed and others fail', async t => {
const { fromEntries } = Object;
const { make } = AmountMath;
const { anchor } = t.context;
const { agoricNames, bankManager } = t.context.consume;
const getBalance = (addr, brand) => {
const bank = E(bankManager).getBankForAddress(addr);
const purse = E(bank).getPurse(brand);
return E(purse).getCurrentAmount();
};
const namedBrands = kws =>
Promise.all(
kws.map(kw =>
E(agoricNames)
.lookup('brand', kw)
.then(b => [kw, b]),
),
).then(fromEntries);

t.log('Johnny has 10 AUSD');
const jAddr = 'addrForJohnny';
const smartWallet = await t.context.simpleProvideWallet(jAddr);
await E(E(smartWallet).getDepositFacet()).receive(
// @ts-expect-error FarRef grumble
E(anchor.mint).mintPayment(make(anchor.brand, 10n)),
);
t.deepEqual(await getBalance(jAddr, anchor.brand), make(anchor.brand, 10n));

t.log('He accidentally offers 10 BLD as well in a trade for IST');
const instance = await E(agoricNames).lookup('instance', 'psm-IST-AUSD');
const brand = await namedBrands(['BLD', 'IST']);
const proposal = harden({
give: { Anchor: make(anchor.brand, 10n), Oops: make(brand.BLD, 10n) },
want: { Proceeds: make(brand.IST, 1n) },
});
await E(smartWallet.getOffersFacet()).executeOffer({
id: '1',
invitationSpec: {
source: 'contract',
instance,
publicInvitationMaker: 'makeWantMintedInvitation',
invitationArgs: [],
},
proposal,
});

t.log('He still has 10 AUSD');
t.deepEqual(await getBalance(jAddr, anchor.brand), make(anchor.brand, 10n));
});

test.todo('bad offer schema');
test.todo('not enough funds');
test.todo(
Expand Down

0 comments on commit f77e3a5

Please sign in to comment.