This document describes the test data population script for the Celo governance database.
The populateTestData.ts script populates a local database with test proposals covering all 26 possible proposal states in the Celo governance system. This is useful for:
- Development and testing
- UI/UX testing of all proposal states
- Database schema validation
- Integration testing
The script includes multiple safety checks to prevent accidental execution on production databases:
- Local Database Check: Verifies that
POSTGRES_URLpoints tolocalhostor127.0.0.1 - Production Environment Check: Blocks execution if
IS_PRODUCTION_DATABASE=trueorNODE_ENV=production - Conflict Handling: Uses
onConflictDoNothing()to prevent overwriting existing data
- Ensure you have a local PostgreSQL database running
- Set your
.envfile to point to the local database:POSTGRES_URL=postgresql://user:password@localhost:5432/celo_mondo_test
yarn populate-test-dataThe script creates 26 proposals covering the following states:
- In draft - No on-chain events, metadata only
- In queue without upvotes - Queued but no upvotes yet
- In queue with upvotes - Queued with active upvotes
- Expired from queued stage - Never dequeued, expired after 28 days
- With revoked upvotes - Had upvotes that were later revoked
- Referendum - Yes > No, No Quorum, No Approval
- Referendum - Yes > No, Passing Quorum, No Approval
- Referendum - Yes > No, No Quorum, Approved
- Referendum - Yes > No, Passing Quorum, Approved
- Referendum - No > Yes, No Quorum
- Referendum - No > Yes, Passing Quorum
- Referendum - Tied Votes (equal YES and NO)
- With revoked votes - Had votes that were later revoked
- Execution - No Approval
- Execution - Partial Approval
- Execution - Full Approval
- Successfully Executed - Completed and executed
- Expired from referendum - Approved
- Expired from referendum - No Approval
- Expired from execution - Approved
- Expired from execution - No Approval
- Withdrawn from queue
- Withdrawn from referendum
- Withdrawn from execution
- Rejected - Expired with more NO votes than YES votes
- Original proposal (rejected) and Re-submitted proposal (active) - Demonstrates the
pastIdlinking
For each test run, the script generates:
- 26 proposals with IDs starting from 1000 (1000-1026)
- CGP numbers starting from 9000 (9000-9025)
- ~60+ events (ProposalQueued, ProposalDequeued, ProposalApproved, ProposalExecuted, etc.)
- ~70+ vote records (Yes, No, Abstain votes for each proposal)
- ~18+ approvals records (0-3 for proposals in referendum, 3 for executed proposals)
All proposals reference the mock proposal file at:
https://raw.githubusercontent.com/celo-org/celo-mondo/main/mock-proposal.md
- Uses current time as base reference
- Calculates historical timestamps for expired/completed proposals
- Uses realistic time intervals (28 days for queue expiry, 7 days for referendum, 3 days for execution)
- Network weight: 1M CELO (1,000,000,000,000,000,000,000,000 wei)
- Quorum threshold: 1% of network weight (10K CELO)
- Half quorum: 5K CELO
- Double quorum: 20K CELO
Proposals are created with various vote distributions to test:
- Passing quorum (votes > 10K CELO)
- Not passing quorum (votes < 10K CELO)
- More YES than NO votes
- More NO than YES votes
- Equal YES and NO votes (tied)
- Block numbers start at 20,000,000 and increment
- Transaction hashes are generated as mock values for uniqueness
The script populates three main tables:
events- Governance events (ProposalQueued, ProposalDequeued, etc.)proposals- Proposal metadata and statevotes- Vote counts (Yes, No, Abstain) for each proposalapprovalsApproval Confirmations for proposals
To remove test data, you can run SQL queries to delete proposals with IDs >= 1000:
DELETE FROM votes WHERE "proposalId" >= 1000;
DELETE FROM proposals WHERE id >= 1000;
DELETE FROM events WHERE (args->>'proposalId')::bigint >= 1000;Or simply drop and recreate your local test database.
- Ensure your
POSTGRES_URLenvironment variable points to localhost - Check that you're not using a remote database connection
- Set
NODE_ENVtodevelopmentor remove it - Ensure
IS_PRODUCTION_DATABASEis not set totrue
- The script uses
onConflictDoNothing()to avoid overwriting data - If you need fresh data, clear test proposals first (see Cleanup section)
Possible improvements:
- Add CLI flags for customizing proposal ID ranges
- Support for creating specific proposal states on demand
- Option to clear existing test data before populating
- Generate more realistic vote distributions
- Add support for multi-sig approval tracking