Skip to content

Commit

Permalink
fixup! test: added more tests for each individual contract
Browse files Browse the repository at this point in the history
test: added test for priceFeed
  • Loading branch information
frazarshad committed Oct 4, 2024
1 parent 2c3c7a8 commit cba5d99
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
60 changes: 57 additions & 3 deletions packages/boot/test/bootstrapTests/ec-replace-charter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,60 @@ test.serial('successful proposal and vote for psm', async t => {
}
});

test.todo(
'successful proposal and vote for price feed (add when there are governed params for this)',
);
test.serial('successful proposal and vote for price feed', async t => {
const { storage, advanceTimeBy, governanceDriver } = t.context;
const newCommittee = governanceDriver.ecMembers.slice(0, 3);

const agoricNamesRemotes = makeAgoricNamesRemotesFromFakeStorage(storage);

const priceFeedInstances = Object.keys(agoricNamesRemotes.instance).filter(
instance => {
const regex = /^(.*)-(.*) price feed$/;
return regex.exec(instance);
},
);

for (const instanceName of priceFeedInstances) {
t.log('Proposing question using new charter invitation for', instanceName);
await governanceDriver.proposeApiCall(

Check failure on line 432 in packages/boot/test/bootstrapTests/ec-replace-charter.test.ts

View workflow job for this annotation

GitHub Actions / lint-rest

The first `await` appearing in an async function must not be nested
agoricNamesRemotes.instance[instanceName],
'addOracles',
[[wallets[0]]],
newCommittee[0],
getQuestionId(instanceName),
offerIds.propose.incoming,
);

t.like(newCommittee[0].getLatestUpdateRecord(), {
status: { id: getQuestionId(instanceName), numWantsSatisfied: 1 },
});

t.log('Voting on question using first 2 wallets');
await governanceDriver.enactLatestProposal(
newCommittee.slice(0, 2),
getVoteId(instanceName),
offerIds.vote.incoming,
);
for (const w of newCommittee.slice(0, 2)) {
t.like(w.getLatestUpdateRecord(), {
status: { id: getVoteId(instanceName), numWantsSatisfied: 1 },
});
}

t.log('no oracle invitation should exist before vote passing');
const oracleInvitation =
await governanceDriver.ecMembers[0].getOracleInvitation();
t.is(oracleInvitation, undefined);

t.log('Waiting for period to end');
await advanceTimeBy(1, 'minutes');

t.log('Verifying outcome');
const lastOutcome = await governanceDriver.getLatestOutcome();
t.assert(lastOutcome.outcome === 'win');

const oracleInvitationAfterProposal =
await governanceDriver.ecMembers[0].getOracleInvitation();
t.not(oracleInvitationAfterProposal, undefined);
}
});
34 changes: 34 additions & 0 deletions packages/boot/tools/drivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ export const makeGovernanceDriver = async (
proposal: {},
});
},
getOracleInvitation: async () => {
const purse = w
.getCurrentWalletRecord()
// TODO: manage brands by object identity #10167
.purses.find(p => p.brand.toString().includes('Invitation'));
// @ts-expect-error
const invitation = purse?.balance.value.find(
v => v.description === 'oracle invitation',
);
return invitation;
},
}));

const ensureInvitationsAccepted = async () => {
Expand Down Expand Up @@ -322,6 +333,28 @@ export const makeGovernanceDriver = async (
});
};

const proposeApiCall = async (
instance,
methodName: string,
methodArgs: any[],
ecMember: (typeof ecMembers)[0] | null = null,
questionId = 'propose',
charterOfferId = charterMembershipId,
) => {
const now = await EV(chainTimerService).getCurrentTimestamp();
const deadline = SECONDS_PER_MINUTE + now.absValue;
await (ecMember || ecMembers[0]).executeOffer({
id: questionId,
invitationSpec: {
invitationMakerName: 'VoteOnApiCall',
previousOffer: charterOfferId,
source: 'continuing',
invitationArgs: [instance, methodName, methodArgs, deadline],
},
proposal: {},
});
};

const enactLatestProposal = async (
members = ecMembers,
voteId = 'voteInNewLimit',
Expand All @@ -344,6 +377,7 @@ export const makeGovernanceDriver = async (

return {
proposeParams,
proposeApiCall,
enactLatestProposal,
getLatestOutcome,
async changeParams(instance: Instance, params: Object, path?: object) {
Expand Down

0 comments on commit cba5d99

Please sign in to comment.