Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 8 additions & 16 deletions basics/hello-solana/steel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions basics/hello-solana/steel/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions basics/hello-solana/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use steel::*;

declare_id!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
5 changes: 3 additions & 2 deletions basics/hello-solana/steel/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
28 changes: 25 additions & 3 deletions basics/hello-solana/steel/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
22 changes: 14 additions & 8 deletions basics/hello-solana/steel/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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`);
});
});