Skip to content

Commit

Permalink
fix: handle new gov proposal query shape (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Feb 12, 2024
1 parent 8524c77 commit 53cf87b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
53 changes: 32 additions & 21 deletions packages/synthetic-chain/src/lib/commonUpgradeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,35 @@ export const addUser = async user => {
export const voteLatestProposalAndWait = async () => {
await waitForBlock();
const proposalsData = await agd.query('gov', 'proposals');
const lastProposalId = proposalsData.proposals.at(-1).proposal_id;
let lastProposal = proposalsData.proposals.at(-1);

lastProposal || Fail`No proposal found`;

const lastProposalId = lastProposal.proposal_id || lastProposal.id;

lastProposalId || Fail`Invalid proposal ${lastProposal}`;

if (lastProposal.status === 'PROPOSAL_STATUS_DEPOSIT_PERIOD') {
await agd.tx(
'gov',
'deposit',
lastProposalId,
'50000000ubld',
'--from',
VALIDATORADDR,
`--chain-id=${CHAINID}`,
'--yes',
'--keyring-backend',
'test',
);

await waitForBlock();
await waitForBlock();

await agd.tx(
'gov',
'deposit',
lastProposalId,
'50000000ubld',
'--from',
VALIDATORADDR,
`--chain-id=${CHAINID}`,
'--yes',
'--keyring-backend',
'test',
);
lastProposal = await agd.query('gov', 'proposal', lastProposalId);
}

await waitForBlock();
lastProposal.status === 'PROPOSAL_STATUS_VOTING_PERIOD' ||
Fail`Latest proposal ${lastProposalId} not in voting period (status=${lastProposal.status})`;

await agd.tx(
'gov',
Expand All @@ -182,19 +193,19 @@ export const voteLatestProposalAndWait = async () => {
'test',
);

let info = {};
for (
;
info.status !== 'PROPOSAL_STATUS_REJECTED' &&
info.status !== 'PROPOSAL_STATUS_PASSED';
lastProposal.status !== 'PROPOSAL_STATUS_PASSED' &&
lastProposal.status !== 'PROPOSAL_STATUS_REJECTED' &&
lastProposal.status !== 'PROPOSAL_STATUS_FAILED';
await waitForBlock()
) {
info = await agd.query('gov', 'proposal', lastProposalId);
lastProposal = await agd.query('gov', 'proposal', lastProposalId);
console.log(
`Waiting for proposal ${lastProposalId} to pass (status=${info.status})`,
`Waiting for proposal ${lastProposalId} to pass (status=${lastProposal.status})`,
);
}
return info;
return { proposal_id: lastProposalId, ...lastProposal };
};

const Fail = (template, ...args) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/synthetic-chain/upgrade-test-scripts/env_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ test_not_val() {

voteLatestProposalAndWait() {
waitForBlock
proposal=$($binary q gov proposals -o json | jq -r '.proposals[-1].proposal_id')
proposal=$($binary q gov proposals -o json | jq -r '.proposals | last | if .proposal_id == null then .id else .proposal_id end')
waitForBlock
$binary tx -bblock gov deposit $proposal 50000000ubld --from=validator --chain-id="$CHAINID" --yes --keyring-backend test
waitForBlock
Expand Down

0 comments on commit 53cf87b

Please sign in to comment.