Skip to content

test: add unit & integration tests for get_price at zero supply (#720) - #732

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Oluwasuyi-Oluwatimilehin-Daniel:test/get-price-zero-supply-720
Aug 25, 2026
Merged

test: add unit & integration tests for get_price at zero supply (#720)#732
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Oluwasuyi-Oluwatimilehin-Daniel:test/get-price-zero-supply-720

Conversation

@Oluwasuyi-Oluwatimilehin-Daniel

Copy link
Copy Markdown
Contributor

Summary

At supply 0 (when no keys are in circulation for a creator), get_price should return the configured base_price constant — representing the price of the very first key on the bonding curve. At supply 1, get_price must return a price strictly greater than base_price when a positive slope is configured.

This PR exposes get_price on CreatorKeysContract and adds unit and integration test suites covering all boundary conditions, curve presets, and invariant checks.

Closes #720


Changes

1. Contract Entrypoint (creator-keys/src/lib.rs)

  • Added pub fn get_price(env: Env, creator: Address, supply: u64) -> Result<i128, ContractError> to CreatorKeysContract.
  • Serves as a read-only bonding curve price query helper at arbitrary supply steps with overflow protection.

2. Unit Tests (creator-keys/src/test_issues.rs)

  • test_get_price_at_supply_zero_returns_base_price_and_greater_at_supply_one: Verifies supply 0 returns base_price, supply 1 returns base_price + slope > base_price, and asserts neither call panics (including try_get_price).
  • test_get_price_various_base_prices_at_supply_zero: Checks supply 0 and supply 1 across multiple base prices ([1, 10, 100, 500, 1000, 10000, 50000]).
  • test_get_price_presets_at_supply_zero_and_one: Verifies Linear, Quadratic, and Flat curve presets at supply 0 and 1.

3. Integration & Boundary Tests (creator-keys/tests/get_price_zero_supply.rs)

  • Standard Linear Curve: Confirms AC-1, AC-2, AC-3 with try-call equivalents.
  • Multiple Base Prices: Verifies price calculations across wide magnitudes (from 1 to 1,000,000 stroops).
  • Curve Presets: Verifies Linear, Quadratic, and Flat curve mathematics.
  • Read-Only Invariant: Asserts contract state, supply, and balances are unchanged across repeated invocations.
  • Quote Parity: Validates consistency between get_price, query_price, and get_buy_quote.
  • Error Handling: Verifies graceful error return (ContractError::KeyPriceNotSet) when key price is uninitialized.
  • Emergency Pause: Confirms get_price remains callable and answers correctly while the contract is paused.

Acceptance Criteria Checklist

  • Supply 0 returns the configured base price constant
  • Supply 1 returns a price strictly above base price (when slope > 0)
  • No panic in either case (both get_price and try_get_price)
  • Tested across multiple base prices and presets (Linear, Quadratic, Flat)
  • State is strictly read-only and unmutated

Verification

# Integration tests
cargo test --test get_price_zero_supply
# Output: 7 passed; 0 failed; finished in 0.19s

# Unit tests
cargo test --lib test_issues::issue_tests::test_get_price
# Output: 3 passed; 0 failed; finished in 0.94s

# Full test suite
cargo test
# Output: 169 passed; 0 failed; 0 ignored

# Linters & Formatters
cargo fmt --check
cargo clippy --all-targets

accesslayerorg#720)

- Add get_price entrypoint to CreatorKeysContract as read-only price query helper
- Add unit tests in test_issues.rs for supply 0 base price, supply 1 strictly greater price, and no-panic assertions
- Add integration tests in tests/get_price_zero_supply.rs covering base price variations, curve presets, read-only state preservation, and pause compatibility

Closes accesslayerorg#720
@drips-wave

drips-wave Bot commented Aug 24, 2026

Copy link
Copy Markdown

@Oluwasuyi-Oluwatimilehin-Daniel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit b0ecfab into accesslayerorg:main Aug 25, 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 get_price returning the base price when supply is zero

2 participants