Skip to content

Commit

Permalink
test(a3p): extend governance test with proposals history
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Lopes committed Dec 13, 2024
1 parent 778a713 commit 77f5205
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
56 changes: 55 additions & 1 deletion a3p-integration/proposals/z:acceptance/governance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import test from 'ava';

import { GOV1ADDR, GOV2ADDR } from '@agoric/synthetic-chain';
import { makeGovernanceDriver } from './test-lib/governance.js';
import { networkConfig, walletUtils } from './test-lib/index.js';
import { walletUtils } 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];
Expand Down Expand Up @@ -184,3 +185,56 @@ test.serial(
);
},
);

test.serial('Governance proposals history is visible', async t => {
/*
* List ordered from most recent to latest 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

Check warning on line 200 in a3p-integration/proposals/z:acceptance/governance.test.js

View workflow job for this annotation

GitHub Actions / lint-rest

Replace `·'DebtLimit'·` with `'DebtLimit'`
['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`,
);
console.log(
'Economic_Committee parameters changes history: ',
changedParameters,
);
console.log(
'Expected parameters changes history: ',
expectedParametersChanges,
);
}
});
25 changes: 22 additions & 3 deletions a3p-integration/proposals/z:acceptance/test-lib/governance.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* global setTimeout */

import { agops, agoric, executeOffer } from '@agoric/synthetic-chain';
import { makeVstorageKit, retryUntilCondition } from '@agoric/client-utils';
import { retryUntilCondition } from '@agoric/client-utils';
import { walletUtils } from './index.js';
import {
checkCommitteeElectionResult,
fetchLatestEcQuestion,
} from './psm-lib.js';
import { makeVstorageKit } from './rpc.js';

/**
* @param {typeof window.fetch} fetch
* @param {import('@agoric/client-utils').MinimalNetworkConfig} networkConfig
* @param {import('./rpc.js').MinimalNetworkConfig} networkConfig
*/
export const makeGovernanceDriver = async (fetch, networkConfig) => {
const { readLatestHead, marshaller } = await makeVstorageKit(
const { readLatestHead, marshaller, vstorage } = await makeVstorageKit(
{ fetch },
networkConfig,
);
Expand Down Expand Up @@ -221,11 +222,29 @@ export const makeGovernanceDriver = async (fetch, networkConfig) => {
return { latestOutcome, latestQuestion };
};

const getLatestQuestionHistory = async () => {
const nodePath = 'published.committees.Economic_Committee.latestQuestion';

const historyIterator = await vstorage.readHistory(nodePath);
const history = [];

for await (const data of historyIterator) {
if (data) {
const question = marshaller.fromCapData(JSON.parse(data[0]));
const changes = question.positions[0].changes;
history.push(changes);
}
}

return history;
};

return {
voteOnProposedChanges,
proposeParamChange,
getCharterInvitation,
getCommitteeInvitation,
getLatestQuestion,
getLatestQuestionHistory,
};
};

0 comments on commit 77f5205

Please sign in to comment.