Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ impl EscrowContract {
env.storage()
.persistent()
.set(&DataKey::ActiveMatches, &active);
env.storage().persistent().extend_ttl(
&DataKey::ActiveMatches,
MATCH_TTL_LEDGERS,
MATCH_TTL_LEDGERS,
);

env.events().publish(
(Symbol::new(&env, "match"), symbol_short!("created")),
Expand Down Expand Up @@ -714,10 +719,19 @@ impl EscrowContract {

/// Return all currently active (non-cancelled, non-completed) match IDs.
pub fn get_active_matches(env: Env) -> Vec<u64> {
env.storage()
let active: Vec<u64> = env
.storage()
.persistent()
.get(&DataKey::ActiveMatches)
.unwrap_or_else(|| vec![&env])
.unwrap_or_else(|| vec![&env]);
if !active.is_empty() {
env.storage().persistent().extend_ttl(
&DataKey::ActiveMatches,
MATCH_TTL_LEDGERS,
MATCH_TTL_LEDGERS,
);
}
active
}

/// Add a token to the allowlist. Requires admin auth.
Expand Down Expand Up @@ -750,6 +764,11 @@ impl EscrowContract {
env.storage()
.persistent()
.set(&DataKey::ActiveMatches, &active);
env.storage().persistent().extend_ttl(
&DataKey::ActiveMatches,
MATCH_TTL_LEDGERS,
MATCH_TTL_LEDGERS,
);
}
}
}
Expand Down
61 changes: 61 additions & 0 deletions contracts/escrow/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,67 @@ fn test_ttl_extended_on_deposit() {
assert_eq!(ttl, crate::MATCH_TTL_LEDGERS);
}

#[test]
fn test_active_matches_ttl_refreshed_on_append_and_removal() {
let (env, contract_id, _oracle, player1, player2, token, _admin) = setup();
let client = EscrowContractClient::new(&env, &contract_id);

let match1 = client.create_match(
&player1,
&player2,
&100,
&token,
&String::from_str(&env, "ttl_active_append_remove_1"),
&Platform::Lichess,
);

env.ledger().set(soroban_sdk::testutils::LedgerInfo {
sequence_number: env.ledger().sequence() + 1000,
timestamp: env.ledger().timestamp() + 5000,
protocol_version: 22,
network_id: Default::default(),
base_reserve: 10,
min_temp_entry_ttl: 1,
min_persistent_entry_ttl: 1,
max_entry_ttl: crate::MATCH_TTL_LEDGERS + 2000,
});

let _match2 = client.create_match(
&player1,
&player2,
&100,
&token,
&String::from_str(&env, "ttl_active_append_remove_2"),
&Platform::Lichess,
);

let ttl_after_append = env.as_contract(&contract_id, || {
env.storage().persistent().get_ttl(&DataKey::ActiveMatches)
});
assert_eq!(ttl_after_append, crate::MATCH_TTL_LEDGERS);

client.deposit(&match1, &player1);
client.deposit(&match1, &player2);

env.ledger().set(soroban_sdk::testutils::LedgerInfo {
sequence_number: env.ledger().sequence() + 1000,
timestamp: env.ledger().timestamp() + 5000,
protocol_version: 22,
network_id: Default::default(),
base_reserve: 10,
min_temp_entry_ttl: 1,
min_persistent_entry_ttl: 1,
max_entry_ttl: crate::MATCH_TTL_LEDGERS + 2000,
});

client.submit_result(&match1, &Winner::Player1);

let ttl_after_removal = env.as_contract(&contract_id, || {
env.storage().persistent().get_ttl(&DataKey::ActiveMatches)
});
assert_eq!(ttl_after_removal, crate::MATCH_TTL_LEDGERS);
}

#[test]
fn test_ttl_extended_on_submit_result() {
let (env, contract_id, _oracle, player1, player2, token, _admin) = setup();
Expand Down
28 changes: 14 additions & 14 deletions task1.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#618 Add Test: escrow instance TTL is refreshed after create_match
Repo Avatar
StellarCheckMate/Checkmate-Escrow
Status: Open - unassigned
Labels: testing, storage
Priority: Medium
Description:
Coverage for issue #3 should include creation paths.
Tasks:
Inspect instance TTL before and after create_match
Assert refresh
#618 Add Test: escrow instance TTL is refreshed after create_match
Repo Avatar
StellarCheckMate/Checkmate-Escrow
Status: Open - unassigned
Labels: testing, storage
Priority: Medium

Description:
Coverage for issue #3 should include creation paths.

Tasks:

Inspect instance TTL before and after create_match
Assert refresh