Skip to content

Commit 10a953d

Browse files
authored
Merge branch 'solana-developers:main' into litesvm/hello-solana
2 parents 8c0bd14 + ce50ad4 commit 10a953d

File tree

15 files changed

+433
-19
lines changed

15 files changed

+433
-19
lines changed

.github/workflows/solana-native.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ jobs:
135135
return 1
136136
fi
137137
138-
# Run Rust unit tests
138+
# Test
139+
if ! pnpm build-and-test; then
140+
echo "::error::tests failed for $project"
141+
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
142+
cd - > /dev/null
143+
return 1
144+
fi
145+
146+
# Run Rust unit tests
139147
if [ -d "program" ]; then
140148
echo "Running Rust unit tests for $project"
141149
if ! cargo test --manifest-path=./program/Cargo.toml; then
@@ -146,14 +154,6 @@ jobs:
146154
fi
147155
fi
148156
149-
# Test
150-
if ! pnpm build-and-test; then
151-
echo "::error::tests failed for $project"
152-
echo "$project: tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt
153-
cd - > /dev/null
154-
return 1
155-
fi
156-
157157
echo "Build and tests succeeded for $project with $solana_version version."
158158
cd - > /dev/null
159159
return 0

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

basics/account-data/native/program/tests/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ fn test_account_data() {
1919

2020
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
2121

22-
let program_bytes =
23-
include_bytes!("../../../../../target/deploy/account_data_native_program.so");
22+
let program_bytes = include_bytes!("../../tests/fixtures/account_data_native_program.so");
2423

2524
svm.add_program(program_id, program_bytes).unwrap();
2625

basics/checking-accounts/native/program/tests/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ fn test_checking_accounts() {
1616
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
1717

1818
let program_id = Pubkey::new_unique();
19-
let program_bytes =
20-
include_bytes!("../../../../../target/deploy/checking_accounts_native_program.so");
19+
let program_bytes = include_bytes!("../../tests/fixtures/checking_accounts_native_program.so");
2120

2221
svm.add_program(program_id, program_bytes).unwrap();
2322

basics/checking-accounts/native/tests/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { start } from 'solana-bankrun';
44

55
describe('Checking accounts', async () => {
66
const PROGRAM_ID = PublicKey.unique();
7-
const context = await start([{ name: 'checking_accounts_program', programId: PROGRAM_ID }], []);
7+
const context = await start([{ name: 'checking_accounts_native_program', programId: PROGRAM_ID }], []);
88
const client = context.banksClient;
99
const payer = context.payer;
1010
const rent = await client.getRent();

basics/cross-program-invocation/native/programs/hand/Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ edition = "2021"
66
[features]
77
no-entrypoint = []
88
cpi = ["no-entrypoint"]
9+
custom-heap = []
10+
custom-panic = []
911

1012
[dependencies]
1113
borsh = "1.5.7"
1214
borsh-derive = "1.5.7"
1315
solana-program = "3.0"
1416
cross-program-invocatio-native-lever = { path = "../lever", features = ["cpi"] }
1517

16-
1718
[lib]
1819
crate-type = ["cdylib", "lib"]
20+
21+
[dev-dependencies]
22+
litesvm = "0.8.1"
23+
solana-instruction = "3.0.0"
24+
solana-keypair = "3.0.1"
25+
solana-native-token = "3.0.0"
26+
solana-pubkey = "3.0.0"
27+
solana-transaction = "3.0.1"
28+
solana-system-interface = {version = "2.0.0", features = ["bincode"]}
29+
30+
[lints.rust]
31+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use cross_program_invocatio_native_lever::{PowerStatus, SetPowerStatus};
2+
use litesvm::LiteSVM;
3+
use solana_instruction::{AccountMeta, Instruction};
4+
use solana_keypair::{Keypair, Signer};
5+
use solana_native_token::LAMPORTS_PER_SOL;
6+
use solana_pubkey::Pubkey;
7+
use solana_transaction::Transaction;
8+
9+
#[test]
10+
fn test_cpi() {
11+
let hand_program_id = Pubkey::new_unique();
12+
let lever_program_id = Pubkey::new_unique();
13+
let hand_program_bytes =
14+
include_bytes!("../../../target/deploy/cross_program_invocatio_native_hand.so");
15+
let lever_program_bytes =
16+
include_bytes!("../../../target/deploy/cross_program_invocatio_native_lever.so");
17+
18+
let payer = Keypair::new();
19+
let power_account = Keypair::new();
20+
21+
let mut svm = LiteSVM::new();
22+
23+
svm.add_program(hand_program_id, hand_program_bytes)
24+
.unwrap();
25+
svm.add_program(lever_program_id, lever_program_bytes)
26+
.unwrap();
27+
28+
svm.airdrop(&payer.pubkey(), LAMPORTS_PER_SOL * 10).unwrap();
29+
30+
let data = borsh::to_vec(&PowerStatus { is_on: true }).unwrap();
31+
32+
let initiate_lever_ix = Instruction {
33+
program_id: lever_program_id,
34+
accounts: vec![
35+
AccountMeta::new(power_account.pubkey(), true),
36+
AccountMeta::new(payer.pubkey(), true),
37+
AccountMeta::new(solana_system_interface::program::ID, false),
38+
],
39+
data,
40+
};
41+
42+
let tx = Transaction::new_signed_with_payer(
43+
&[initiate_lever_ix],
44+
Some(&payer.pubkey()),
45+
&[&payer, &power_account],
46+
svm.latest_blockhash(),
47+
);
48+
49+
let _ = svm.send_transaction(tx).is_ok();
50+
51+
let data = borsh::to_vec(&SetPowerStatus {
52+
name: "Chris".to_string(),
53+
})
54+
.unwrap();
55+
56+
let pull_lever_ix = Instruction {
57+
program_id: hand_program_id,
58+
accounts: vec![
59+
AccountMeta::new(power_account.pubkey(), false),
60+
AccountMeta::new(lever_program_id, false),
61+
],
62+
data,
63+
};
64+
65+
let tx = Transaction::new_signed_with_payer(
66+
&[pull_lever_ix],
67+
Some(&payer.pubkey()),
68+
&[&payer],
69+
svm.latest_blockhash(),
70+
);
71+
72+
let _ = svm.send_transaction(tx).is_ok();
73+
}

basics/cross-program-invocation/native/programs/lever/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ edition = "2021"
66
[features]
77
no-entrypoint = []
88
cpi = ["no-entrypoint"]
9+
custom-heap = []
10+
custom-panic = []
911

1012
[dependencies]
1113
borsh = "1.5.7"
@@ -15,3 +17,6 @@ solana-system-interface = {version = "2.0.0", features = ["bincode"]}
1517

1618
[lib]
1719
crate-type = ["cdylib", "lib"]
20+
21+
[lints.rust]
22+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }

basics/program-derived-addresses/native/tests/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { start } from 'solana-bankrun';
66

77
describe('PDAs', async () => {
88
const PROGRAM_ID = PublicKey.unique();
9-
const context = await start([{ name: 'program_derived_addresses_program', programId: PROGRAM_ID }], []);
9+
const context = await start([{ name: 'program_derived_addresses_native_program', programId: PROGRAM_ID }], []);
1010
const client = context.banksClient;
1111
const payer = context.payer;
1212
const rent = await client.getRent();

basics/realloc/native/program/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ solana-system-interface.workspace = true
1313
crate-type = ["cdylib", "lib"]
1414

1515
[features]
16-
anchor-debug = []
1716
custom-heap = []
1817
custom-panic = []
1918

2019
[lints.rust]
2120
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("solana"))'] }
21+
22+
[dev-dependencies]
23+
litesvm = "0.8.1"
24+
solana-instruction = "3.0.0"
25+
solana-keypair = "3.0.1"
26+
solana-native-token = "3.0.0"
27+
solana-pubkey = "3.0.0"
28+
solana-transaction = "3.0.1"

0 commit comments

Comments
 (0)