initial commit
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
.anchor
|
||||
.DS_Store
|
||||
target
|
||||
**/*.rs.bk
|
||||
node_modules
|
||||
test-ledger
|
||||
.yarn
|
||||
.surfpool
|
||||
spec.md
|
||||
9922
.pnp.cjs
generated
Executable file
9922
.pnp.cjs
generated
Executable file
File diff suppressed because one or more lines are too long
2126
.pnp.loader.mjs
generated
Normal file
2126
.pnp.loader.mjs
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
.prettierignore
Normal file
7
.prettierignore
Normal file
@@ -0,0 +1,7 @@
|
||||
.anchor
|
||||
.DS_Store
|
||||
target
|
||||
node_modules
|
||||
dist
|
||||
build
|
||||
test-ledger
|
||||
18
Anchor.toml
Normal file
18
Anchor.toml
Normal file
@@ -0,0 +1,18 @@
|
||||
[toolchain]
|
||||
package_manager = "yarn"
|
||||
|
||||
[features]
|
||||
resolution = true
|
||||
skip-lint = false
|
||||
|
||||
[programs.localnet]
|
||||
descro = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3"
|
||||
|
||||
[provider]
|
||||
cluster = "localnet"
|
||||
wallet = "~/.config/solana/id.json"
|
||||
|
||||
[scripts]
|
||||
test = "cargo test"
|
||||
|
||||
[hooks]
|
||||
4126
Cargo.lock
generated
Normal file
4126
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"programs/*"
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[profile.release]
|
||||
overflow-checks = true
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
[profile.release.build-override]
|
||||
opt-level = 3
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
12
migrations/deploy.ts
Normal file
12
migrations/deploy.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// Migrations are an early feature. Currently, they're nothing more than this
|
||||
// single deploy script that's invoked from the CLI, injecting a provider
|
||||
// configured from the workspace's Anchor.toml.
|
||||
|
||||
import * as anchor from "@anchor-lang/core";
|
||||
|
||||
module.exports = async function (provider: anchor.AnchorProvider) {
|
||||
// Configure client to use the provider.
|
||||
anchor.setProvider(provider);
|
||||
|
||||
// Add your deploy script here.
|
||||
};
|
||||
20
package.json
Normal file
20
package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
|
||||
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anchor-lang/core": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"chai": "^4.3.4",
|
||||
"mocha": "^9.0.3",
|
||||
"prettier": "^2.6.2",
|
||||
"ts-mocha": "^10.0.0",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
4
rust-toolchain.toml
Normal file
4
rust-toolchain.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "1.89.0"
|
||||
components = ["rustfmt","clippy"]
|
||||
profile = "minimal"
|
||||
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"types": ["mocha", "chai"],
|
||||
"typeRoots": ["./node_modules/@types"],
|
||||
"lib": ["es2015"],
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user