Skip to content

test: add new_supply to KeysBoughtEvent and unit tests for buy event supply tracking - #711

Merged
Chucks1093 merged 3 commits into
accesslayerorg:mainfrom
unlimitedengineer:test/buy-event-new-supply-698
Aug 24, 2026
Merged

test: add new_supply to KeysBoughtEvent and unit tests for buy event supply tracking#711
Chucks1093 merged 3 commits into
accesslayerorg:mainfrom
unlimitedengineer:test/buy-event-new-supply-698

Conversation

@unlimitedengineer

Copy link
Copy Markdown
Contributor

Closes #698

Summary

  • Adds new_supply: u32 to KeysBoughtEvent so the buy event reflects the total supply after the purchase (not before).
  • Updates buy_key in lib.rs to populate new_supply from the already-incremented profile.supply value.
  • Updates BUY_EVENT_DATA_FIELDS const to include "new_supply".
  • Adds creator-keys/tests/key_purchased_new_supply.rs with unit tests covering all four acceptance criteria.
  • Aligns the field-order assertion and supply-tracking test in tests/events.rs.

Test plan

  • Single buy from supply 0 → event new_supply: 1
  • Buy from supply 10 → event new_supply: 11
  • Two sequential buys emit new_supply: 1, then new_supply: 2
  • Five sequential buys: each event new_supply matches get_total_key_supply after the call
  • No buy event emitted when buy fails (insufficient payment)
  • new_supply in event equals get_total_key_supply return value after every buy

…event supply tracking

Closes accesslayerorg#698

Add new_supply: u32 to KeysBoughtEvent so the buy event reflects the
total supply after the purchase rather than before. Update the buy
function in lib.rs to populate new_supply from the already-incremented
profile.supply value.

Add creator-keys/tests/key_purchased_new_supply.rs covering all four
acceptance criteria:
- Single buy from supply 0 emits new_supply: 1
- Buy from supply 10 emits new_supply: 11
- Two sequential buys emit incrementing new_supply (1, then 2)
- Five sequential buys each match get_total_key_supply after the call
- No buy event is emitted when the buy fails (insufficient payment)
- new_supply in the event equals get_total_key_supply after each buy

Also update BUY_EVENT_DATA_FIELDS to include "new_supply" and align the
field-order assertion and supply-tracking test in tests/events.rs.
@Chucks1093

Copy link
Copy Markdown
Member

This is a solid change. Including new_supply directly in the buy event removes any guesswork about the supply state after a purchase and the sequential buy tests give good confidence that the value is always accurate.

@Chucks1093
Chucks1093 merged commit c56a70b into accesslayerorg:main Aug 24, 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

Development

Successfully merging this pull request may close these issues.

Add unit tests for the buy function emitting a KeyPurchased event with the correct new supply after each purchase

2 participants