test(workspace): wire settle_position through public API with token balance assertions#284
Open
christabel888 wants to merge 196 commits into
Open
Conversation
* feature/withdraw-unused-collateral * feature/withdraw-unused-collateral * feature/withdraw-unused-collateral
Co-authored-by: Yusuf Habib <109147010+manlikeHB@users.noreply.github.com>
* feature/resolve-market-oracle * feature/resolve-market-oracle
…ix-Protocol#71) Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…tix-Protocol#74) Co-authored-by: Cursor <cursoragent@cursor.com>
onboarding fixes for expiration, deposit, withdraw docs, and positions errors
…es to public items
…itionAlreadySettled
- Define ValidationFailedEvent in events.rs with context and error_code fields - Add emit_validation_failed() helper function - Add test asserting event emission and field values
Replace flat Symbol constants (MARKETS_KEY, POSITIONS_KEY, ADMIN_KEY, COUNTER_KEY) with a contracttype StorageKey enum. No behavior change.
Add TODO(#issue) references near each emit_* call site explaining potential future improvements to the event payloads.
- Assert all error discriminant values match their documented ranges - Assert equality and inequality between variants - Assert ordering across error categories
Explicitly reject withdrawals when total_deposited is zero before computing locked collateral, preventing silent unwrap_or(0) fallthrough. Adds test_withdraw_zero_deposited_rejected to cover the rejection.
…rams HarnessError variants carry doc comments explaining the failure cause. MarketParams::default_valid provides a reusable baseline for integration tests, removing the need for repeated boilerplate setup.
Documents all arguments, return value, error variants, emitted event, and includes an inline example showing typical usage.
…ejected Defines PositionLimitExceededEvent in events.rs with market_id, user, and side_yes (which share side would go negative). update_position now emits the event before returning ShareBalanceBelowZero. Adds test_update_position_limit_exceeded_emits_event to assert emission.
Adds a Next.js frontend under apps/web, plus scripts to generate/publish 375 onboarding issues across the three Vatix repos. Updates CI and docs to include the new frontend workflow.
Add a no-layout-shift loading skeleton
…contract-improvements Onboarding/contract improvements
…ding-tasks Feature/onboarding tasks
…ct-tasks Onboarding/contract tasks
…mission-tests feat(contracts): add event emission unit tests
…/onboarding-tasks-147-148-149-150 fix: complete onboarding tasks for frontend, contracts, and tooling
…142-ci-comment-jsdoc-error-messages feat: issue 140, 141, 142
- Fix missing Vec import and Position PartialEq derive in market contract - Remove unused ContractError import from positions module - Delete TypeScript test files lacking test dependencies and not run by CI - Contract now compiles successfully (4 pre-existing test failures remain) - Web app builds and lints successfully
Ran cargo fmt to standardize code formatting across market contract source files and removed conflicting pnpm version specification in GitHub Actions workflow. The pnpm version is now sourced from package.json's packageManager field.
- Add #[allow(dead_code)] to unused event structs and functions (ValidationFailedEvent, OracleSignatureVerifiedEvent, and their emit functions) - Simplify boolean expression in position_limit_exceeded_side: new_yes < 0 || new_no < 0 - Use range contains for market price validation: !(0..=10_000).contains(&price)
…code in test - Fixed position_limit_exceeded_side to properly return boolean value instead of unit type - Updated test_initialize_market_non_admin_fails to expect correct error code Vatix-Protocol#41 (NotAdmin) instead of Vatix-Protocol#40 (Unauthorized) - This brings total passing tests from 112 to 113
…thdraw edge case events - Fixed test_collateral_deposit_emits_event: register mock StellarAssetClient token and mint tokens to user - Fixed test_withdraw_success_updates_position_and_transfers: move token mint after mock_all_auths for proper authorization - Fixed test_withdraw_edge_case_emits_event: query events inside as_contract block and simplify to check event count All 116 tests now passing
Expose share trading on MarketContract
…tion-tests Implement workspace integration tests using tests/helpers harness
…ontract - Add ContractError::AlreadyInitialized (Vatix-Protocol#42) to error.rs to guard against re-initialization replay attacks on the admin slot - Add storage::has_admin() helper that returns true when the ADMIN_KEY persistent slot is populated; used by initialize() to enforce one-time bootstrap semantics - Add ContractInitializedEvent and emit_contract_initialized() to events.rs so off-chain indexers can confirm which address owns a freshly deployed contract - Expose MarketContract::initialize(env, admin) in lib.rs: 1. admin.require_auth() — cryptographic proof of ownership 2. Guard: if has_admin() -> Err(AlreadyInitialized) — prevents hijack 3. storage::set_admin() — persists the admin address 4. emit_contract_initialized() — publishes the bootstrap event This closes the dependency gap described in Vatix-Protocol#245: previously the admin slot could only be written by test-only as_contract bypasses, making the deployed contract unusable (initialize_market panics on missing admin). The new function gives deployers a safe, authorized on-chain path to bootstrap the contract. - Add tests in test.rs covering: * test_initialize_sets_admin_and_emits_event * test_initialize_allows_subsequent_market_creation * test_initialize_twice_fails_with_already_initialized * test_initialize_second_admin_fails - Extend storage test: test_admin_storage now asserts has_admin() returns false before set_admin() and true after - Extend events test: test_emit_contract_initialized verifies topic symbol and admin address topic Closes Vatix-Protocol#245
…ic ordering Soroban contractevent macro only prepends the struct-name symbol as topic[0] when the event has both topic fields AND data fields. A struct with only topic fields emits them starting at index 0 with no name symbol prefix, so the assertion: assert_eq!(topic0, Symbol::new(env, contract_initialized_event)) was comparing the name symbol against the admin Address, causing the test to fail. Fix: add initialized_at: u64 as a data field. This gives the macro a non-topic payload to serialize, which causes it to emit the name symbol at topic[0] as expected. The field is also useful context for indexers. Update test_emit_contract_initialized to assert the initialized_at data field as well.
…//github.com/Meshmulla/vatix-contract into feature/245-add-initialize-admin-entry-point
…ayout Add settle_position public API with SAC token payout transfer
…initialize-admin-entry-point feat(contracts): add initialize(admin) deploy entry point for MarketContract
…osition, and withdraw deposit_collateral incremented locked_collateral by the deposit amount, so a fresh deposit with zero shares already looked fully locked. Meanwhile withdraw_unused_collateral ignored the stored locked_collateral and recomputed its own lock from a hardcoded 50/50 price, diverging from the real trade price update_position actually used. Make update_position's calculate_locked_collateral the single source of truth: deposit no longer touches locked_collateral, and withdraw now reads Position.locked_collateral directly instead of recomputing it. Adds regression tests for both bugs plus a randomized property test asserting locked_collateral <= total_deposited across deposit/buy/withdraw sequences, and a MIGRATION.md note for anyone with seeded position state predating this fix. Closes Vatix-Protocol#262 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e-locked-collateral fix(contracts): reconcile locked_collateral between deposit, update_position, and withdraw
…alance assertions Closes Vatix-Protocol#270 Upgrades the workspace-level full-lifecycle test in tests/settlement_test.rs to call client.settle_position() (the public contract entry point) instead of the internal settlement::execute_settlement helper. The test now asserts that: - collateral tokens move from the contract to the user on settlement - double-settlement is rejected - position.is_settled is set Also adds assert_any_event_emitted to tests/helpers/mod.rs to search the full event log for a topic, needed because settle_position emits position_settled_event followed by a SAC transfer event (so the existing last-event helper would match the wrong event). Updates settlement_before_resolution_is_rejected to go through the public client instead of internal APIs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
@christabel888 bug filled commit 'fix and push will be happy to review |
Author
I am fixing conflicts from the github app not my VScode, so i did not make a commit, hope this is not an issue @Mimah97 |
Contributor
|
@christabel888 you are recomminting the whole work and it is not correct |
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.
Closes #270
Summary
full_lifecycle_init_create_deposit_resolve_settleintests/settlement_test.rsto callclient.settle_position()(the public contract entry point) instead of the internalsettlement::execute_settlementhelper, completing the deposit → trade → resolve → settle → payout loop through the public APItry_settle_positionsettlement_before_resolution_is_rejectedto useclient.settle_position()instead of internal APIs, matching the correct contract error code#3assert_any_event_emittedtotests/helpers/mod.rsto search the full event log for a topic (needed becausesettle_positionemitsposition_settled_eventfollowed by a SACtransferevent, so the existing last-event assertion would match the wrong event)Test plan
cargo testat repo root passes (134 tests: 9 workspace integration + 125 contract unit tests)full_lifecycle_init_create_deposit_resolve_settleuses publicclient.settle_position()and asserts token balancessettlement_before_resolution_is_rejectedtriggers via public client and panics withError(Contract, #3)🤖 Generated with Claude Code