test(share): add full test coverage for share token contract#589
Open
DeborahOlaboye wants to merge 1 commit into
Open
test(share): add full test coverage for share token contract#589DeborahOlaboye wants to merge 1 commit into
DeborahOlaboye wants to merge 1 commit into
Conversation
…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
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
client.mint(&holder, &100i128);
let result = client.try_burn(&holder, &100i128);
assert!(result.is_err()); |
This file contains hidden or 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
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.
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_fromwith insufficient balance,transfer_fromto self, burn auth enforcement, sender auth on transfer, andi128large-value overflow safetycontracts/share/tests/fuzz_tests.rs— 5 property-based tests (proptest, 50 cases each):total_supply == sum of balances,balance >= 0invariant, allowance-never-underflows, transfer is net-zero on supply, burn reduces supply exactlycontracts/share/Cargo.toml— addedrlibcrate-type,proptest = "1.4"dev-dep, and[[test]]entries for both test files.github/workflows/ci.yml— addedshareto the rust-contracts matrix (fmt + clippy + build + test on every PR)Test plan
cargo test -p sharepasses locally — 33 tests total (16 inline + 12 integration + 5 fuzz)