From 2ca314e65d737a1995c5c2c114e7fe126eddccc3 Mon Sep 17 00:00:00 2001 From: Jun Jiang Date: Sat, 29 Jun 2024 22:44:08 +0800 Subject: [PATCH 1/3] attempt to fix GHA --- examples/template/Cargo.toml | 30 ----- examples/template/README.md | 3 - examples/template/keypair.json | 1 - examples/template/src/instruction.rs | 51 ------- examples/template/src/lib.rs | 12 -- examples/template/src/pda.rs | 14 -- examples/template/src/processor.rs | 133 ------------------ examples/template/tests/functional.rs | 186 -------------------------- 8 files changed, 430 deletions(-) delete mode 100644 examples/template/Cargo.toml delete mode 100644 examples/template/README.md delete mode 100644 examples/template/keypair.json delete mode 100644 examples/template/src/instruction.rs delete mode 100644 examples/template/src/lib.rs delete mode 100644 examples/template/src/pda.rs delete mode 100644 examples/template/src/processor.rs delete mode 100644 examples/template/tests/functional.rs diff --git a/examples/template/Cargo.toml b/examples/template/Cargo.toml deleted file mode 100644 index 3730eff..0000000 --- a/examples/template/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "dephy-io-dephy-template" -version = "0.0.0" -edition = "2021" -readme = "./README.md" -license-file = "../LICENSE" -publish = false - -[package.metadata.solana] -program-id = "D6QAaYRpbRXhWicCbF6knEGmoLXiAvG8MsT77ZtKNo3K" -program-dependencies = [] - -[lib] -crate-type = ["cdylib", "lib"] - -[dependencies] -borsh = { workspace = true } -shank = { workspace = true } -num-derive = { workspace = true } -num-traits = { workspace = true } -thiserror = { workspace = true } -solana-program = { workspace = true } -spl-token-2022 = { workspace = true, features = ["no-entrypoint"] } -spl-token-metadata-interface = { workspace = true } -spl-associated-token-account = { workspace = true, features = ["no-entrypoint"] } -dephy-id-program-client = { path = "../../clients/rust" } - -[dev-dependencies] -solana-program-test = { workspace = true } -solana-sdk = { workspace = true } diff --git a/examples/template/README.md b/examples/template/README.md deleted file mode 100644 index 9045295..0000000 --- a/examples/template/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Dephy Template - -Your generated Solana program. Have fun! diff --git a/examples/template/keypair.json b/examples/template/keypair.json deleted file mode 100644 index d663c96..0000000 --- a/examples/template/keypair.json +++ /dev/null @@ -1 +0,0 @@ -[194,46,164,46,245,195,70,105,156,56,76,46,236,66,242,239,166,18,60,185,232,90,234,94,57,177,47,188,163,163,189,155,179,174,87,14,254,246,237,240,86,224,232,98,110,160,129,35,42,1,237,65,216,224,85,142,122,195,204,96,225,107,101,70] \ No newline at end of file diff --git a/examples/template/src/instruction.rs b/examples/template/src/instruction.rs deleted file mode 100644 index bf3c29f..0000000 --- a/examples/template/src/instruction.rs +++ /dev/null @@ -1,51 +0,0 @@ -use borsh::{BorshDeserialize, BorshSerialize}; -use shank::{ShankContext, ShankInstruction}; - -#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, ShankContext, ShankInstruction)] -#[rustfmt::skip] -pub enum DemoInstruction { - /// Creates the demo account derived from the provided authority. - /// This will also create a DePHY ID Product with a PDA as vendor - #[account(0, writable, name="demo", desc = "The program derived address of the demo account to create (seeds: ['DEMO'])")] - #[account(1, signer, name="authority", desc = "The authority of the demo")] - #[account(2, writable, signer, name="payer", desc = "The account paying for the storage fees")] - #[account(3, name="system_program", desc = "The system program")] - #[account(4, name="token_2022_program", desc="The SPL Token 2022 program")] - #[account(5, name="dephy_id", desc = "DePHY ID program id")] - #[account(6, name="vendor", desc="PDA as product vendor (seeds: ['VENDOR'])")] - #[account(7, writable, name="product_mint", desc="PDA of the product mint account (program: dephy_id, seeds: ['DePHY_ID-PRODUCT', vendor, PRODUCT_NAME])")] - Init(InitArgs), - - /// Create a Virtual Device - #[account(0, writable, name="demo", desc = "The program derived address of the demo account to increment (seeds: ['DEMO'])")] - #[account(1, writable, signer, name="payer", desc = "The account paying for the storage fees")] - #[account(2, name="system_program", desc = "The system program")] - #[account(3, name="token_2022_program", desc = "The SPL Token 2022 program")] - #[account(4, name="ata_program", desc = "The associated token program")] - #[account(5, name="dephy_id", desc = "DePHY ID program id")] - #[account(6, name="vendor", desc = "PDA as product vendor (seeds: ['VENDOR'])")] - #[account(7, name="product_mint", desc = "PDA of the product mint account (program: dephy_id, seeds: ['DePHY_ID-PRODUCT', vendor, PRODUCT_NAME])")] - #[account(8, name="owner", desc="The device's owner")] - #[account(9, name="device", desc = "PDA of the virtual device (seeds: ['DEVICE', owner])")] - #[account(10, writable, name="product_atoken", desc="The associated token account of the product")] - #[account(11, writable, name="device_mint", desc="The mint account of the device")] - #[account(12, writable, name="device_atoken", desc="The associated token account for the device")] - CreateVirtualDevice(CreateVirtualDeviceArgs), -} - - -#[repr(C)] -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] -pub struct InitArgs { - pub name: String, - pub symbol: String, - pub uri: String, - pub additional_metadata: Vec<(String, String)>, -} - -#[repr(C)] -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] -pub struct CreateVirtualDeviceArgs { - pub challenge: u8, -} - diff --git a/examples/template/src/lib.rs b/examples/template/src/lib.rs deleted file mode 100644 index c7294ac..0000000 --- a/examples/template/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub mod assertions; -pub mod entrypoint; -pub mod error; -pub mod instruction; -pub mod processor; -pub mod state; -pub mod utils; -pub mod pda; - -pub use solana_program; - -solana_program::declare_id!("D6QAaYRpbRXhWicCbF6knEGmoLXiAvG8MsT77ZtKNo3K"); diff --git a/examples/template/src/pda.rs b/examples/template/src/pda.rs deleted file mode 100644 index ee62c31..0000000 --- a/examples/template/src/pda.rs +++ /dev/null @@ -1,14 +0,0 @@ -use solana_program::pubkey::Pubkey; - -pub fn find_device( - owner: &Pubkey, - program_id: &Pubkey, -) -> (Pubkey, u8) { - Pubkey::find_program_address( - &[ - b"DEVICE", - owner.as_ref(), - ], - program_id, - ) -} diff --git a/examples/template/src/processor.rs b/examples/template/src/processor.rs deleted file mode 100644 index 14527c5..0000000 --- a/examples/template/src/processor.rs +++ /dev/null @@ -1,133 +0,0 @@ -use borsh::BorshDeserialize; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey, system_program, -}; -use spl_token_2022::extension::{BaseStateWithExtensions, StateWithExtensions}; -use spl_token_2022::state::Mint; -use spl_token_metadata_interface::state::TokenMetadata; - -use crate::assertions::{ - assert_pda, assert_same_pubkeys, assert_signer, assert_writable, -}; -use crate::instruction::accounts::{CreateVirtualDeviceAccounts, InitAccounts}; -use crate::instruction::{CreateVirtualDeviceArgs, DemoInstruction, InitArgs}; -use crate::state::{DemoAccount, Key}; -use crate::utils::create_account; - -use dephy_id_program_client::instructions::{ - CreateActivatedDeviceCpiBuilder, CreateProductCpiBuilder, -}; - -pub fn process_instruction<'a>( - program_id: &Pubkey, - accounts: &'a [AccountInfo<'a>], - instruction_data: &[u8], -) -> ProgramResult { - let instruction: DemoInstruction = DemoInstruction::try_from_slice(instruction_data)?; - match instruction { - DemoInstruction::Init(args) => { - msg!("Instruction: Init"); - init(program_id, accounts, args) - } - DemoInstruction::CreateVirtualDevice(args) => { - msg!("Instruction: CreateVirtualDevice"); - create_virtual_device(program_id, accounts, args) - } - } -} - -fn init<'a>(program_id: &Pubkey, accounts: &'a [AccountInfo<'a>], args: InitArgs) -> ProgramResult { - // Accounts. - let ctx = InitAccounts::context(accounts)?; - - // Guards. - let mut demo_seeds = DemoAccount::seeds(); - let demo_bump = [assert_pda("counter", ctx.accounts.demo, &crate::ID, &demo_seeds)?]; - demo_seeds.push(&demo_bump); - assert_signer("authority", ctx.accounts.authority)?; - assert_signer("payer", ctx.accounts.payer)?; - assert_writable("payer", ctx.accounts.payer)?; - assert_same_pubkeys( - "system_program", - ctx.accounts.system_program, - &system_program::id(), - )?; - - // Create Counter PDA. - let account = DemoAccount { - key: Key::DemoAccount, - authority: *ctx.accounts.authority.key, - product_mint: *ctx.accounts.product_mint.key, - }; - create_account( - ctx.accounts.demo, - ctx.accounts.payer, - ctx.accounts.system_program, - DemoAccount::LEN, - &crate::ID, - Some(&[&demo_seeds]), - )?; - - account.save(ctx.accounts.demo)?; - - let mut vendor_seeds: Vec<&[u8]> = vec![b"VENDOR"]; - let vendor_bump = [assert_pda( - "vendor", - ctx.accounts.vendor, - program_id, - &vendor_seeds, - )?]; - vendor_seeds.push(&vendor_bump); - - let mut create_product = CreateProductCpiBuilder::new(ctx.accounts.dephy_id); - create_product - .system_program(ctx.accounts.system_program) - .token2022_program(ctx.accounts.token_2022_program) - .payer(ctx.accounts.payer) - .vendor(ctx.accounts.vendor) - .product_mint(ctx.accounts.product_mint) - .name(args.name) - .symbol(args.symbol) - .uri(args.uri) - .additional_metadata(args.additional_metadata) - .invoke_signed(&[&vendor_seeds])?; - - Ok(()) -} - -fn create_virtual_device<'a>( - program_id: &Pubkey, - accounts: &'a [AccountInfo<'a>], - args: CreateVirtualDeviceArgs, -) -> ProgramResult { - // Accounts. - let ctx = CreateVirtualDeviceAccounts::context(accounts)?; - let owner_pubkey = ctx.accounts.owner.key; - - let product_mint_data = ctx.accounts.product_mint.data.borrow(); - let product_mint = StateWithExtensions::::unpack(&product_mint_data)?; - let product_mint_metadata = product_mint.get_variable_len_extension::()?; - - assert_pda("device", ctx.accounts.device, program_id, &[b"DEVICE", owner_pubkey.as_ref()])?; - - // TODO: use your own verify method - assert_eq!(args.challenge, 42); - - let mut create_activated_device = CreateActivatedDeviceCpiBuilder::new(ctx.accounts.dephy_id); - create_activated_device - .system_program(ctx.accounts.system_program) - .token2022_program(ctx.accounts.token_2022_program) - .ata_program(ctx.accounts.ata_program) - .payer(ctx.accounts.payer) - .vendor(ctx.accounts.vendor) - .product_mint(ctx.accounts.product_mint) - .product_associated_token(ctx.accounts.product_atoken) - .device(ctx.accounts.device) - .device_mint(ctx.accounts.device_mint) - .device_associated_token(ctx.accounts.device_atoken) - .name(product_mint_metadata.name) - .uri(product_mint_metadata.uri) - .additional_metadata(product_mint_metadata.additional_metadata); - - Ok(()) -} diff --git a/examples/template/tests/functional.rs b/examples/template/tests/functional.rs deleted file mode 100644 index 0fce7c2..0000000 --- a/examples/template/tests/functional.rs +++ /dev/null @@ -1,186 +0,0 @@ -use dephy_id_program_client::find_device_mint; -use dephy_io_dephy_template::{ - instruction::{CreateVirtualDeviceArgs, DemoInstruction, InitArgs}, - pda::find_device, - state::DemoAccount, -}; -use solana_program::pubkey::Pubkey; -use solana_program_test::{tokio, ProgramTest, ProgramTestContext}; -use solana_sdk::{ - instruction::{AccountMeta, Instruction as SolanaInstruction}, - signature::Keypair, - signer::Signer, - system_program, - transaction::Transaction, -}; - -#[tokio::test] -async fn test_all() { - let program_id = dephy_io_dephy_template::id(); - - let mut program_test = ProgramTest::new("dephy_io_dephy_template", program_id, None); - program_test.add_program("dephy_id_program", dephy_id_program_client::ID, None); - - let mut ctx = program_test.start_with_context().await; - - let authority = Keypair::new(); - - // Initialize the program - let (demo_account_pubkey, _) = DemoAccount::find_pda(); - let (vendor_pubkey, _) = Pubkey::find_program_address(&[b"VENDOR"], &program_id); - - let product_name = "Demo".to_string(); - let (product_mint_pubkey, _) = Pubkey::find_program_address( - &[ - dephy_id_program_client::PRODUCT_MINT_SEED_PREFIX, - vendor_pubkey.as_ref(), - product_name.as_ref(), - ], - &dephy_id_program_client::ID, - ); - - test_init( - &mut ctx, - program_id, - demo_account_pubkey, - authority, - vendor_pubkey, - product_mint_pubkey, - product_name, - ) - .await; - - let owner = Keypair::new(); - - test_create_virtual_device( - &mut ctx, - program_id, - demo_account_pubkey, - vendor_pubkey, - product_mint_pubkey, - owner, - ) - .await; -} - -async fn test_init( - ctx: &mut ProgramTestContext, - program_id: Pubkey, - demo_account_pubkey: Pubkey, - authority: Keypair, - vendor_pubkey: Pubkey, - product_mint_pubkey: Pubkey, - product_name: String, -) { - let mut transaction = Transaction::new_with_payer( - &[SolanaInstruction::new_with_borsh( - program_id, - &DemoInstruction::Init(InitArgs { - name: product_name, - symbol: "DEMO".to_string(), - uri: "https://example.com".to_string(), - additional_metadata: vec![], - }), - vec![ - // #[account(0, writable, name="demo", desc = "The program derived address of the demo account to create (seeds: ['DEMO'])")] - AccountMeta::new(demo_account_pubkey, false), - // #[account(1, signer, name="authority", desc = "The authority of the demo")] - AccountMeta::new(authority.pubkey(), true), - // #[account(2, writable, signer, name="payer", desc = "The account paying for the storage fees")] - AccountMeta::new(ctx.payer.pubkey(), true), - // #[account(3, name="system_program", desc = "The system program")] - AccountMeta::new(system_program::id(), false), - // #[account(4, name="token_2022_program", desc="The SPL Token 2022 program")] - AccountMeta::new(spl_token_2022::id(), false), - // #[account(5, name="dephy_id", desc = "DePHY ID program id")] - AccountMeta::new(dephy_id_program_client::ID, false), - // #[account(6, name="vendor", desc="PDA as product vendor (seeds: ['VENDOR'])")] - AccountMeta::new(vendor_pubkey, false), - // #[account(7, writable, name="product_mint", desc="PDA of the product mint account (program: dephy_id, seeds: ['DePHY_ID-PRODUCT', vendor, PRODUCT_NAME])")] - AccountMeta::new(product_mint_pubkey, false), - ], - )], - Some(&ctx.payer.pubkey()), - ); - transaction.sign(&[&ctx.payer, &authority], ctx.last_blockhash); - ctx.banks_client - .process_transaction(transaction) - .await - .unwrap(); - - // Associated account now exists - let demo_account = ctx - .banks_client - .get_account(demo_account_pubkey) - .await - .expect("get_account") - .expect("Account not none"); - assert_eq!(demo_account.data.len(), DemoAccount::LEN); -} - -async fn test_create_virtual_device( - ctx: &mut ProgramTestContext, - program_id: Pubkey, - demo_account_pubkey: Pubkey, - vendor_pubkey: Pubkey, - product_mint_pubkey: Pubkey, - owner: Keypair, -) { - let (device_pubkey, _) = find_device(&owner.pubkey(), &program_id); - - let product_atoken_pubkey = - spl_associated_token_account::get_associated_token_address_with_program_id( - &device_pubkey, - &product_mint_pubkey, - &spl_token_2022::id(), - ); - let (device_mint_pubkey, _) = - find_device_mint(&product_mint_pubkey, &device_pubkey, &program_id); - let device_atoken_pubkey = - spl_associated_token_account::get_associated_token_address_with_program_id( - &device_pubkey, - &device_mint_pubkey, - &spl_token_2022::id(), - ); - - let mut transaction = Transaction::new_with_payer( - &[SolanaInstruction::new_with_borsh( - program_id, - &DemoInstruction::CreateVirtualDevice(CreateVirtualDeviceArgs { challenge: 42 }), - vec![ - // #[account(0, writable, name="demo", desc = "The program derived address of the demo account to increment (seeds: ['DEMO'])")] - AccountMeta::new(demo_account_pubkey, false), - // #[account(1, writable, signer, name="payer", desc = "The account paying for the storage fees")] - AccountMeta::new(ctx.payer.pubkey(), true), - // #[account(2, name="system_program", desc = "The system program")] - AccountMeta::new(system_program::id(), false), - // #[account(3, name="token_2022_program", desc = "The SPL Token 2022 program")] - AccountMeta::new(spl_token_2022::id(), false), - // #[account(4, name="ata_program", desc = "The associated token program")] - AccountMeta::new(spl_associated_token_account::id(), false), - // #[account(5, name="dephy_id", desc = "DePHY ID program id")] - AccountMeta::new(dephy_id_program_client::ID, false), - // #[account(6, name="vendor", desc = "PDA as product vendor (seeds: ['VENDOR'])")] - AccountMeta::new(vendor_pubkey, false), - // #[account(7, name="product_mint", desc = "PDA of the product mint account (program: dephy_id, seeds: ['DePHY_ID-PRODUCT', vendor, PRODUCT_NAME])")] - AccountMeta::new(product_mint_pubkey, false), - // #[account(8, name="owner", desc="The device's owner")] - AccountMeta::new(owner.pubkey(), false), - // #[account(9, name="device", desc = "PDA of the virtual device (seeds: ['DEVICE', owner])")] - AccountMeta::new(device_pubkey, false), - // #[account(10, writable, name="product_atoken", desc="The associated token account of the product")] - AccountMeta::new(product_atoken_pubkey, false), - // #[account(11, writable, name="device_mint", desc="The mint account of the device")] - AccountMeta::new(device_mint_pubkey, false), - // #[account(12, writable, name="device_atoken", desc="The associated token account for the device")] - AccountMeta::new(device_atoken_pubkey, false), - ], - )], - Some(&ctx.payer.pubkey()), - ); - transaction.sign(&[&ctx.payer], ctx.last_blockhash); - ctx.banks_client - .process_transaction(transaction) - .await - .unwrap(); -} From 0925894db8fc952ba072d38d8a4a0aee4d90284f Mon Sep 17 00:00:00 2001 From: Jun Jiang Date: Sun, 30 Jun 2024 02:23:09 +0800 Subject: [PATCH 2/3] attempt to fix GHA --- .github/actions/setup/action.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 99b4095..aeebe67 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,33 +1,25 @@ name: Setup environment -inputs: - cache: - description: Enable caching - default: "true" - node: - description: The Node.js version to install - required: true - solana: - description: The Solana version to install - runs: using: "composite" steps: - - name: Setup pnpm - uses: pnpm/action-setup@v3 + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9.4.0 + run_install: false - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: ${{ inputs.node }} + node-version: 20 cache: "pnpm" - name: Install dependencies run: pnpm install --frozen-lockfile shell: bash - name: Install Solana - if: ${{ inputs.solana != '' }} uses: metaplex-foundation/actions/install-solana@v1 with: - version: ${{ inputs.solana }} - cache: ${{ inputs.cache }} + version: 1.18.15 + cache: "true" - name: Install Protoc uses: arduino/setup-protoc@v3 From 8a6cc7d3daa07b24ad1b059b8d1cdf12301e6c5c Mon Sep 17 00:00:00 2001 From: Jun Jiang Date: Sun, 30 Jun 2024 02:44:49 +0800 Subject: [PATCH 3/3] attempt to fix GHA --- .github/actions/setup/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index aeebe67..3baea5d 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -7,14 +7,13 @@ runs: uses: pnpm/action-setup@v4 with: version: 9.4.0 - run_install: false - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 cache: "pnpm" - name: Install dependencies - run: pnpm install --frozen-lockfile + run: pnpm install shell: bash - name: Install Solana uses: metaplex-foundation/actions/install-solana@v1