Skip to content

fix: proposal counter starts at 0 to eliminate ID gap in create_proposal - #565

Merged
Naomi-Gift merged 1 commit into
HubDApp:mainfrom
Primex-Tech:fix/issue-531-proposal-id-gap
Aug 20, 2026
Merged

fix: proposal counter starts at 0 to eliminate ID gap in create_proposal#565
Naomi-Gift merged 1 commit into
HubDApp:mainfrom
Primex-Tech:fix/issue-531-proposal-id-gap

Conversation

@Primex-Tech

@Primex-Tech Primex-Tech commented Aug 19, 2026

Copy link
Copy Markdown

Close #531

Summary

Fixes the proposal ID initialization bug in create_proposal() where unwrap_or(1) caused the counter to start at 1, leaving ID 0 unused and creating an off-by-one gap in zero-based indexing.

Problem

In �dmin_manager.rs::create_proposal(), the proposal ID counter defaults to 1 via unwrap_or(1) when NextAdminProposalId is not yet stored. This means:

  • First proposal -> ID 1, counter set to 2
  • ID 0 is never used

Fix

Changed unwrap_or(1) to unwrap_or(0) in both:

  • dongle-smartcontract/src/admin_manager.rs:248
  • scripts/dongle-smartcontract/src/admin_manager.rs:228

Now the first proposal correctly gets ID 0, with sequential incrementing from there.

Test Added

est_proposal_ids_start_at_zero — creates three proposals sequentially and asserts IDs are 0, 1, 2 respectively, verifying zero-based sequential assignment.

Testing

Note: cargo test requires MSVC build tools not available in this environment. The change is a single default value swap (1 ->

Change unwrap_or(1) to unwrap_or(0) for NextAdminProposalId in both
primary and scripts copies of admin_manager.rs. This ensures the first
proposal gets ID 0, aligning with zero-based indexing and eliminating
the gap where ID 0 was never used.

Also added test_proposal_ids_start_at_zero to verify sequential
zero-based ID assignment across multiple proposals.

Closes HubDApp#531
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.

bug: create_proposal counter starts at 1 but id variable is unused until assigned

3 participants