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
8 changes: 8 additions & 0 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address, Error> {
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<i128, Error> {
let m: Match = env
Expand Down
26 changes: 26 additions & 0 deletions contracts/escrow/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
8 changes: 8 additions & 0 deletions contracts/escrow/test_snapshots/tests/test_draw_refund.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@
"durability": "persistent",
"val": {
"map": [
{
"key": {
"symbol": "created_ledger"
},
"val": {
"u32": 0
}
},
{
"key": {
"symbol": "game_id"
Expand Down
Loading