Skip to content

Commit

Permalink
test(smartWallet): simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 13, 2023
1 parent 8720d22 commit 9b6e2cd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ const acceptInvitation = async (wallet, priceAggregator) => {
instance: priceAggregator,
description: ORACLE_INVITATION_MAKERS_DESC,
};

/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const invMakersOffer = {
await wallet.getOffersFacet().executeOffer({
id,
invitationSpec: getInvMakersSpec,
proposal: {},
};
await wallet.getOffersFacet().executeOffer(invMakersOffer);
});
// wait for it to settle
await eventLoopIteration();
return id;
Expand All @@ -143,14 +140,11 @@ const pushPrice = async (wallet, adminOfferId, priceRound) => {

pushPriceCounter += 1;
const id = `pushPrice${pushPriceCounter}`;
/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const proposalOfferSpec = {
await wallet.getOffersFacet().executeOffer({
id,
invitationSpec: proposeInvitationSpec,
proposal: {},
};

await wallet.getOffersFacet().executeOffer(proposalOfferSpec);
});
await eventLoopIteration();
return id;
};
Expand Down Expand Up @@ -209,13 +203,11 @@ test.serial('invitations', async t => {
};

const id = '33';
/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const invMakersOffer = {
await wallet.getOffersFacet().executeOffer({
id,
invitationSpec: getInvMakersSpec,
proposal: {},
};
await wallet.getOffersFacet().executeOffer(invMakersOffer);
});

const currentSub = E(wallet).getCurrentSubscriber();
/** @type {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} */
Expand Down
81 changes: 37 additions & 44 deletions packages/inter-protocol/test/smartWallet/test-psm-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,16 @@ test('null swap', async t => {
instance: psmInstance,
publicInvitationMaker: 'makeGiveMintedInvitation',
};
/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const offerSpec = {
id: 1,

await offersFacet.executeOffer({
id: 'nullSwap',
invitationSpec,
proposal: {
// empty amounts
give: { In: AmountMath.makeEmpty(mintedBrand) },
want: { Out: anchor.makeEmpty() },
},
};

// let promises settle to notify brands and create purses
await eventLoopIteration();

await offersFacet.executeOffer(offerSpec);
});
await eventLoopIteration();

t.is(await E.get(getBalanceFor(anchor.brand)).value, 0n);
Expand All @@ -114,8 +109,6 @@ test('want stable', async t => {

const offersFacet = wallet.getOffersFacet();
t.assert(offersFacet, 'undefined offersFacet');
// let promises settle to notify brands and create purses
await eventLoopIteration();

t.is(await E.get(getBalanceFor(anchor.brand)).value, 0n);

Expand All @@ -127,24 +120,21 @@ test('want stable', async t => {

t.log('Prepare the swap');

t.log('Execute the swap');
/** @type {import('@agoric/smart-wallet/src/invitations').ContractInvitationSpec} */
const invitationSpec = {
source: 'contract',
instance: psmInstance,
publicInvitationMaker: 'makeWantMintedInvitation',
};
/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const offerSpec = {
await offersFacet.executeOffer({
id: 1,
invitationSpec,
proposal: {
give: { In: anchor.make(swapSize) },
want: {},
},
};

t.log('Execute the swap');
await offersFacet.executeOffer(offerSpec);
});
await eventLoopIteration();
t.is(await E.get(getBalanceFor(anchor.brand)).value, 0n);
t.is(await E.get(getBalanceFor(stableBrand)).value, swapSize); // assume 0% fee
Expand Down Expand Up @@ -223,14 +213,11 @@ test('govern offerFilter', async t => {
description: INVITATION_MAKERS_DESC,
};

/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const invMakersOffer = {
id: 44,
await offersFacet.executeOffer({
id: 'acceptEcInvitationOID',
invitationSpec: getInvMakersSpec,
proposal: {},
};

await offersFacet.executeOffer(invMakersOffer);
});

/** @type {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} */
let currentState = await headValue(currentSub);
Expand All @@ -240,9 +227,12 @@ test('govern offerFilter', async t => {
1,
'one invitation consumed, one left',
);
t.deepEqual(Object.keys(currentState.offerToUsedInvitation), ['44']);
t.deepEqual(Object.keys(currentState.offerToUsedInvitation), [
'acceptEcInvitationOID',
]);
t.is(
currentState.offerToUsedInvitation[44].value[0].description,
currentState.offerToUsedInvitation.acceptEcInvitationOID.value[0]
.description,
'charter member invitation',
);
const voteInvitationDetails = await getInvitationFor(
Expand All @@ -262,52 +252,55 @@ test('govern offerFilter', async t => {
description: 'Voter0',
};

/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const committeeInvMakersOffer = {
id: 46,
await offersFacet.executeOffer({
id: 'acceptVoterOID',
invitationSpec: getCommitteeInvMakersSpec,
proposal: {},
};

await offersFacet.executeOffer(committeeInvMakersOffer);
});
currentState = await headValue(currentSub);
t.is(
// @ts-expect-error cast amount kind
currentPurseBalance(currentState, invitationBrand).length,
0,
'last invitation consumed, none left',
);
t.deepEqual(Object.keys(currentState.offerToUsedInvitation), ['44', '46']);
// 44 tested above
t.is(currentState.offerToUsedInvitation[46].value[0].description, 'Voter0');
t.deepEqual(Object.keys(currentState.offerToUsedInvitation), [
'acceptEcInvitationOID',
'acceptVoterOID',
]);
// acceptEcInvitationOID tested above
t.is(
currentState.offerToUsedInvitation.acceptVoterOID.value[0].description,
'Voter0',
);

// Call for a vote ////////////////////////////////

/** @type {import('@agoric/smart-wallet/src/invitations').ContinuingInvitationSpec} */
const proposeInvitationSpec = {
source: 'continuing',
previousOffer: 44,
previousOffer: 'acceptEcInvitationOID',
invitationMakerName: 'VoteOnPauseOffers',
invitationArgs: harden([psmInstance, ['wantStable'], 2n]),
};

/** @type {import('@agoric/smart-wallet/src/offers').OfferSpec} */
const proposalOfferSpec = {
id: 45,
await offersFacet.executeOffer({
id: 'proposeVoteOnPauseOffers',
invitationSpec: proposeInvitationSpec,
proposal: {},
};

await offersFacet.executeOffer(proposalOfferSpec);
});
await eventLoopIteration();

// vote /////////////////////////

const committeePublic = E(zoe).getPublicFacet(economicCommittee);

await offersFacet.executeOffer({
id: 47,
invitationSpec: await voteForOpenQuestion(committeePublic, '46'),
id: 'voteForPauseOffers',
invitationSpec: await voteForOpenQuestion(
committeePublic,
'acceptVoterOID',
),
proposal: {},
});
await eventLoopIteration();
Expand Down Expand Up @@ -380,7 +373,7 @@ test('recover when some withdrawals succeed and others fail', async t => {
want: { Proceeds: make(brand.IST, 1n) },
});
await E(smartWallet.getOffersFacet()).executeOffer({
id: '1',
id: 'recover',
invitationSpec: {
source: 'contract',
instance,
Expand Down

0 comments on commit 9b6e2cd

Please sign in to comment.