-
Notifications
You must be signed in to change notification settings - Fork 0
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 Comprehensive Tests for Governance and Oracle Features #4
Open
emmanuelist
wants to merge
60
commits into
main
Choose a base branch
from
feature/test-continue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…, and pausing the contract
- Add constants and error codes for governance contract - Adds constant values for contract owner and error codes such as `ERR_UNAUTHORIZED, ERR_INVALID_PROPOSAL,` and more.
- Define data variables for proposal count, stake, and voting period - Initializes proposal-count, min-proposal-stake, and voting-period.
- Define maps for proposals and user votes tracking - Defines proposals and user-votes data structures.
- Implement SIP-010 token trait for fungible token interactions - Adds the trait ft-trait with functions like transfer and get-balance to interact with tokens.
- Add private helper function for token transfers - Defines a private function transfer-tokens to manage token transfers between principals.
- Add function to create a proposal with staking mechanism - Implements the logic for creating a proposal, ensuring the proposer has enough stake and transferring tokens.
- Add function to cast votes on proposals - Allows users to vote either for or against a proposal and ensures they haven't voted before.
- Add function to end a proposal and determine result - Adds the logic for concluding a proposal and refunding tokens based on the outcome (pass or reject).
- Add read-only functions for proposal and vote status" Implements functions `get-proposal`, `get-user-vote`, and `get-proposal-count` for querying the state.
- Add admin function to update the minimum proposal stake - Allows the contract owner to modify the minimum stake required for creating proposals.
- Add admin function to update the voting period - Allows the contract owner to modify the voting period duration.
- Define constants for contract owner, error codes, and update intervals. - Define data variables for storing STX price, last update time, and update interval.
- Add public function to update the STX price. - Include authorization checks to ensure only the contract owner can update the price. - Validate the price to ensure it is greater than zero. - Ensure the update interval has passed before allowing a new update. - Update the last update time and STX price. - Print an event indicating the price has been updated.
- Add get-stx-price function to return the current STX price. - Add get-last-update function to return the last update time.
- Add public function to allow the contract owner to update the interval. - Include authorization checks to ensure only the contract owner can update the interval. - Validate the new interval to ensure it is within the allowed range. - Update the update interval.
- Set up test environment with Vitest and Stacks transactions. - Add test to ensure users can create proposals.
- Add test to ensure users can vote on proposals. - Verify that the vote is recorded correctly.
- Add test to ensure users cannot vote twice on the same proposal. - Verify that an error is returned for the second vote.
- Add test to ensure proposals can be ended after the voting period. - Simulate time passing and verify the proposal status.
- Add test to ensure proposals cannot be ended before the voting period is over. - Verify that an error is returned if attempted.
- Add test to ensure the contract owner can set the minimum proposal stake. - Verify that the new stake value is set correctly.
- Add test to ensure the contract owner can set the voting period. - Verify that the new voting period is set correctly.
- Add test to ensure only the contract owner can access admin functions. - Verify that an error is returned for unauthorized access.
…rotocol into feature/test-continue
…col into feature/test-continue
- Set up test environment with Vitest and Stacks transactions. - Add test to ensure the owner can set the STX price.
- Add test to ensure anyone can read the STX price.
- Add test to ensure non-owners cannot set the STX price. - Verify that an error is returned for unauthorized access.
- Add test to ensure the price cannot be set to zero. - Verify that an error is returned for invalid price.
- Add test to ensure the last update block height can be read.
- Add test to ensure the owner can set the update interval. - Verify that the new interval value is set correctly.
- Add test to ensure the update interval cannot be set to an invalid value. - Verify that an error is returned for invalid interval.
- Add test to ensure the price cannot be updated before the interval has passed. - Verify that an error is returned if attempted.
- Add test to ensure the price can be updated after the interval has passed. - Simulate time passing and verify the price update.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a comprehensive suite of tests for our governance and oracle features. These tests ensure the correct functionality of proposal creation, voting mechanisms, admin controls, and price oracle operations.
Changes
Governance Tests
Oracle Tests
Testing
All new tests have been run and pass successfully. To run the tests:
npm install
npm run test
Reviewers
@contract-reviewer
@security-expert
@token-specialist
Checklist
Additional Notes
This PR significantly improves our test coverage for critical governance and oracle functionalities. It ensures that our smart contract behaves as expected under various scenarios and provides a solid foundation for future development and maintenance.