Skip to content

test(share): add full test coverage for share token contract#589

Open
DeborahOlaboye wants to merge 1 commit into
astera-hq:mainfrom
DeborahOlaboye:test/share-token-coverage
Open

test(share): add full test coverage for share token contract#589
DeborahOlaboye wants to merge 1 commit into
astera-hq:mainfrom
DeborahOlaboye:test/share-token-coverage

Conversation

@DeborahOlaboye

Copy link
Copy Markdown
Contributor

Summary

Closes #578

The share token contract had zero tests despite being the voting-power primitive for governance. This PR adds a complete test suite across three layers:

  • contracts/share/tests/lib.rs — 12 integration tests covering all checklist gaps: allowance overwrite, zero-approve clearing, transfer_from with insufficient balance, transfer_from to self, burn auth enforcement, sender auth on transfer, and i128 large-value overflow safety
  • contracts/share/tests/fuzz_tests.rs — 5 property-based tests (proptest, 50 cases each): total_supply == sum of balances, balance >= 0 invariant, allowance-never-underflows, transfer is net-zero on supply, burn reduces supply exactly
  • contracts/share/Cargo.toml — added rlib crate-type, proptest = "1.4" dev-dep, and [[test]] entries for both test files
  • .github/workflows/ci.yml — added share to the rust-contracts matrix (fmt + clippy + build + test on every PR)

Test plan

  • cargo test -p share passes locally — 33 tests total (16 inline + 12 integration + 5 fuzz)
  • All issue checklist items covered
  • CI matrix updated to run share contract on every PR

…hq#578)

The share token had zero tests despite being the voting-power primitive
for governance. This commit adds:

- contracts/share/tests/lib.rs: 12 integration tests covering the gaps
  not reached by the inline test module — allowance overwrite, zero-
  approve clearing, transfer_from with insufficient balance, transfer_from
  to self, burn auth enforcement, sender auth on transfer, and i128 large-
  value overflow safety.

- contracts/share/tests/fuzz_tests.rs: 5 property-based tests using
  proptest (50 cases each):
    * total_supply == sum of all holder balances
    * balance(addr) >= 0 after any mint+partial-burn sequence
    * allowance never underflows below 0 after transfer_from
    * transfer is net-zero on total_supply
    * burn reduces total_supply by exactly the burned amount

- contracts/share/Cargo.toml: added rlib crate-type (required for the
  external test crate to link against share), proptest 1.4 dev-dep, and
  [[test]] entries for both test files.

- .github/workflows/ci.yml: added share to the rust-contracts matrix so
  CI runs fmt, clippy, build, and cargo test on every PR.

All 33 tests pass locally (16 inline + 12 integration + 5 fuzz).

Closes astera-hq#578
@sanmipaul

Copy link
Copy Markdown
Contributor

@DeborahOlaboye Great work on this, the proptest invariants are well-chosen, the doc-comments explaining why each property matters are exactly right, and the CI matrix addition is clean. A few things before merge:

Must fix

test_burn_requires_admin_auth has no tokens minted before attempting the burn.
holder has zero balance, so the test may be failing on "insufficient balance" rather than "unauthorized" — it passes for the wrong reason. Mint tokens to holder first so the test actually isolates the auth check:

client.mint(&holder, &100i128);
let result = client.try_burn(&holder, &100i128);
assert!(result.is_err());

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.

test: share token contract has zero test coverage — transfer, allowance, and edge case behaviors are unverified

2 participants