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 Comprehensive Tests for Governance and Oracle Features #4

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

Conversation

emmanuelist
Copy link
Owner

@emmanuelist emmanuelist commented Sep 30, 2024

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

  • Set up test environment with Vitest and Stacks transactions
  • Add tests for proposal creation and management:
    • Creating proposals
    • Voting on proposals
    • Preventing double voting
    • Ending proposals after the voting period
    • Preventing early proposal termination
  • Add tests for admin functions:
    • Setting minimum proposal stake
    • Setting voting period
    • Preventing unauthorized access to admin functions

Oracle Tests

  • Set up test environment for oracle functionality
  • Add tests for STX price management:
    • Setting STX price by owner
    • Reading STX price
    • Preventing non-owners from setting price
    • Preventing invalid price settings
  • Add tests for update mechanics:
    • Reading last update block height
    • Setting update interval
    • Preventing invalid update interval
    • Enforcing update interval before price changes
    • Allowing updates after interval has passed

Testing

All new tests have been run and pass successfully. To run the tests:

  1. Ensure you have the latest dependencies installed: npm install
  2. Run the test suite: npm run test

Reviewers

@contract-reviewer
@security-expert
@token-specialist

Checklist

  • Code follows the project's coding standards
  • Tests for the changes have been added and all pass
  • Documentation has been updated (if necessary)
  • Changes generate no new warnings or errors
  • Any dependent changes have been merged and published in downstream modules

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.

- 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.
- 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant