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

Feat: Added update current turn after proc raise is called #14

Merged
merged 25 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7f1a841
feat: add update current turn in proc raise
Created-for-a-purpose May 19, 2024
c0d043f
fix: update proc raise unit test
Created-for-a-purpose May 19, 2024
18d35ef
fix: merge main into rg/add-raise-contract
Created-for-a-purpose May 19, 2024
e19bc91
add update current turn in proc call
Created-for-a-purpose May 19, 2024
975a234
add update phase logic in proc call
Created-for-a-purpose May 19, 2024
e8f8416
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
2f69d71
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
42e933c
feat: add update current turn and phase logic in proc fold
Created-for-a-purpose May 19, 2024
658d7ae
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
63358e1
fix: update fold offset in proc fold test
Created-for-a-purpose May 19, 2024
44ea50f
feat: add update current turn and phase logic in proc check
Created-for-a-purpose May 19, 2024
910b0d1
fix: update proc check unit test
Created-for-a-purpose May 19, 2024
54cf153
feat: add proc bet contract
Created-for-a-purpose May 19, 2024
ee97a0b
feat: add proc bet
Created-for-a-purpose May 19, 2024
81ebb9b
feat: add e2e test
Created-for-a-purpose May 19, 2024
c6a10c2
fix: remove redundant code
Created-for-a-purpose May 19, 2024
302d845
feat: add test for proc bet
Created-for-a-purpose May 20, 2024
f3b8a7b
e2e test reorganization
Created-for-a-purpose May 20, 2024
640ae11
add e2e test path in cargo.toml
Created-for-a-purpose May 20, 2024
71b39d4
Merge branch 'feat/add-bet-contract' into feat/add-e2e-test
Created-for-a-purpose May 21, 2024
d93a962
Merge pull request #19 from RizeLabs/feat/add-e2e-test
nlok5923 May 21, 2024
5b41cae
Merge pull request #18 from RizeLabs/feat/add-bet-contract
nlok5923 May 21, 2024
7c77a9f
Merge pull request #17 from RizeLabs/rg/active-player
nlok5923 May 21, 2024
e70dd26
Merge pull request #16 from RizeLabs/rg/add-play-check
nlok5923 May 21, 2024
088a797
Merge pull request #15 from RizeLabs/rg/add-call-contract
nlok5923 May 21, 2024
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
Prev Previous commit
Next Next commit
e2e test reorganization
Created-for-a-purpose committed May 20, 2024
commit f3b8a7b3c74a966fe23401758a0d642336ddc315
5 changes: 4 additions & 1 deletion lib/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ pub const PLAYER_INITIAL_BALANCE: u8 = 30;
pub const HIGHEST_BET: u8 = SMALL_BLIND_AMOUNT;
pub const NO_OF_PLAYERS: u8 = 4;
pub const FLOP_INDEX: u8 = NO_OF_PLAYERS * 2 + 1;
pub const PLAYER_BET_OFFSET: u8 = 3;
pub const IS_FOLD_OFFSET: u8 = 10;
pub const PLAYER_STATS_SLOTS: u8 = 13;
pub const FIRST_PLAYER_INDEX: u8 = 64;
@@ -24,4 +25,6 @@ pub const CURRENT_TURN_INDEX_SLOT: u8 = 60;
pub const HIGHEST_BET_SLOT: u8 = 61;
pub const CURRENT_PHASE_SLOT: u8 = 62;
pub const CHECK_COUNTER_SLOT: u8 = 63;
pub const PLAYER_BALANCE_SLOT: u8 = 68;
pub const PLAYER_BALANCE_SLOT: u8 = 68;
pub const PLAYER_CARD1_SLOT: u8 = 100;
pub const PLAYER_CARD2_SLOT: u8 = 101;
196 changes: 196 additions & 0 deletions node/tests/e2e/test_basic_e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
mod utils;
use aze_lib::client::{
AzeClient,
AzeGameMethods,
AzeAccountTemplate,
};
use aze_lib::constants::{
SMALL_BLIND_AMOUNT,
HIGHEST_BET,
PLAYER_INITIAL_BALANCE,
CURRENT_PHASE_SLOT
};
use miden_client::{
client::{
accounts::{ AccountTemplate, AccountStorageMode },
},
errors::ClientError,
};
use miden_crypto::hash::rpo::RpoDigest;
use miden_crypto::FieldElement;
use miden_objects::{
Felt,
accounts::Account,
};

