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

Update anchor-lang to the latest version (solution branch) #4

Open
wants to merge 3 commits into
base: solution
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolution = true
skip-lint = false

[programs.localnet]
duplicate_mutable_accounts = "Lo5sj2wWy4BHbe8kCSUvgdhzFbv9c6CEERfgAXusBj9"
duplicate_mutable_accounts = "CSp7FzR2rCzq4AHQcU57wJ4gxmFp8Q7CFHNziTdmQAZC"

[registry]
url = "https://api.apr.dev"
Expand Down
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[workspace]
members = [
"programs/*"
]
members = ["programs/*"]
resolver = "2"

[profile.release]
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
"@coral-xyz/anchor": "^0.30.1",
"@project-serum/anchor": "^0.25.0"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.1",
"@types/node": "^22.5.1",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.2.2",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
Expand Down
15 changes: 8 additions & 7 deletions programs/duplicate-mutable-accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use anchor_lang::prelude::*;

mod constants;
use constants::DISCRIMINATOR_SIZE;
declare_id!("CSp7FzR2rCzq4AHQcU57wJ4gxmFp8Q7CFHNziTdmQAZC");

declare_id!("Lo5sj2wWy4BHbe8kCSUvgdhzFbv9c6CEERfgAXusBj9");
const DISCRIMINATOR_SIZE: usize = 8;

#[program]
pub mod duplicate_mutable_accounts {
Expand All @@ -21,6 +20,7 @@ pub mod duplicate_mutable_accounts {
player_two_choice: RockPaperScissors,
) -> Result<()> {
ctx.accounts.player_one.choice = Some(player_one_choice);

ctx.accounts.player_two.choice = Some(player_two_choice);
Ok(())
}
Expand All @@ -31,6 +31,7 @@ pub mod duplicate_mutable_accounts {
player_two_choice: RockPaperScissors,
) -> Result<()> {
ctx.accounts.player_one.choice = Some(player_one_choice);

ctx.accounts.player_two.choice = Some(player_two_choice);
Ok(())
}
Expand Down Expand Up @@ -69,13 +70,13 @@ pub struct RockPaperScissorsSecure<'info> {
}

#[account]
#[derive(Default, InitSpace)]
#[derive(InitSpace)]
pub struct PlayerState {
pub player: Pubkey,
pub choice: Option<RockPaperScissors>,
player: Pubkey,
choice: Option<RockPaperScissors>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, InitSpace)]
#[derive(Clone, Copy, AnchorDeserialize, AnchorSerialize, InitSpace)]
pub enum RockPaperScissors {
Rock,
Paper,
Expand Down
14 changes: 7 additions & 7 deletions tests/duplicate-mutable-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Program, Wallet } from "@coral-xyz/anchor";
import { assert, expect } from "chai";
import { DuplicateMutableAccounts } from "../target/types/duplicate_mutable_accounts";

Expand All @@ -14,7 +14,7 @@ describe("duplicate-mutable-accounts", () => {
const playerOne = anchor.web3.Keypair.generate();
const playerTwo = anchor.web3.Keypair.generate();

it("Initialized Player One", async () => {
it("Initialized Player One should be successful", async () => {
await program.methods
.initialize()
.accounts({
Expand All @@ -25,7 +25,7 @@ describe("duplicate-mutable-accounts", () => {
.rpc();
});

it("Initialized Player Two", async () => {
it("Initialized Player Two should be successful", async () => {
await program.methods
.initialize()
.accounts({
Expand All @@ -36,7 +36,7 @@ describe("duplicate-mutable-accounts", () => {
.rpc();
});

it("Invoke insecure instruction", async () => {
it("Invoke insecure instruction with the same player should be successful", async () => {
await program.methods
.rockPaperScissorsShootInsecure({ rock: {} }, { scissors: {} })
.accounts({
Expand All @@ -50,7 +50,7 @@ describe("duplicate-mutable-accounts", () => {
assert.notEqual(JSON.stringify(p1.choice), JSON.stringify({ rock: {} }));
});

it("Invoke secure instruction", async () => {
it("Invoke secure instruction with different players should be successful", async () => {
await program.methods
.rockPaperScissorsShootSecure({ rock: {} }, { scissors: {} })
.accounts({
Expand All @@ -65,7 +65,7 @@ describe("duplicate-mutable-accounts", () => {
assert.equal(JSON.stringify(p2.choice), JSON.stringify({ scissors: {} }));
});

it("Invoke secure instruction - expect error", async () => {
it("Invoke secure instruction with the same player should throw an expection", async () => {
try {
await program.methods
.rockPaperScissorsShootSecure({ rock: {} }, { scissors: {} })
Expand All @@ -79,4 +79,4 @@ describe("duplicate-mutable-accounts", () => {
console.log(err);
}
});
});
});
Loading