Skip to content

Commit

Permalink
fix player count
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaviderb committed Oct 12, 2022
1 parent 4e95db0 commit 5e6813c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion programs/dejavu-football/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub mod dejavu_football {
ctx.accounts.player_metadata.room = ctx.accounts.room.key();
ctx.accounts.player_metadata.token_account = ctx.accounts.player_token_account.key();
ctx.accounts.player_metadata.key = player_bet[2];
ctx.accounts.room.players_count += 1;
ctx.accounts.room.players_count = 2;
ctx.accounts.players.add_bet(player_bet)?;

// transfer
Expand Down Expand Up @@ -367,6 +367,7 @@ pub struct CreateRoomInstruction<'info> {
pub struct JoinRoomInstruction<'info> {
oracle: Account<'info, Oracle>,
mint: Account<'info, Mint>,
#[account(mut)]
room: Account<'info, Room>,
#[account(
init,
Expand Down
21 changes: 13 additions & 8 deletions tests/room_instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ describe("Program Authorizer methods", () => {
//provider
anchor.setProvider(provider);
const program = anchor.workspace.DejavuFootball as Program<DejavuFootball>;

// anchor.web3.Keypair.fromSecretKey()

// new anchor.web3.Keypair('3WHWwZTJbP2V5KWAMgUBzS7PKzdQU1cf7uKvPHRCppNRpwfEqCbpSauS8QtUtVfYnLFLHqBafG48438MzFLwMbYj')

const payer = anchor.web3.Keypair.fromSecretKey(
Buffer.from(
JSON.parse(
Expand Down Expand Up @@ -126,6 +121,12 @@ describe("Program Authorizer methods", () => {
"checks if player mint account was decreased a token by the program"
);

assert.equal(
Number(roomData.playersCount),
1,
"checks if room player count is assigned"
);

assert.equal(
Number(vaultMintAccountBalance.value.amount),
1,
Expand Down Expand Up @@ -241,10 +242,8 @@ describe("Program Authorizer methods", () => {

const { room, roomPlayers, vault } = response.accounts;


// join room


const joinRoomResponse = await joinRoom(program, {
inputs: {
teamAResult: 0,
Expand All @@ -261,7 +260,7 @@ describe("Program Authorizer methods", () => {
vaultAccount: vault
}
});

const roomData = await program.account.room.fetch(room);
const { joinPlayerMetadata } = joinRoomResponse.accounts;


Expand All @@ -281,6 +280,12 @@ describe("Program Authorizer methods", () => {
playerMintTokenAccount
);

assert.equal(
Number(roomData.playersCount),
2,
"checks if room player count is assigned"
);

assert.equal(
Number(vaultMintAccountBalance.value.amount),
2,
Expand Down

0 comments on commit 5e6813c

Please sign in to comment.