#[tokio::test]
async fn test_e2e() {
let mut client: AzeClient = utils::create_test_client();

let (game_account, player1_account_id, faucet_account_id, game_slot_data) = utils::setup_accounts(
&mut client
);

let game_account_id = game_account.id();

let (player2_account, _) = client
.new_game_account(
AzeAccountTemplate::PlayerAccount {
mutable_code: false,
storage_mode: AccountStorageMode::Local,
},
None
)
.unwrap();

let (player3_account, _) = client
.new_game_account(
AzeAccountTemplate::PlayerAccount {
mutable_code: false,
storage_mode: AccountStorageMode::Local,
},
None
)
.unwrap();

let (player4_account, _) = client
.new_game_account(
AzeAccountTemplate::PlayerAccount {
mutable_code: false,
storage_mode: AccountStorageMode::Local,
},
None
)
.unwrap();

// Preflop

// Player 1 --> Small blind bets SMALL_BLIND_AMOUNT
let player1_bet = SMALL_BLIND_AMOUNT;
utils::bet(&mut client, player1_account_id, game_account_id, faucet_account_id, player1_bet, 1 as u8).await;
//check player balance
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(68 as u8),
RpoDigest::new([Felt::from((PLAYER_INITIAL_BALANCE - player1_bet) as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Small blind betted");

// Player 2 --> Big blind bets SMALL_BLIND_AMOUNT * 2
let player2_bet = SMALL_BLIND_AMOUNT * 2;
utils::bet(&mut client, player2_account.id(), game_account_id, faucet_account_id, player2_bet, 2 as u8).await;
// check balance
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(81 as u8),
RpoDigest::new([Felt::from((PLAYER_INITIAL_BALANCE - player2_bet) as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Big blind betted");

// Deal cards to players and assert the account status
utils::deal_card(&mut client, game_account_id, player1_account_id, faucet_account_id, 0).await;
utils::deal_card(&mut client, game_account_id, player2_account.id(), faucet_account_id, 2).await;
utils::deal_card(&mut client, game_account_id, player3_account.id(), faucet_account_id, 4).await;
utils::deal_card(&mut client, game_account_id, player4_account.id(), faucet_account_id, 6).await;
println!("----->>> Cards distributed");

// Player 3 --> Call
utils::call(&mut client, player3_account.id(), game_account_id, faucet_account_id, 3).await;
// check balance
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(94 as u8),
RpoDigest::new([Felt::from(20 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Player 3 called");

// Player 4 --> Fold
utils::fold(&mut client, player4_account.id(), game_account_id, faucet_account_id, 4).await;
println!("----->>> Player 4 folded");

// Player 1 --> Call
utils::call(&mut client, player1_account_id, game_account_id, faucet_account_id, 1).await;
// check balance
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(68 as u8),
RpoDigest::new([Felt::from(20 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Player 1 called");

// Player 2 --> Check
println!("----->>> Big blind checking...");
utils::check(&mut client, player2_account.id(), game_account_id, faucet_account_id, 2).await;
// assert check counter
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(CURRENT_PHASE_SLOT),
RpoDigest::new([Felt::from(1 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Player 2 checked");
println!("----->>> Flop revealed");

// Player 1 --> Check
utils::check(&mut client, player1_account_id, game_account_id, faucet_account_id, 1).await;
println!("----->>> Player 1 checked");
// Player 2 --> Check
utils::check(&mut client, player2_account.id(), game_account_id, faucet_account_id, 2).await;
println!("----->>> Player 2 checked");
// Player 3 --> Check
utils::check(&mut client, player3_account.id(), game_account_id, faucet_account_id, 3).await;
println!("----->>> Player 3 checked");
println!("----->>> Turn revealed");

// check phase
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(CURRENT_PHASE_SLOT),
RpoDigest::new([Felt::from(2 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);

// Player 1 --> Check
utils::check(&mut client, player1_account_id, game_account_id, faucet_account_id, 1).await;
println!("----->>> Player 1 checked");
// Player 2 --> Raise
utils::raise(&mut client, player2_account.id(), game_account_id, faucet_account_id, 3 * SMALL_BLIND_AMOUNT, 2).await;
// check balance
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(81 as u8),
RpoDigest::new([Felt::from(5 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);
println!("----->>> Player 2 raised");
// Player 3 --> Call
utils::call(&mut client, player3_account.id(), game_account_id, faucet_account_id, 3).await;
println!("----->>> Player 3 called");
// Player 1 --> Call
utils::call(&mut client, player1_account_id, game_account_id, faucet_account_id, 1).await;
println!("----->>> Player 1 called");
println!("----->>> River revealed");

// check phase
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(CURRENT_PHASE_SLOT),
RpoDigest::new([Felt::from(3 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);

// Player 1 --> Check
utils::check(&mut client, player1_account_id, game_account_id, faucet_account_id, 1).await;
println!("----->>> Player 1 checked");
// Player 2 --> Check
utils::check(&mut client, player2_account.id(), game_account_id, faucet_account_id, 2).await;
println!("----->>> Player 2 checked");
// Player 3 --> Check
utils::check(&mut client, player3_account.id(), game_account_id, faucet_account_id, 3).await;
println!("----->>> Player 3 checked");

// check phase
let game_account = client.get_account(game_account_id).unwrap().0;
assert_eq!(
game_account.storage().get_item(CURRENT_PHASE_SLOT),
RpoDigest::new([Felt::from(4 as u8), Felt::ZERO, Felt::ZERO, Felt::ZERO])
);

println!("----->>> Showdown");
}
Loading