initial commit
This commit is contained in:
35
programs/descro/Cargo.toml
Normal file
35
programs/descro/Cargo.toml
Normal file
@@ -0,0 +1,35 @@
|
||||
[package]
|
||||
name = "descro"
|
||||
version = "0.1.0"
|
||||
description = "Created with Anchor"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "descro"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
cpi = ["no-entrypoint"]
|
||||
no-entrypoint = []
|
||||
no-idl = []
|
||||
no-log-ix-name = []
|
||||
idl-build = ["anchor-lang/idl-build"]
|
||||
anchor-debug = []
|
||||
custom-heap = []
|
||||
custom-panic = []
|
||||
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "1.0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
litesvm = "0.10.0"
|
||||
solana-message = "3.0.1"
|
||||
solana-transaction = "3.0.2"
|
||||
solana-signer = "3.0.0"
|
||||
solana-keypair = "3.0.1"
|
||||
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
|
||||
4
programs/descro/src/constants.rs
Normal file
4
programs/descro/src/constants.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
use anchor_lang::prelude::*;
|
||||
|
||||
#[constant]
|
||||
pub const SEED: &str = "anchor";
|
||||
7
programs/descro/src/error.rs
Normal file
7
programs/descro/src/error.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use anchor_lang::prelude::*;
|
||||
|
||||
#[error_code]
|
||||
pub enum ErrorCode {
|
||||
#[msg("Custom error message")]
|
||||
CustomError,
|
||||
}
|
||||
3
programs/descro/src/instructions.rs
Normal file
3
programs/descro/src/instructions.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod initialize;
|
||||
|
||||
pub use initialize::*;
|
||||
9
programs/descro/src/instructions/initialize.rs
Normal file
9
programs/descro/src/instructions/initialize.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use anchor_lang::prelude::*;
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct Initialize {}
|
||||
|
||||
pub fn handler(ctx: Context<Initialize>) -> Result<()> {
|
||||
msg!("Greetings from: {:?}", ctx.program_id);
|
||||
Ok(())
|
||||
}
|
||||
21
programs/descro/src/lib.rs
Normal file
21
programs/descro/src/lib.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
pub mod constants;
|
||||
pub mod error;
|
||||
pub mod instructions;
|
||||
pub mod state;
|
||||
|
||||
use anchor_lang::prelude::*;
|
||||
|
||||
pub use constants::*;
|
||||
pub use instructions::*;
|
||||
pub use state::*;
|
||||
|
||||
declare_id!("DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3");
|
||||
|
||||
#[program]
|
||||
pub mod descro {
|
||||
use super::*;
|
||||
|
||||
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
|
||||
initialize::handler(ctx)
|
||||
}
|
||||
}
|
||||
0
programs/descro/src/state.rs
Normal file
0
programs/descro/src/state.rs
Normal file
32
programs/descro/tests/test_initialize.rs
Normal file
32
programs/descro/tests/test_initialize.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
use {
|
||||
anchor_lang::{solana_program::instruction::Instruction, InstructionData, ToAccountMetas},
|
||||
litesvm::LiteSVM,
|
||||
solana_message::{Message, VersionedMessage},
|
||||
solana_signer::Signer,
|
||||
solana_keypair::Keypair,
|
||||
solana_transaction::versioned::VersionedTransaction,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_initialize() {
|
||||
let program_id = descro::id();
|
||||
let payer = Keypair::new();
|
||||
let mut svm = LiteSVM::new();
|
||||
let bytes = include_bytes!("../../../target/deploy/descro.so");
|
||||
svm.add_program(program_id, bytes).unwrap();
|
||||
svm.airdrop(&payer.pubkey(), 1_000_000_000).unwrap();
|
||||
|
||||
let instruction = Instruction::new_with_bytes(
|
||||
program_id,
|
||||
&descro::instruction::Initialize {}.data(),
|
||||
descro::accounts::Initialize {}.to_account_metas(None),
|
||||
);
|
||||
|
||||
let blockhash = svm.latest_blockhash();
|
||||
let msg = Message::new_with_blockhash(&[instruction], Some(&payer.pubkey()), &blockhash);
|
||||
let tx = VersionedTransaction::try_new(VersionedMessage::Legacy(msg), &[payer]).unwrap();
|
||||
|
||||
let res = svm.send_transaction(tx);
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
Reference in New Issue
Block a user