Skip to content

Commit 88f49f6

Browse files
committed
adding the hello-solana tests
1 parent bb7a577 commit 88f49f6

File tree

5 files changed

+1480
-0
lines changed

5 files changed

+1480
-0
lines changed

a.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash -xe
2+
build() {
3+
declare -a ProjectDirs=(
4+
"basics/account-data/native/program"
5+
"basics/checking-accounts/native/program"
6+
"basics/close-account/native/program"
7+
"basics/counter/native/program"
8+
"basics/create-account/native/program"
9+
"basics/hello-solana/native/program"
10+
"basics/pda-rent-payer/native/program"
11+
"basics/processing-instructions/native/program"
12+
"basics/program-derived-addresses/native/program"
13+
"basics/realloc/native/program"
14+
"basics/rent/native/program"
15+
"basics/repository-layout/native/program"
16+
"basics/transfer-sol/native/program"
17+
)
18+
for projectDir in "${ProjectDirs[@]}"; do
19+
echo "
20+
********
21+
Building $projectDir
22+
********"
23+
cd $projectDir
24+
if cargo-build-sbf --verbose; then
25+
echo "Build succeeded for $projectDir."
26+
else
27+
failed=true
28+
failed_builds+=($projectDir)
29+
echo "Build failed for $projectDir. Continuing with the next program."
30+
fi
31+
cd - > /dev/null
32+
done
33+
}
34+
35+
run() {
36+
solana -V
37+
rustc -V
38+
declare -a ProjectDirs=(
39+
#"basics/account-data/native/"
40+
#"basics/checking-accounts/native/"
41+
#"basics/close-account/native/"
42+
#"basics/counter/native/"
43+
#"basics/create-account/native/"
44+
"basics/hello-solana/native/"
45+
#"basics/pda-rent-payer/native/"
46+
#"basics/processing-instructions/native/"
47+
#"basics/program-derived-addresses/native/"
48+
#"basics/rent/native/"
49+
#"basics/repository-layout/native/"
50+
#"basics/transfer-sol/native/"
51+
)
52+
for projectDir in "${ProjectDirs[@]}"; do
53+
echo "
54+
********
55+
Testing $projectDir
56+
********"
57+
cd $projectDir
58+
pnpm install --frozen-lockfile
59+
if (cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test); then
60+
echo "Tests succeeded for $projectDir."
61+
else
62+
failed=true
63+
failed_tests+=($projectDir)
64+
echo "Tests failed for $projectDir. Continuing with the next program."
65+
fi
66+
cd - > /dev/null
67+
done
68+
}
69+
70+
run

basics/hello-solana/move/deploy.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/** WIP */
2+
import * as fs from 'fs';
3+
import * as solanaWeb3 from '@solana/web3.js';
4+
5+
async function startValidator() {
6+
// TODO: Start a test-validator programmatically to have a self contained test.
7+
// solana-test-validator -l test-ledger
8+
}
9+
10+
async function deployProgramShell(programPath: string) {
11+
const util = require('util');
12+
const exec = util.promisify(require('child_process').exec);
13+
try {
14+
const { stdout, stderr } = await exec(`solana program deploy ${programPath}`);
15+
console.log('stdout:', stdout);
16+
console.log('stderr:', stderr);
17+
return stdout;
18+
} catch (e) {
19+
console.error(e); // should contain code (exit code) and signal (that caused the termination).
20+
return e;
21+
}
22+
}
23+
24+
// WIP: Function to deploy a Solana program programmatically.
25+
async function deployProgram(
26+
connection: solanaWeb3.Connection,
27+
payer: solanaWeb3.Keypair,
28+
programKeypair: solanaWeb3.Keypair,
29+
programPath: string
30+
): Promise<solanaWeb3.PublicKey> {
31+
// solana program deploy programPath
32+
// Load the program data
33+
const programData = fs.readFileSync(programPath);
34+
35+
// Allocate space for the program data
36+
const transaction = new solanaWeb3.Transaction();
37+
const { feeCalculator } = await connection.getRecentBlockhash();
38+
const programSpace = solanaWeb3.BpfLoader.getMinimumBalanceForRentExemption(
39+
programData.length,
40+
feeCalculator
41+
);
42+
43+
// Create the program account
44+
transaction.add(
45+
solanaWeb3.SystemProgram.createAccount({
46+
fromPubkey: payer.publicKey,
47+
newAccountPubkey: programKeypair.publicKey,
48+
lamports: programSpace,
49+
space: programData.length,
50+
programId: solanaWeb3.BpfLoader.programId,
51+
})
52+
);
53+
54+
// Load the program
55+
transaction.add(
56+
solanaWeb3.BpfLoader.load(
57+
connection,
58+
payer,
59+
programKeypair,
60+
programData,
61+
solanaWeb3.BpfLoader.programId
62+
)
63+
);
64+
65+
// Send the transaction
66+
await solanaWeb3.sendAndConfirmTransaction(
67+
connection,
68+
transaction,
69+
[payer, programKeypair]
70+
);
71+
72+
return programKeypair.publicKey;
73+
}
74+
75+
async function main() {
76+
const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('devnet'), 'confirmed');
77+
const payer = solanaWeb3.Keypair.generate();
78+
const programKeypair = solanaWeb3.Keypair.generate();
79+
const programPath = 'bin/hello_solana_move_program.so';
80+
const programId = await deployProgramShell(programPath);
81+
console.log('Program deployed with', programId);
82+
}
83+
84+
main().catch(console.error);

basics/hello-solana/native/go.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
2+
solana program deploy ./program/target/so/program.so

basics/hello-solana/native/kp.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import base58
2+
import json
3+
import sys
4+
5+
#key_array = [4,182,130,247,119,117,227,207,112,73,170,126,222,197,244,99,215,107,255,202,33,43,36,17,104,111,157,246,196,192,174,95,240,23,238,206,118,215,154,238,229,96,11,37,156,123,51,223,5,231,17,117,86,136,103,14,75,95,175,132,148,54,1,46]
6+
7+
def print_keys_from_file(f):
8+
key_array = json.load(open(f, 'r'))
9+
10+
secret_key = key_array[0:32]
11+
public_key = key_array[32:64]
12+
13+
sk = base58.b58encode(bytes(secret_key))
14+
pk = base58.b58encode(bytes(public_key))
15+
16+
print(pk)
17+
print(sk)
18+
19+
if __name__ == "__main__":
20+
print_keys_from_file(sys.argv[1])

0 commit comments

Comments
 (0)