Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Implement voteOnProposal command #220

Merged

Conversation

Irfan-Personal
Copy link
Contributor

What was the problem?

This PR resolves #126 for the dexGovernace module.

How was it solved?

  • Added voteOnProposal command in voteOnProposal.ts file.
  • Registered command in modules.ts folder.

How was it tested?

  • Command verification and execute tests are added in commandVoteOnProposal.spec.ts file.
  • All tests are passing.

@Irfan-Personal Irfan-Personal added this to the Sprint 20 milestone Feb 27, 2023
@Irfan-Personal Irfan-Personal self-assigned this Feb 27, 2023
@Irfan-Personal Irfan-Personal linked an issue Feb 27, 2023 that may be closed by this pull request
Copy link
Contributor

@emiliolisk emiliolisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove the coverage-final.json file from your PR, as that should be generated on GitHub


public commands = [];
public commands = [this.__createvoteOnPorposalCommand];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the typos to "Proposal" and add proper caps/names where needed, for example this would be this._voteOnProposalCommand

Copy link
Contributor Author

@Irfan-Personal Irfan-Personal Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was not aligned with command name so change it to
this.__createvoteOnPorposalCommand => __voteOnPorposalCommand at the required places in code.
I will push the code soon.


const index = ctx.params.proposalIndex;

const stakedAmount = (await this._posEndpoint.getLockedStakedAmount(moduleEndpointContext))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it was already added as a method here, I think it would make more sense to use that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emiliolisk I think I am already using the method you mentioned here. I have an import at the top of file as well:
import { PoSEndpoint } from 'lisk-framework/dist-node/modules/pos/endpoint';
Can you please give a look again. Thanks

emiliolisk

This comment was marked as duplicate.

methodContext,
this.stores.get(ProposalsStore),
index,
voteInfos[itr]!.amount,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be -amount, i.e. we deduce the previously cast votes from the total result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov true replaces this line with:
-voteStoreInfos[itr]!.amount,

voteInfos[itr]!.amount,
voteInfos[itr]!.decision,
);
votesStoreInfo.setKey(methodContext, [senderAddress], newVoteInfo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the code correctly, there is an error here. I think you set the votes store entry to newVoteInfo, but voteInfos is an array that should mostly stay the same i.e. the entries for this address for other votes should not be deleted. You should reassign voteInfos[itr] = newVoteInfo.voteInfos[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov
Updated this and replaced.
votesStoreInfo.setKey(methodContext, [senderAddress], newVoteInfo);
=>
voteInfos[itr] = newVoteInfo.voteInfos[0];


if (
!previousSavedStorescheck &&
(await votesStoreInfo.get(methodContext, senderAddress)).voteInfos.length <

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small suggestion: you could use voteInfos.length here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov updated it to your recommendation.

);
} else if (!previousSavedStorescheck) {
[(await votesStoreInfo.get(methodContext, senderAddress)).voteInfos[smallestproposalIndex]] =
newVoteInfo.voteInfos;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be newVoteInfo.voteInfos[0].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov agree and that is why changed it to:
[voteStoreInfos[smallestproposalIndex]] = newVoteInfo.voteInfos;
it is doing array destructing in TS and it is equal to:
voteStoreInfos[smallestproposalIndex] = newVoteInfo.voteInfos[0];

@@ -51,3 +51,5 @@ export const DECISION_NO = 1; // Code for the vote decision "No".
export const DECISION_PASS = 2; // Code for the vote decision "Pass".

export const defaultConfig = {};

export const COMMAND_ID_VOTE_ON_PORPOSAL = Buffer.from('0002', 'hex');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have command IDs anymore, instead we have command names:

COMMAND_VOTE_ON_PROPOSAL | string | "voteOnProposal" | Command name of the vote command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov chnaged it to:

export const COMMAND_VOTE_ON_PORPOSAL = 'voteOnProposal';

@@ -38,7 +38,7 @@ export const ProposalVotedEventSchema = {
},
voterAddress: {
dataType: 'bytes',
length: LENGTH_ADDRESS,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The address of the voter should be exactly 20 bytes (i.e. LENGTH_ADDRESS). So the previous version was correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov if change it to length it gives a schema validator error
Rejected to value: [Error: Lisk validator found 1 error[s]: strict mode: unknown keyword: "length"]

expect(result.error?.message).toBe('Decision does not exist');
expect(result.status).toEqual(VerifyStatus.FAIL);
});
it('should Fail with Proposal does not exist message', async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a test case for a revote. Like this: cast a vote with x tokens and decision No, recast a vote from the same account with x tokens and decision Yes. Check that votesYes for the proposal increased by x while votesNo decreased by x.

Copy link
Contributor Author

@Irfan-Personal Irfan-Personal Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyshemyakov I agree and that's why I have updated the tests and included these lines:
The bases value for votesYes and votesNo is 100;
expect((await dexGovernanceStore.getKey(methodContext, [indexBuffer])).votesNo).toBe( BigInt(95), ); expect((await dexGovernanceStore.getKey(methodContext, [indexBuffer])).votesYes).toBe( BigInt(205), );

@Daniel-Lightcurve Daniel-Lightcurve merged commit 90adb55 into feature/governance Feb 27, 2023
@Naureen1lightcurve Naureen1lightcurve removed this from the Sprint 20 milestone Feb 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement voteOn Proposal command
5 participants