Skip to content

Commit

Permalink
add steel framework
Browse files Browse the repository at this point in the history
  • Loading branch information
heyAyushh committed Oct 7, 2024
1 parent 8f894a3 commit 009a7ba
Show file tree
Hide file tree
Showing 8 changed files with 2,252 additions and 605 deletions.
1,412 changes: 807 additions & 605 deletions basics/hello-solana/native/pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions basics/hello-solana/steel/cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = [
"program",
]
resolver = "2"

[profile.release]
overflow-checks = true
28 changes: 28 additions & 0 deletions basics/hello-solana/steel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "steel-hello-solana",
"version": "1.0.0",
"description": "hello world with steel framework for solana",
"scripts": {
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/hello_solana_program.so"
},
"keywords": [],
"author": "Ayush Chauhan",
"license": "ISC",
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^22.7.4",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"solana-bankrun": "^0.3.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
},
"dependencies": {
"@solana/web3.js": "^1.95.3"
}
}
1,336 changes: 1,336 additions & 0 deletions basics/hello-solana/steel/pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions basics/hello-solana/steel/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "steel-hello-solana"
version = "0.1.0"
edition = "2021"

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

[dependencies]
solana-program = "2.0.13"
steel = "1.3.0"
16 changes: 16 additions & 0 deletions basics/hello-solana/steel/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use steel::*;
use solana_program::msg;

entrypoint!(process_instruction);

fn process_instruction(
program_id: &Pubkey,
_accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
msg!("Hello, Solana!");

msg!("Our program's Program ID: {}", &program_id);

Ok(())
}
36 changes: 36 additions & 0 deletions basics/hello-solana/steel/tests/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, test } from 'node:test';
import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js';
import { assert } from 'chai';
import { start } from 'solana-bankrun';

describe('hello-solana', async () => {
// load program in solana-bankrun
const PROGRAM_ID = PublicKey.unique();
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;
// 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
});

const tx = new Transaction();
tx.recentBlockhash = blockhash;
tx.add(ix).sign(payer);

// Now we process the transaction
const transaction = await client.processTransaction(tx);

assert(transaction.logMessages[0].startsWith(`Program ${PROGRAM_ID}`));
assert(transaction.logMessages[1] === 'Program log: Hello, Solana!');
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);
});
});
10 changes: 10 additions & 0 deletions basics/hello-solana/steel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"types": ["mocha", "chai", "node"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
}

0 comments on commit 009a7ba

Please sign in to comment.