diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 038c4c3..364a1a1 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -2,8 +2,8 @@ mod rust_template; use crate::rust_template::{create_component, create_system}; use anchor_cli::config::{ - BootstrapMode, Config, ConfigOverride, ProgramArch, ProgramDeployment, TestValidator, - Validator, WithPath, + BootstrapMode, Config, ConfigOverride, GenesisEntry, ProgramArch, ProgramDeployment, + TestValidator, Validator, WithPath, }; use anchor_client::Cluster; use anyhow::{anyhow, Result}; @@ -17,6 +17,8 @@ use std::process::Stdio; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const ANCHOR_VERSION: &str = anchor_cli::VERSION; +pub const WORLD_PROGRAM: &str = "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n"; + #[derive(Debug, Subcommand)] pub enum BoltCommand { #[clap(about = "Create a new component")] @@ -231,18 +233,11 @@ fn init( rpc_port: 8899, bind_address: "0.0.0.0".to_owned(), ledger: ".bolt/test-ledger".to_owned(), - clone: Some(vec![ - // World program - anchor_cli::config::CloneEntry { - address: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n".to_owned(), - }, - // World executable data - anchor_cli::config::CloneEntry { - address: "CrsqUXPpJYpVAAx5qMKU6K8RT1TzT81T8BL6JndWSeo3".to_owned(), - }, - // Registry - anchor_cli::config::CloneEntry { + account: Some(vec![ + // Registry account + anchor_cli::config::AccountEntry { address: "EHLkWwAT9oebVv9ht3mtqrvHhRVMKrt54tF3MfHTey2K".to_owned(), + filename: "tests/fixtures/registry.json".to_owned(), }, ]), ..Default::default() @@ -252,6 +247,11 @@ fn init( startup_wait: 5000, shutdown_wait: 2000, validator: Some(validator), + genesis: Some(vec![GenesisEntry { + address: WORLD_PROGRAM.to_owned(), + program: "tests/fixtures/world.so".to_owned(), + upgradeable: Some(false), + }]), ..Default::default() }; @@ -284,16 +284,54 @@ fn init( if solidity { anchor_cli::solidity_template::create_program(&project_name)?; } else { - create_component(component_name)?; create_system(system_name)?; + create_component(component_name)?; anchor_cli::rust_template::create_program(&project_name, template)?; + + // Add the component as a dependency to the system + std::process::Command::new("cargo") + .arg("add") + .arg("--package") + .arg(system_name) + .arg("--path") + .arg(format!("programs-ecs/components/{}", component_name)) + .arg("--features") + .arg("cpi") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + .map_err(|e| { + anyhow::format_err!( + "error adding component as dependency to the system: {}", + e.to_string() + ) + })?; } // Build the test suite. - fs::create_dir_all("tests")?; + fs::create_dir_all("tests/fixtures")?; // Build the migrations directory. fs::create_dir_all("migrations")?; + // Create the registry account + fs::write( + "tests/fixtures/registry.json", + rust_template::registry_account(), + )?; + + // Dump the World program into tests/fixtures/world.so + std::process::Command::new("solana") + .arg("program") + .arg("dump") + .arg("-u") + .arg("d") + .arg(WORLD_PROGRAM) + .arg("tests/fixtures/world.so") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + .map_err(|e| anyhow::format_err!("solana program dump failed: {}", e.to_string()))?; + if javascript { // Build javascript config let mut package_json = File::create("package.json")?; diff --git a/cli/src/rust_template.rs b/cli/src/rust_template.rs index d4f556d..a1ca271 100644 --- a/cli/src/rust_template.rs +++ b/cli/src/rust_template.rs @@ -67,17 +67,18 @@ fn create_system_template_simple(name: &str, program_path: &Path) -> Files { program_path.join("src").join("lib.rs"), format!( r#"use bolt_lang::*; -use component_position::Position; +use position::Position; declare_id!("{}"); #[system] pub mod {} {{ - pub fn execute(ctx: Context, args: Vec) -> Result {{ - let mut position = Position::from_account_info(&ctx.accounts.position)?; + pub fn execute(ctx: Context, args_p: Vec) -> Result {{ + let position = &mut ctx.accounts.position; position.x += 1; - Ok(position) + position.y += 1; + Ok(ctx.accounts) }} #[system_input] @@ -460,3 +461,22 @@ build test-ledger "# } + +pub fn registry_account() -> &'static str { + r#" +{ + "pubkey": "EHLkWwAT9oebVv9ht3mtqrvHhRVMKrt54tF3MfHTey2K", + "account": { + "lamports": 1002240, + "data": [ + "L65u9ri2/NoCAAAAAAAAAA==", + "base64" + ], + "owner": "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n", + "executable": false, + "rentEpoch": 18446744073709551615, + "space": 16 + } +} +"# +}