Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(a3p): extend governance test coverage for acceptance proposal #10555

Merged
merged 12 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions a3p-integration/proposals/z:acceptance/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ restart-valueVow
start-valueVow
localchaintest-submission
recorded-instances-submission
upgrade-vaultFactory
upgrade-provisionPool
237 changes: 181 additions & 56 deletions a3p-integration/proposals/z:acceptance/governance.test.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
/* global fetch setTimeout */
/* global fetch */

import test from 'ava';

import { makeWalletUtils } from '@agoric/client-utils';
import { GOV1ADDR, GOV2ADDR } from '@agoric/synthetic-chain';
import { makeGovernanceDriver } from './test-lib/governance.js';
import { networkConfig } from './test-lib/index.js';
import { makeTimerUtils } from './test-lib/utils.js';
import { agdWalletUtils } from './test-lib/index.js';
import { upgradeContract } from './test-lib/utils.js';
import { networkConfig } from './test-lib/rpc.js';

const GOV4ADDR = 'agoric1c9gyu460lu70rtcdp95vummd6032psmpdx7wdy';
const governanceAddresses = [GOV4ADDR, GOV2ADDR, GOV1ADDR];

// TODO test-lib export `walletUtils` with this ambient authority like s:stake-bld has
/** @param {number} ms */
const delay = ms =>
new Promise(resolve => setTimeout(() => resolve(undefined), ms));
const { getLastUpdate, readLatestHead } = agdWalletUtils;
const governanceDriver = await makeGovernanceDriver(fetch, networkConfig);

const testSkipXXX = test.skip; // same lenth as test.serial to avoid reformatting all lines

