Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ jobs:
path: tests/idl
- cmd: cd tests/lazy-account && anchor test
path: tests/lazy-account
- cmd: cd tests/post2018-template && anchor test --skip-lint
path: tests/post2018-template
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
Expand Down
4 changes: 2 additions & 2 deletions cli/src/rust_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub enum ErrorCode {
.into(),
),
(
src_path.join("instructions").join("mod.rs"),
src_path.join("instructions.rs"),
r#"pub mod initialize;

pub use initialize::*;
Expand All @@ -170,7 +170,7 @@ pub fn handler(ctx: Context<Initialize>) -> Result<()> {
"#
.into(),
),
(src_path.join("state").join("mod.rs"), r#""#.into()),
(src_path.join("state.rs"), r#""#.into()),
]
}

Expand Down
6 changes: 6 additions & 0 deletions tests/post2018-template/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[programs.localnet]
template_multiple_files = "CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
15 changes: 15 additions & 0 deletions tests/post2018-template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[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

21 changes: 21 additions & 0 deletions tests/post2018-template/programs/template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "template"
version = "0.1.0"
description = "Test for multiple file template structure"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "template_multiple_files"

[features]
default = []
cpi = ["no-entrypoint"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = { path = "../../../../lang" }

3 changes: 3 additions & 0 deletions tests/post2018-template/programs/template/src/instructions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod initialize;

pub use initialize::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anchor_lang::prelude::*;
use crate::state::*;

#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
init,
payer = user,
space = 8 + MyAccount::INIT_SPACE
)]
pub account: Account<'info, MyAccount>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<Initialize>) -> Result<()> {
let account = &mut ctx.accounts.account;
account.data = 0;
msg!("Account initialized with data: {}", account.data);
Ok(())
}

18 changes: 18 additions & 0 deletions tests/post2018-template/programs/template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub mod instructions;
pub mod state;

use anchor_lang::prelude::*;

pub use instructions::*;
pub use state::*;

declare_id!("CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr");

#[program]
pub mod template_multiple_files {
use super::*;

pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
initialize::handler(ctx)
}
}
3 changes: 3 additions & 0 deletions tests/post2018-template/programs/template/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod state;

pub use state::*;
8 changes: 8 additions & 0 deletions tests/post2018-template/programs/template/src/state/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use anchor_lang::prelude::*;

#[account]
#[derive(InitSpace)]
pub struct MyAccount {
pub data: u64,
}