From b7b981b5c6fc5da4cd00fbcbfffebff62054be9f Mon Sep 17 00:00:00 2001 From: KingDavid9999 Date: Wed, 29 Jul 2026 04:53:53 -0700 Subject: [PATCH 1/3] test: add integration test for buy/sell revert when paused (#643) Add pause_blocks_buy_sell_integration.rs covering the full pause/unpause lifecycle in a single flow: pause via admin, buy reverts with ProtocolPaused, sell reverts with ProtocolPaused, supply/balance remain unchanged during the paused window, then unpause and confirm buy succeeds and increments supply as expected. Closes #643 --- .../pause_blocks_buy_sell_integration.rs | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 creator-keys/tests/pause_blocks_buy_sell_integration.rs diff --git a/creator-keys/tests/pause_blocks_buy_sell_integration.rs b/creator-keys/tests/pause_blocks_buy_sell_integration.rs new file mode 100644 index 00000000..dda36d29 --- /dev/null +++ b/creator-keys/tests/pause_blocks_buy_sell_integration.rs @@ -0,0 +1,95 @@ +//! Integration test for issue #643. +//! +//! Scope: +//! - Initialize the contract and pause it via the admin pause function +//! - Invoke buy and assert the transaction reverts with the paused error code +//! - Invoke sell and assert it also reverts with the paused error code +//! - Unpause the contract and assert a subsequent buy succeeds +//! - Assert no supply or balance changes occur while the contract is paused + +mod contract_test_env; + +use contract_test_env::{register_creator_keys, register_test_creator, set_pricing_and_fees, test_env_with_auths}; +use creator_keys::ContractError; +use soroban_sdk::{testutils::Address as _, Address}; + +const KEY_PRICE: i128 = 1_000; +const CREATOR_BPS: u32 = 9_000; +const PROTOCOL_BPS: u32 = 1_000; + +#[test] +fn test_buy_and_sell_revert_while_paused_then_buy_succeeds_after_unpause() { + let env = test_env_with_auths(); + let (client, _) = register_creator_keys(&env); + set_pricing_and_fees(&env, &client, KEY_PRICE, CREATOR_BPS, PROTOCOL_BPS); + + let admin = Address::generate(&env); + client.set_protocol_admin(&admin, &admin); + + let creator = register_test_creator(&env, &client, "alice"); + let buyer = Address::generate(&env); + + // Baseline: one key purchased before pausing so sell has something to act on. + let quote = client.get_buy_quote(&creator); + client.buy_key(&creator, &buyer, "e.total_amount, &None); + + let supply_before_pause = client.get_total_key_supply(&creator); + let balance_before_pause = client.get_key_balance(&creator, &buyer); + assert_eq!(supply_before_pause, 1); + assert_eq!(balance_before_pause, 1); + + // --- Pause the contract via the admin function --- + client.pause(&admin); + assert!(client.get_is_paused()); + + // --- buy reverts with the paused error code while paused --- + let buy_quote_while_paused = client.get_buy_quote(&creator); + let buy_result = client.try_buy_key(&creator, &buyer, &buy_quote_while_paused.total_amount, &None); + assert_eq!( + buy_result, + Err(Ok(ContractError::ProtocolPaused)), + "buy must revert with ProtocolPaused while contract is paused" + ); + + // --- sell reverts with the paused error code while paused --- + let sell_result = client.try_sell_key(&creator, &buyer, &None); + assert_eq!( + sell_result, + Err(Ok(ContractError::ProtocolPaused)), + "sell must revert with ProtocolPaused while contract is paused" + ); + + // --- No supply or balance changes occur while paused --- + assert_eq!( + client.get_total_key_supply(&creator), + supply_before_pause, + "supply must be unchanged after failed buy/sell attempts while paused" + ); + assert_eq!( + client.get_key_balance(&creator, &buyer), + balance_before_pause, + "buyer balance must be unchanged after failed buy/sell attempts while paused" + ); + + // --- Unpause the contract --- + client.unpause(&admin); + assert!(!client.get_is_paused()); + + // --- A subsequent buy succeeds after unpausing --- + let quote_after_unpause = client.get_buy_quote(&creator); + let new_supply = client.buy_key(&creator, &buyer, "e_after_unpause.total_amount, &None); + + assert_eq!( + new_supply, + supply_before_pause + 1, + "buy after unpause must succeed and increment supply by exactly 1" + ); + assert_eq!( + client.get_total_key_supply(&creator), + supply_before_pause + 1 + ); + assert_eq!( + client.get_key_balance(&creator, &buyer), + balance_before_pause + 1 + ); +} From 3a9ce1a4f7c8a7546804a92d147af3c8c413162a Mon Sep 17 00:00:00 2001 From: KingDavid9999 Date: Wed, 29 Jul 2026 04:57:58 -0700 Subject: [PATCH 2/3] style: apply cargo fmt to pause/unpause integration test Fix formatting in pause_blocks_buy_sell_integration.rs flagged by `cargo fmt --all -- --check`: wrap the multi-import use statement and the try_buy_key call to match rustfmt's line-width rules. --- .../tests/pause_blocks_buy_sell_integration.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/creator-keys/tests/pause_blocks_buy_sell_integration.rs b/creator-keys/tests/pause_blocks_buy_sell_integration.rs index dda36d29..bd3fe6e8 100644 --- a/creator-keys/tests/pause_blocks_buy_sell_integration.rs +++ b/creator-keys/tests/pause_blocks_buy_sell_integration.rs @@ -9,7 +9,9 @@ mod contract_test_env; -use contract_test_env::{register_creator_keys, register_test_creator, set_pricing_and_fees, test_env_with_auths}; +use contract_test_env::{ + register_creator_keys, register_test_creator, set_pricing_and_fees, test_env_with_auths, +}; use creator_keys::ContractError; use soroban_sdk::{testutils::Address as _, Address}; @@ -44,7 +46,12 @@ fn test_buy_and_sell_revert_while_paused_then_buy_succeeds_after_unpause() { // --- buy reverts with the paused error code while paused --- let buy_quote_while_paused = client.get_buy_quote(&creator); - let buy_result = client.try_buy_key(&creator, &buyer, &buy_quote_while_paused.total_amount, &None); + let buy_result = client.try_buy_key( + &creator, + &buyer, + &buy_quote_while_paused.total_amount, + &None, + ); assert_eq!( buy_result, Err(Ok(ContractError::ProtocolPaused)), @@ -92,4 +99,4 @@ fn test_buy_and_sell_revert_while_paused_then_buy_succeeds_after_unpause() { client.get_key_balance(&creator, &buyer), balance_before_pause + 1 ); -} +} \ No newline at end of file From 12a757e427fbf12a7120bb3ba26bf6bd5c1e9216 Mon Sep 17 00:00:00 2001 From: KingDavid9999 Date: Wed, 29 Jul 2026 05:05:33 -0700 Subject: [PATCH 3/3] style: apply cargo fmt to pause/unpause integration test --- creator-keys/tests/pause_blocks_buy_sell_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/creator-keys/tests/pause_blocks_buy_sell_integration.rs b/creator-keys/tests/pause_blocks_buy_sell_integration.rs index bd3fe6e8..9d526c3a 100644 --- a/creator-keys/tests/pause_blocks_buy_sell_integration.rs +++ b/creator-keys/tests/pause_blocks_buy_sell_integration.rs @@ -99,4 +99,4 @@ fn test_buy_and_sell_revert_while_paused_then_buy_succeeds_after_unpause() { client.get_key_balance(&creator, &buyer), balance_before_pause + 1 ); -} \ No newline at end of file +}