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

Add Governor component #1180

Open
wants to merge 99 commits into
base: main
Choose a base branch
from

Conversation

ericnordelo
Copy link
Member

Fixes #294

PR Checklist

  • Tests
  • Documentation
  • Added entry to CHANGELOG.md
  • Tried the feature on a public network

…eat/remove-mocks-from-released-package-#1141
* feat: remove modules

* fix: mock

* fix: linter

* fix: tests

* fix: mock

* feat: apply review suggestions
…eat/remove-mocks-from-released-package-#1141
…eat/remove-mocks-from-released-package-#1141
…eat/remove-mocks-from-released-package-#1141
Copy link
Collaborator

@immrsd immrsd left a comment

Choose a reason for hiding this comment

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

Great job, Eric! That wasn't an easy walkthrough, the feature is really complex. It's looking good, I left several comments

packages/governance/src/governor/interface.cairo Outdated Show resolved Hide resolved
packages/governance/src/governor/interface.cairo Outdated Show resolved Hide resolved
packages/governance/src/governor/interface.cairo Outdated Show resolved Hide resolved
packages/utils/src/bytearray.cairo Outdated Show resolved Hide resolved
Comment on lines +502 to +505
self
.validate_state(
proposal_id, array![ProposalState::Succeeded, ProposalState::Queued].span()
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to be overkill for checking the state: we have to create an array and iterate through it. Maybe a more direct approach would be better

Suggested change
self
.validate_state(
proposal_id, array![ProposalState::Succeeded, ProposalState::Queued].span()
);
match self.state(proposal_id) {
ProposalState::Succeeded => (),
ProposalState::Queued => (),
_ => panic_with_felt252(Errors:: UNEXPECTED_PROPOSAL_STATE),

Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably more efficient, but the validate_state helper can be used by users as well. We can refactor it into bitmap operations to avoid looping or matching, which should be even more efficient, and also usable by users. Let's keep the thread opened until the pending stuff is finished and I will work on that then.

@ericnordelo ericnordelo marked this pull request as ready for review November 15, 2024 00:05
ref self: ComponentState<TContractState>, calls: Span<Call>, description_hash: felt252
) -> felt252 {
let proposal_id = self._hash_proposal(calls, description_hash);
self.validate_state(proposal_id, array![ProposalState::Pending].span());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to cancel a queued proposal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't be possible, why?

Copy link
Collaborator

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

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

Fantastic job with the first iteration of tests! I left some comments

packages/governance/src/governor/governor.cairo Outdated Show resolved Hide resolved
packages/governance/src/governor/governor.cairo Outdated Show resolved Hide resolved
packages/utils/src/bytearray.cairo Outdated Show resolved Hide resolved
packages/utils/src/bytearray.cairo Outdated Show resolved Hide resolved
packages/governance/src/tests/governor/test_governor.cairo Outdated Show resolved Hide resolved
packages/governance/src/tests/governor/test_governor.cairo Outdated Show resolved Hide resolved
packages/governance/src/governor/governor.cairo Outdated Show resolved Hide resolved
Comment on lines 125 to 126
/// Temporary defined as a function since constant ByteArray is not supported yet.
fn DEFAULT_PARAMS() -> Span<felt252>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should adjust the comment. Maybe test this with a non-empty span, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment adjusted. Will revisit tests after finishing tests for extensions.

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.

Governance Contracts
3 participants