diff --git a/basics/hello-solana/steel/Cargo.toml b/basics/hello-solana/steel/Cargo.toml index be454182e..a5a13c951 100644 --- a/basics/hello-solana/steel/Cargo.toml +++ b/basics/hello-solana/steel/Cargo.toml @@ -1,21 +1,13 @@ [workspace] +members = [ + "api", + "program" +] resolver = "2" -members = ["program"] -[workspace.package] -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -homepage = "" -documentation = "" -repository = "" -readme = "./README.md" -keywords = ["solana"] +[profile.release] +overflow-checks = true [workspace.dependencies] -bytemuck = "1.14" -num_enum = "0.7" -solana-program = "1.18" -steel = "2.0" -thiserror = "1.0" -solana-sdk = "1.18" +solana-program = "1.18.17" +steel = "2.1" diff --git a/basics/hello-solana/steel/api/Cargo.toml b/basics/hello-solana/steel/api/Cargo.toml new file mode 100644 index 000000000..337903c96 --- /dev/null +++ b/basics/hello-solana/steel/api/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "steel-hello-solana-api" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] + +[dependencies] +solana-program.workspace = true +steel.workspace = true diff --git a/basics/hello-solana/steel/api/src/lib.rs b/basics/hello-solana/steel/api/src/lib.rs new file mode 100644 index 000000000..017b8911b --- /dev/null +++ b/basics/hello-solana/steel/api/src/lib.rs @@ -0,0 +1,3 @@ +use steel::*; + +declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35"); diff --git a/basics/hello-solana/steel/program/Cargo.toml b/basics/hello-solana/steel/program/Cargo.toml index 43004175e..92208589c 100644 --- a/basics/hello-solana/steel/program/Cargo.toml +++ b/basics/hello-solana/steel/program/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" crate-type = ["cdylib", "lib"] [dependencies] -solana-program = "2.0.13" -steel = "1.3.0" +solana-program.workspace = true +steel.workspace = true +steel-hello-solana-api = {path = "../api"} \ No newline at end of file diff --git a/basics/hello-solana/steel/program/src/lib.rs b/basics/hello-solana/steel/program/src/lib.rs index e0e9b453d..f5efe56aa 100644 --- a/basics/hello-solana/steel/program/src/lib.rs +++ b/basics/hello-solana/steel/program/src/lib.rs @@ -5,12 +5,34 @@ entrypoint!(process_instruction); fn process_instruction( program_id: &Pubkey, - _accounts: &[AccountInfo], - _instruction_data: &[u8], + accounts: &[AccountInfo], + instruction_data: &[u8], ) -> ProgramResult { - msg!("Hello, Solana!"); + // The instruction data passed in + msg!( + "Hello, {}!", + String::from_utf8(instruction_data.to_vec()).unwrap() + ); + // Check the supplied program id is the same as our program ID + if steel_hello_solana_api::ID.ne(program_id) { + return Err(ProgramError::IncorrectProgramId); + }; + + // Our Program ID msg!("Our program's Program ID: {}", &program_id); + // The number of accounts passed in + msg!("We have {} accounts", accounts.len()); + + for (id, account) in accounts.iter().enumerate() { + // The PublicKey of the account + msg!("Account {} PublicKey: {}", id, account.key); + // Do we expect a signature from this account? + msg!("Account {} is signer?: {}", id, account.is_signer); + // Will this account be modified in this instruction? + msg!("Account {} is writable?: {}", id, account.is_writable); + } + Ok(()) } diff --git a/basics/hello-solana/steel/tests/index.test.ts b/basics/hello-solana/steel/tests/index.test.ts index 4e3a04531..78a592f8e 100644 --- a/basics/hello-solana/steel/tests/index.test.ts +++ b/basics/hello-solana/steel/tests/index.test.ts @@ -5,18 +5,22 @@ import { start } from 'solana-bankrun'; describe('hello-solana', async () => { // load program in solana-bankrun - const PROGRAM_ID = PublicKey.unique(); + const PROGRAM_ID = new PublicKey('z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35'); const context = await start([{ name: 'steel_hello_solana', programId: PROGRAM_ID }], []); const client = context.banksClient; const payer = context.payer; test('Say hello!', async () => { const blockhash = context.lastBlockhash; + + // pass in our name as the instruction data. + const name = 'The Wuh'; + // We set up our instruction first. const ix = new TransactionInstruction({ - keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }], - programId: PROGRAM_ID, - data: Buffer.alloc(0), // No data + keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }], // Accounts we are passing in + programId: PROGRAM_ID, // Our Program ID + data: Buffer.from(name), // takes in a buffer }); const tx = new Transaction(); @@ -26,11 +30,13 @@ describe('hello-solana', async () => { // Now we process the transaction const transaction = await client.processTransaction(tx); + const logCount = transaction.logMessages.length; + assert(transaction.logMessages[0].startsWith(`Program ${PROGRAM_ID}`)); - assert(transaction.logMessages[1] === 'Program log: Hello, Solana!'); + assert(transaction.logMessages[1] === `Program log: Hello, ${name}!`); assert(transaction.logMessages[2] === `Program log: Our program's Program ID: ${PROGRAM_ID}`); - assert(transaction.logMessages[3].startsWith(`Program ${PROGRAM_ID} consumed`)); - assert(transaction.logMessages[4] === `Program ${PROGRAM_ID} success`); - assert(transaction.logMessages.length === 5); + assert(transaction.logMessages[3] === `Program log: We have ${ix.keys.length} accounts`); + assert(transaction.logMessages[logCount - 2].startsWith(`Program ${PROGRAM_ID} consumed`)); + assert(transaction.logMessages[logCount - 1] === `Program ${PROGRAM_ID} success`); }); });