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

Anyone should be able to activate an account's vote #7517

Merged
merged 19 commits into from
Apr 2, 2021

Conversation

deepakhb2
Copy link
Contributor

@deepakhb2 deepakhb2 commented Mar 24, 2021

Description

Currently an accounts pending votes can be activated by the same account. This change will allow to activate any other accounts pending vote. But, the account should belong to group i.e is passed. A new method is added to implement this change and non of the existing methods are modified.

Other change

Upgraded Election contract to inherit InitializableV2.

Tested

Added unit tests to cover this change.

Related issues

Backwards compatibility

As this change is made by added a new method and it doesn't affect the existing features.

Function accepts group and account parameter to activate pending votes of any account.
Extract common functionality from activate to _activate method.
@deepakhb2 deepakhb2 requested a review from a team March 24, 2021 21:38
@deepakhb2
Copy link
Contributor Author

@nambrot The tests are failing due to ElectionTestInstance interface don't have the new property that was added as part of this change. Any idea where this interface is defined? It looks like this is defined in some other repo.

@nambrot
Copy link
Contributor

nambrot commented Mar 25, 2021

Hmm that is a good question. It's based upon https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/contracts/governance/test/ElectionTest.sol#L9:L9 which should inherit the method and therefore should have it during type generation

@nambrot
Copy link
Contributor

nambrot commented Mar 25, 2021

Is it passing locally for you?

Copy link
Contributor

@AlexBHarley AlexBHarley left a comment

Choose a reason for hiding this comment

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

Nice! I'm a big fan of this functionality, it will be a great UX improvement for staking services.

packages/protocol/test/governance/voting/election.ts Outdated Show resolved Hide resolved
packages/protocol/test/governance/voting/election.ts Outdated Show resolved Hide resolved
})
})

describe('when another voter activates votes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm all for more tests but I feel this logic is already tested by the #activate.when another voter activates votes test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already tested by activate for negative scenarios. In this case it positive test cases for activateByAccount method.

@deepakhb2
Copy link
Contributor Author

deepakhb2 commented Mar 25, 2021

Thank you @nambrot for pointing me to the file how the types are generated and I had made typo while calling the method from test.
I tried running the tests locally and I see more fails with other issues. Also, I am not sure if I used the right command to run the tests locally.

@nambrot
Copy link
Contributor

nambrot commented Mar 26, 2021

What command are you using to run the test? For the initializable error, consider checking out #7254, you just have to make Election inherit from the new InitializableV2 library instead of the old one

@deepakhb2
Copy link
Contributor Author

@nambrot I tried running tests using npm run test command.

@deepakhb2
Copy link
Contributor Author

@m-chrzan I think ElectionTestContract needs some update. I am not sure if InitializableV2 is creating issues during build. https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/test/governance/voting/lockedgold.ts#L33 please let me know if I am missing something here. Thank you.

@m-chrzan
Copy link
Contributor

@m-chrzan I think ElectionTestContract needs some update. I am not sure if InitializableV2 is creating issues during build. https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/test/governance/voting/lockedgold.ts#L33 please let me know if I am missing something here. Thank you.

Huh, so this appears to be a slight bug in the test that hadn't been caught before. To fix this particular error message, it should be enough to change that line to

const Election: ElectionContract = artifacts.require('Election')

(since we're requireing the Election contract, not the ElectionTest one) and then propagating those changes throughout the file (changing imports, changing references to ElectionTest to Election).

I imagine you might then start running into issues with the ElectionTest contract itself, since it inherits from Election (which now inherits from InitializableV2), so also needs to call its parent constructor. Since ElectionTest will always be used in testing, just doing

contract ElectionTest is Election(true) {

should be enough.

Change the type of Election contract in test to ElectionContract.
@deepakhb2
Copy link
Contributor Author

@m-chrzan I think ElectionTestContract needs some update. I am not sure if InitializableV2 is creating issues during build. https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/test/governance/voting/lockedgold.ts#L33 please let me know if I am missing something here. Thank you.

Huh, so this appears to be a slight bug in the test that hadn't been caught before. To fix this particular error message, it should be enough to change that line to

const Election: ElectionContract = artifacts.require('Election')

(since we're requireing the Election contract, not the ElectionTest one) and then propagating those changes throughout the file (changing imports, changing references to ElectionTest to Election).

I imagine you might then start running into issues with the ElectionTest contract itself, since it inherits from Election (which now inherits from InitializableV2), so also needs to call its parent constructor. Since ElectionTest will always be used in testing, just doing

contract ElectionTest is Election(true) {

should be enough.

Thank you @m-chrzan for sharing more details around this issue with solution.

@deepakhb2
Copy link
Contributor Author

@nambrot One required 'certora-test' is failing. Is it related to this PR?

@yorhodes
Copy link
Contributor

@nambrot One required 'certora-test' is failing. Is it related to this PR?

@deepakhb2 This is unrelated and there was a fix merged to master today. I have updated your branch.

Copy link
Contributor

@yorhodes yorhodes left a comment

Choose a reason for hiding this comment

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

1 nit

packages/protocol/contracts/governance/Election.sol Outdated Show resolved Hide resolved
@nambrot
Copy link
Contributor

nambrot commented Apr 1, 2021

@deepakhb2 Looks like there is a linting error?

@deepakhb2
Copy link
Contributor Author

@nambrot for election.ts file the prettier check is getting passed on my local machine. I am not sure if this is with election.ts file.

@yorhodes
Copy link
Contributor

yorhodes commented Apr 1, 2021

@nambrot for election.ts file the prettier check is getting passed on my local machine. I am not sure if this is with election.ts file.

Patch for the lint fix
https://gist.github.com/yorhodes/1181c8d1cd64426f2a4af529a64ef3ec

Generated from
yarn prettier -w --config .prettierrc.js packages/protocol/test/governance/voting/election.ts

@nambrot
Copy link
Contributor

nambrot commented Apr 1, 2021

@yorhodes @deepakhb2 Can one of y'all apply the patch, and if it passes then I can merge

Signed-off-by: Deepak HB <deepakhb2@gmail.com>
@deepakhb2
Copy link
Contributor Author

@nambrot I have applied the patch and lint-checks is passed.

@nambrot nambrot merged commit 969abc0 into celo-org:master Apr 2, 2021
@deepakhb2 deepakhb2 deleted the issue/6467-activate-account branch April 2, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anyone should be able to activate an account's vote
5 participants