diff --git a/contracts/escrow/src/lib.rs b/contracts/escrow/src/lib.rs index 0641057..07136d6 100644 --- a/contracts/escrow/src/lib.rs +++ b/contracts/escrow/src/lib.rs @@ -308,6 +308,14 @@ impl EscrowContract { Ok(m.player1_deposited && m.player2_deposited) } + /// Return the oracle address set at initialization. + pub fn get_oracle(env: Env) -> Result { + env.storage() + .instance() + .get(&DataKey::Oracle) + .ok_or(Error::Unauthorized) + } + /// Return the total escrowed balance for a match (0, 1x, or 2x stake). pub fn get_escrow_balance(env: Env, match_id: u64) -> Result { let m: Match = env diff --git a/contracts/escrow/src/tests.rs b/contracts/escrow/src/tests.rs index 9ce2f9c..f4194d0 100644 --- a/contracts/escrow/src/tests.rs +++ b/contracts/escrow/src/tests.rs @@ -912,3 +912,29 @@ fn test_escrow_balance_zero_after_draw() { assert_eq!(client.get_escrow_balance(&id), 0); } + +#[test] +fn test_get_oracle_returns_initialized_address() { + let (env, contract_id, oracle, _player1, _player2, _token, _admin) = setup(); + let client = EscrowContractClient::new(&env, &contract_id); + assert_eq!(client.get_oracle(), oracle); +} + +#[test] +fn test_get_match_returns_correct_players() { + let (env, contract_id, _oracle, player1, player2, token, _admin) = setup(); + let client = EscrowContractClient::new(&env, &contract_id); + + let id = client.create_match( + &player1, + &player2, + &100, + &token, + &String::from_str(&env, "players_test"), + &Platform::Lichess, + ); + + let m = client.get_match(&id); + assert_eq!(m.player1, player1); + assert_eq!(m.player2, player2); +} diff --git a/contracts/escrow/test_snapshots/tests/test_admin_unpause_allows_create_match.1.json b/contracts/escrow/test_snapshots/tests/test_admin_unpause_allows_create_match.1.json index 50786bf..34b2bf4 100644 --- a/contracts/escrow/test_snapshots/tests/test_admin_unpause_allows_create_match.1.json +++ b/contracts/escrow/test_snapshots/tests/test_admin_unpause_allows_create_match.1.json @@ -420,6 +420,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_cancel_active_match_fails_with_invalid_state.1.json b/contracts/escrow/test_snapshots/tests/test_cancel_active_match_fails_with_invalid_state.1.json index 0ee7ac9..a996f6b 100644 --- a/contracts/escrow/test_snapshots/tests/test_cancel_active_match_fails_with_invalid_state.1.json +++ b/contracts/escrow/test_snapshots/tests/test_cancel_active_match_fails_with_invalid_state.1.json @@ -487,6 +487,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_cancel_match_emits_event.1.json b/contracts/escrow/test_snapshots/tests/test_cancel_match_emits_event.1.json index 5208186..9e17c37 100644 --- a/contracts/escrow/test_snapshots/tests/test_cancel_match_emits_event.1.json +++ b/contracts/escrow/test_snapshots/tests/test_cancel_match_emits_event.1.json @@ -379,6 +379,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_cancel_refunds_deposit.1.json b/contracts/escrow/test_snapshots/tests/test_cancel_refunds_deposit.1.json index e83dda5..7fb801a 100644 --- a/contracts/escrow/test_snapshots/tests/test_cancel_refunds_deposit.1.json +++ b/contracts/escrow/test_snapshots/tests/test_cancel_refunds_deposit.1.json @@ -460,6 +460,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_create_match.1.json b/contracts/escrow/test_snapshots/tests/test_create_match.1.json index 9f8b214..87c3598 100644 --- a/contracts/escrow/test_snapshots/tests/test_create_match.1.json +++ b/contracts/escrow/test_snapshots/tests/test_create_match.1.json @@ -325,6 +325,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_create_match_emits_event.1.json b/contracts/escrow/test_snapshots/tests/test_create_match_emits_event.1.json index 341068a..ffadfd6 100644 --- a/contracts/escrow/test_snapshots/tests/test_create_match_emits_event.1.json +++ b/contracts/escrow/test_snapshots/tests/test_create_match_emits_event.1.json @@ -324,6 +324,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_deposit_and_activate.1.json b/contracts/escrow/test_snapshots/tests/test_deposit_and_activate.1.json index c389286..3b13e41 100644 --- a/contracts/escrow/test_snapshots/tests/test_deposit_and_activate.1.json +++ b/contracts/escrow/test_snapshots/tests/test_deposit_and_activate.1.json @@ -485,6 +485,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_draw_refund.1.json b/contracts/escrow/test_snapshots/tests/test_draw_refund.1.json index e329434..702c252 100644 --- a/contracts/escrow/test_snapshots/tests/test_draw_refund.1.json +++ b/contracts/escrow/test_snapshots/tests/test_draw_refund.1.json @@ -543,6 +543,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_get_match_returns_stake_and_token.1.json b/contracts/escrow/test_snapshots/tests/test_get_match_returns_stake_and_token.1.json index 631600b..de5e33b 100644 --- a/contracts/escrow/test_snapshots/tests/test_get_match_returns_stake_and_token.1.json +++ b/contracts/escrow/test_snapshots/tests/test_get_match_returns_stake_and_token.1.json @@ -325,6 +325,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_payout_winner.1.json b/contracts/escrow/test_snapshots/tests/test_payout_winner.1.json index 87a4f20..ec82d92 100644 --- a/contracts/escrow/test_snapshots/tests/test_payout_winner.1.json +++ b/contracts/escrow/test_snapshots/tests/test_payout_winner.1.json @@ -543,6 +543,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_player2_cancel_only_player2_deposited.1.json b/contracts/escrow/test_snapshots/tests/test_player2_cancel_only_player2_deposited.1.json index ee806ed..0c807db 100644 --- a/contracts/escrow/test_snapshots/tests/test_player2_cancel_only_player2_deposited.1.json +++ b/contracts/escrow/test_snapshots/tests/test_player2_cancel_only_player2_deposited.1.json @@ -460,6 +460,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_player2_cancel_pending_match.1.json b/contracts/escrow/test_snapshots/tests/test_player2_cancel_pending_match.1.json index 555e9fb..8fbd773 100644 --- a/contracts/escrow/test_snapshots/tests/test_player2_cancel_pending_match.1.json +++ b/contracts/escrow/test_snapshots/tests/test_player2_cancel_pending_match.1.json @@ -380,6 +380,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_player2_cancel_refunds_both_players.1.json b/contracts/escrow/test_snapshots/tests/test_player2_cancel_refunds_both_players.1.json index 48c176c..2eb01a7 100644 --- a/contracts/escrow/test_snapshots/tests/test_player2_cancel_refunds_both_players.1.json +++ b/contracts/escrow/test_snapshots/tests/test_player2_cancel_refunds_both_players.1.json @@ -483,6 +483,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_submit_result_emits_event.1.json b/contracts/escrow/test_snapshots/tests/test_submit_result_emits_event.1.json index c3fde42..362243f 100644 --- a/contracts/escrow/test_snapshots/tests/test_submit_result_emits_event.1.json +++ b/contracts/escrow/test_snapshots/tests/test_submit_result_emits_event.1.json @@ -541,6 +541,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_cancel.1.json b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_cancel.1.json index bac561c..a3f7f9a 100644 --- a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_cancel.1.json +++ b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_cancel.1.json @@ -380,6 +380,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_create_match.1.json b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_create_match.1.json index 6f1c11d..cc82f26 100644 --- a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_create_match.1.json +++ b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_create_match.1.json @@ -325,6 +325,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_deposit.1.json b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_deposit.1.json index a69a669..bb9edbe 100644 --- a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_deposit.1.json +++ b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_deposit.1.json @@ -404,6 +404,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_submit_result.1.json b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_submit_result.1.json index a37df2c..94a578a 100644 --- a/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_submit_result.1.json +++ b/contracts/escrow/test_snapshots/tests/test_ttl_extended_on_submit_result.1.json @@ -542,6 +542,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id" diff --git a/contracts/escrow/test_snapshots/tests/test_unauthorized_player_cannot_cancel.1.json b/contracts/escrow/test_snapshots/tests/test_unauthorized_player_cannot_cancel.1.json index 057e39e..eb90b2d 100644 --- a/contracts/escrow/test_snapshots/tests/test_unauthorized_player_cannot_cancel.1.json +++ b/contracts/escrow/test_snapshots/tests/test_unauthorized_player_cannot_cancel.1.json @@ -325,6 +325,14 @@ "durability": "persistent", "val": { "map": [ + { + "key": { + "symbol": "created_ledger" + }, + "val": { + "u32": 0 + } + }, { "key": { "symbol": "game_id"