// z:acceptance governance fails/flakes: No quorum #10708
testSkipXXX(
'economic committee can make governance proposal and vote on it',
async t => {
const { waitUntil } = makeTimerUtils({ setTimeout });
const { readLatestHead, getLastUpdate, getCurrentWalletRecord } =
await makeWalletUtils({ delay, fetch }, networkConfig);
const governanceDriver = await makeGovernanceDriver(fetch, networkConfig);

/** @type {any} */
const instance = await readLatestHead(`published.agoricNames.instance`);
const instances = Object.fromEntries(instance);

const wallet = await getCurrentWalletRecord(governanceAddresses[0]);
const usedInvitations = wallet.offerToUsedInvitation;

const charterInvitation = usedInvitations.find(
v =>
v[1].value[0].instance.getBoardId() ===
instances.econCommitteeCharter.getBoardId(),
const charterInvitation = await governanceDriver.getCharterInvitation(
governanceAddresses[0],
);
assert(charterInvitation, 'missing charter invitation');

const params = {
ChargingPeriod: 400n,
};
const path = { paramPath: { key: 'governedParams' } };
t.log('Proposing param change', { params, path });
const instanceName = 'VaultFactory';

await governanceDriver.proposeVaultDirectorParamChange(
await governanceDriver.proposeParamChange(
governanceAddresses[0],
params,
path,
instanceName,
charterInvitation[0],
);

Expand All @@ -62,22 +47,9 @@ testSkipXXX(

t.log('Voting on param change');
for (const address of governanceAddresses) {
const voteWallet =
/** @type {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} */ (
await readLatestHead(`published.wallet.${address}.current`)
);
const committeeInvitationForVoter =
await governanceDriver.getCommitteeInvitation(address);

const usedInvitationsForVoter = voteWallet.offerToUsedInvitation;

const committeeInvitationForVoter = usedInvitationsForVoter.find(
v =>
v[1].value[0].instance.getBoardId() ===
instances.economicCommittee.getBoardId(),
);
assert(
committeeInvitationForVoter,
`${address} must have committee invitation`,
);
await governanceDriver.voteOnProposedChanges(
address,
committeeInvitationForVoter[0],
Expand All @@ -90,22 +62,175 @@ testSkipXXX(
});
}

const latestQuestion =
/** @type {import('@agoric/governance/src/types.js').QuestionSpec} */ (
await readLatestHead(
'published.committees.Economic_Committee.latestQuestion',
)
);
t.log('Waiting for deadline', latestQuestion);
/** @type {bigint} */
// @ts-expect-error assume POSIX seconds since epoch
const deadline = latestQuestion.closingRule.deadline;
await waitUntil(deadline);

const latestOutcome = await readLatestHead(
'published.committees.Economic_Committee.latestOutcome',
);
const { latestOutcome } = await governanceDriver.getLatestQuestion();
t.log('Verifying latest outcome', latestOutcome);
t.like(latestOutcome, { outcome: 'win' });
},
);

test.serial(
'VaultFactory governed parameters are intact following contract upgrade',
async t => {
/** @type {any} */
const vaultFactoryParamsBefore = await readLatestHead(
'published.vaultFactory.governance',
);

/*
* At the previous test ('economic committee can make governance proposal and vote on it')
* The value of ChargingPeriod was updated to 400
* The 'published.vaultFactory.governance' node should reflect that change.
*/
t.is(
vaultFactoryParamsBefore.current.ChargingPeriod.value,
400n,
'vaultFactory ChargingPeriod parameter value is not the expected ',
);

await upgradeContract('upgrade-vaultFactory', 'zcf-b1-6c08a-vaultFactory');

const vaultFactoryParamsAfter = await readLatestHead(
'published.vaultFactory.governance',
);

t.deepEqual(
vaultFactoryParamsAfter,
vaultFactoryParamsBefore,
'vaultFactory governed parameters did not match',
);
},
);

test.serial(
'economic committee can make governance proposal for ProvisionPool',
async t => {
const charterInvitation = await governanceDriver.getCharterInvitation(
governanceAddresses[0],
);

/** @type {any} */
const brand = await readLatestHead(`published.agoricNames.brand`);
const brands = Object.fromEntries(brand);

const params = {
PerAccountInitialAmount: { brand: brands.IST, value: 100_000n },
};
const path = { paramPath: { key: 'governedParams' } };
const instanceName = 'provisionPool';

await governanceDriver.proposeParamChange(
governanceAddresses[0],
params,
path,
instanceName,
charterInvitation[0],
);

const questionUpdate = await getLastUpdate(governanceAddresses[0]);
t.like(questionUpdate, {
status: { numWantsSatisfied: 1 },
});

for (const address of governanceAddresses) {
const committeeInvitationForVoter =
await governanceDriver.getCommitteeInvitation(address);

await governanceDriver.voteOnProposedChanges(
address,
committeeInvitationForVoter[0],
);

const voteUpdate = await getLastUpdate(address);
t.like(voteUpdate, {
status: { numWantsSatisfied: 1 },
});
}

const { latestOutcome } = await governanceDriver.getLatestQuestion();
t.like(latestOutcome, { outcome: 'win' });
},
);

test.serial(
'ProvisionPool governed parameters are intact following contract upgrade',
async t => {
/** @type {any} */
const provisionPoolParamsBefore = await readLatestHead(
'published.provisionPool.governance',
);

/*
* At the previous test ('economic committee can make governance proposal and vote on it')
* The value of ChargingPeriod was updated to 400
* The 'published.vaultFactory.governance' node should reflect that change.
*/
t.is(
provisionPoolParamsBefore.current.PerAccountInitialAmount.value.value,
100_000n,
'provisionPool PerAccountInitialAmount parameter value is not the expected ',
);

await upgradeContract(
'upgrade-provisionPool',
'zcf-b1-db93f-provisionPool',
);

/** @type {any} */
const provisionPoolParamsAfter = await readLatestHead(
'published.provisionPool.governance',
);

t.deepEqual(
provisionPoolParamsAfter.current.PerAccountInitialAmount,
provisionPoolParamsBefore.current.PerAccountInitialAmount,
'provisionPool governed parameters did not match',
);
},
);

test.serial('Governance proposals history is visible', async t => {
/*
* List ordered from most recent to earliest of Economic Committee
* parameter changes proposed prior to the execution of this test.
*
* XXX a dynamic solution should replace this hardcoded list to ensure
* the acceptance tests scalability
*/
const expectedParametersChanges = [
['PerAccountInitialAmount'], // z:acceptance/governance.test.js
['ChargingPeriod'], // z:acceptance/governance.test.js
['DebtLimit'], // z:acceptance/vaults.test.js
['GiveMintedFee', 'MintLimit', 'WantMintedFee'], // z:acceptance/psm.test.js
['DebtLimit'], // z:acceptance/scripts/test-vaults.mts
['ClockStep', 'PriceLockPeriod', 'StartFrequency'], // z:acceptance/scripts/test-vaults.mts
['DebtLimit'], // agoric-3-proposals/proposals/34:upgrade-10/performActions.js
['ClockStep', 'PriceLockPeriod', 'StartFrequency'], // agoric-3-proposals/proposals/34:upgrade-10/performActions.js
];

// history of Economic Committee parameters changes proposed since block height 0
const history = await governanceDriver.getLatestQuestionHistory();
t.true(
history.length > 0,
'published.committees.Economic_Committee.latestQuestion node should not be empty',
);

const changedParameters = history.map(changes => Object.keys(changes));

/*
* In case you see the error message bellow and you
* executed an VoteOnParamChange offer prior to this test,
* please make sure to update the expectedParametersChanges list.
*/
if (
!(
JSON.stringify(changedParameters) ===
JSON.stringify(expectedParametersChanges)
)
) {
console.error(
`ERROR: Economic_Committee parameters changes history does not match with the expected list`,
);
t.log('Economic_Committee parameters changes history: ', changedParameters);
t.log('Expected parameters changes history: ', expectedParametersChanges);
}
});
4 changes: 3 additions & 1 deletion a3p-integration/proposals/z:acceptance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"testing/start-valueVow.js start-valueVow",
"testing/recorded-retired-instances.js recorded-instances-submission",
"vats/test-localchain.js localchaintest-submission",
"testing/restart-valueVow.js restart-valueVow"
"testing/restart-valueVow.js restart-valueVow",
"testing/upgrade-vaultFactory.js upgrade-vaultFactory",
"vats/upgrade-provisionPool.js upgrade-provisionPool"
]
},
"type": "module",
Expand Down
Loading
Loading