Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend unit testing for elo-ranking #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
60 changes: 58 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,9 @@ fn check_elo_stronger_looses() {
}

#[test]
fn check_elo_player_aborts() {
fn check_elo_player_draws() {
new_test_ext().execute_with(|| {
System::set_block_number(1);

let alice = account("Alice", 0, 0);
let bob = account("Bob", 0, 1);

Expand Down Expand Up @@ -578,6 +577,63 @@ fn check_elo_player_aborts() {
});
}

#[test]
fn check_elo_stronger_abandon() {
new_test_ext().execute_with(|| {
System::set_block_number(1);

let alice = account("Alice", 0, 0);
let bob = account("Bob", 0, 1);

let bet_asset_id = AssetId::get();
let bet_amount = AssetMinBalance::get() * 5;

assert_ok!(Chess::create_match(
RuntimeOrigin::signed(bob),
alice,
MatchStyle::Bullet,
bet_asset_id,
bet_amount
));

let match_id = Chess::chess_match_id_from_nonce(0).unwrap();

assert_ok!(Chess::join_match(RuntimeOrigin::signed(alice), match_id));

// check elo before the match finishes
assert_eq!(Chess::player_elo(alice), 2000);
assert_eq!(Chess::player_elo(bob), 2400);

assert_ok!(Chess::make_move(
RuntimeOrigin::signed(bob),
match_id,
"f2f3".into()
));
assert_ok!(Chess::make_move(
RuntimeOrigin::signed(alice),
match_id,
"e7e5".into()
));

// advance the block number to the point where bob's time-to-move is expired
System::set_block_number(
System::block_number() + <Test as Config>::BulletPeriod::get() + 1,
);

// Bob abandoned, alice claims victory
assert_ok!(Chess::clear_abandoned_match(
RuntimeOrigin::signed(alice),
match_id
));

assert_eq!(Chess::chess_matches(match_id), None);

// check the elo after match is complete
assert_eq!(Chess::player_elo(alice), 2029);
assert_eq!(Chess::player_elo(bob), 2371);
});
}

const BOARD_STATE: &str = "Q7/5Q2/8/8/3k4/6P1/6BP/7K b - - 0 67";

#[test]
Expand Down