Skip to content

Commit

Permalink
starter
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYJLiu authored and jamesrp13 committed Dec 15, 2022
1 parent a115a23 commit f7c01dd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
19 changes: 0 additions & 19 deletions programs/duplicate-mutable-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ pub mod duplicate_mutable_accounts {
ctx.accounts.player_two.games_played.checked_add(1).unwrap();
Ok(())
}

pub fn secure_start_game(ctx: Context<SecureGameStart>) -> Result<()> {
ctx.accounts.player_one.games_played =
ctx.accounts.player_one.games_played.checked_add(1).unwrap();

ctx.accounts.player_two.games_played =
ctx.accounts.player_two.games_played.checked_add(1).unwrap();
Ok(())
}
}

#[derive(Accounts)]
Expand All @@ -52,16 +43,6 @@ pub struct InsecureGameStart<'info> {
pub player_two: Account<'info, PlayerState>,
}

#[derive(Accounts)]
pub struct SecureGameStart<'info> {
#[account(
mut,
constraint = player_one.key() != player_two.key())]
pub player_one: Account<'info, PlayerState>,
#[account(mut)]
pub player_two: Account<'info, PlayerState>,
}

#[account]
pub struct PlayerState {
player: Pubkey,
Expand Down
35 changes: 0 additions & 35 deletions tests/duplicate-mutable-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,4 @@ describe("duplicate-mutable-accounts", () => {
.signers([playerTwo])
.rpc()
})

it("Invoke insecure instruction", async () => {
await program.methods
.insecureStartGame()
.accounts({
playerOne: playerOne.publicKey,
playerTwo: playerOne.publicKey,
})
.rpc()
})

it("Invoke secure instruction, expect error", async () => {
try {
await program.methods
.secureStartGame()
.accounts({
playerOne: playerOne.publicKey,
playerTwo: playerOne.publicKey,
})
.rpc()
} catch (err) {
expect(err)
console.log(err)
}
})

it("Invoke secure instruction", async () => {
await program.methods
.secureStartGame()
.accounts({
playerOne: playerOne.publicKey,
playerTwo: playerTwo.publicKey,
})
.rpc()
})
})

0 comments on commit f7c01dd

Please sign in to comment.