Skip to content

feat: add key supply view, zero-amount validation, payment helper, and event tests#23

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
playground-ogazboiz:feat/issue-18-20-21-22-contract-enhancements
Mar 26, 2026
Merged

feat: add key supply view, zero-amount validation, payment helper, and event tests#23
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
playground-ogazboiz:feat/issue-18-20-21-22-contract-enhancements

Conversation

@ogazboiz

Copy link
Copy Markdown
Contributor

Closes #18
Closes #20
Closes #21
Closes #22

Summary

Adds a read-only key supply view method, zero-amount purchase validation with a shared helper, and comprehensive event payload tests.

Changes

get_total_key_supply view method (#18)

  • New read-only method returning u32 supply for a creator
  • Returns 0 for unregistered creators (no panic)
  • 4 tests: new creator, unregistered, increments after buy, read-only verification

Zero-amount purchase validation (#20)

  • buy_key() now explicitly rejects payment <= 0 before any other checks
  • Panics with "payment amount must be positive" for zero or negative amounts
  • 3 tests: zero payment, negative payment, positive payment succeeds

Shared payment amount helper (#21)

  • Added assert_positive_amount(amount: i128) — reusable validation
  • Used in both buy_key() and set_key_price() (replaces inline check)
  • Consistent error message across all payment validation
  • 2 tests: zero price, negative price via set_key_price

Event payload tests (#22)

  • test_register_creator_emits_event — verifies "register" topic
  • test_register_creator_event_fires_once — exactly one event
  • test_buy_key_emits_event_with_correct_topics — verifies "buy" topic + creator + buyer addresses
  • test_buy_key_event_data_is_new_supply — supply=1 then supply=2
  • test_buy_key_event_present_after_purchase — buy event in log

Test Results

30 tests passing (14 new + 16 existing), 0 failures

How to test

cargo test --workspace

@Chucks1093 Chucks1093 merged commit 0be87bf into accesslayerorg:main Mar 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants