Skip to content

Commit

Permalink
setup action
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaviderb committed Dec 26, 2023
1 parent ec97115 commit 374dae3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Solana Program Tests

on: [push]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Rust
uses: hecrj/setup-rust-action@v2
with:
rust-version: stable

- name: Setup Solana Tool suite
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.17.13/install)"
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: '18.x'

- name: Run Tests
run: |
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
solana-keygen new --no-passphrase --force -o program.json
cd e2e
npm install
npm run test



1 change: 1 addition & 0 deletions e2e/down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Global {
module.exports = async function() {
const gb = global as Global;

console.log('Killing Solana Validator...');
// Kill Solana Validator
if (gb.SOLANA_VALIDATOR_PROCESS && gb.SOLANA_VALIDATOR_PROCESS.kill()) {
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build-bpf": "cargo build-bpf --manifest-path ../Cargo.toml",
"test": "npm run build-bpf && COPYFILE_DISABLE=1 jest"
"test": "COPYFILE_DISABLE=1 jest"
},
"author": "",
"license": "ISC",
Expand Down
26 changes: 19 additions & 7 deletions e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ process.env['RPC_PORT'] = process.env['RPC_PORT'] || '8899';
const RPC_PORT = process.env['RPC_PORT'];

module.exports = async function() {
if (!fs.existsSync(PackageConfig.solana.wallet)) {
throw new Error(`wallet path: ${PackageConfig.solana.wallet} not found`);
}
// if (!fs.existsSync(PackageConfig.solana.wallet)) {
// throw new Error(`wallet path: ${PackageConfig.solana.wallet} not found`);
// }

if (!fs.existsSync(PackageConfig.solana.output)) {
throw new Error(`program path: ${PackageConfig.solana.output} not found`);
}
// if (!fs.existsSync(PackageConfig.solana.output)) {
// throw new Error(`program path: ${PackageConfig.solana.output} not found`);
// }

// Get Program Keypair
const programRawKeypair = JSON.parse(fs.readFileSync(PackageConfig.solana.wallet, 'utf-8'));
Expand All @@ -26,13 +26,19 @@ module.exports = async function() {
const gb = global as any;

// Initialize Solana Validator
gb.SOLANA_VALIDATOR_PROCESS = spawn('solana-test-validator', ['--bpf-program', programKeyPair.publicKey.toString(), programLibPath, '--reset', '--rpc-port', RPC_PORT.toString(), '-l', './validator']);
gb.SOLANA_VALIDATOR_PROCESS = spawn('solana-test-validator', ['--reset', '--rpc-port', RPC_PORT.toString(), '-l', './validator']);
gb.SOLANA_VALIDATOR_PROCESS.on('close', () => {
console.log('closed');
throw new Error('solana-test-validator closed unexpectedly')
});

// gb.SOLANA_VALIDATOR_PROCESS.stdout.on('data', (data: Buffer) => {
// // console.log(data.toString());
// });

// Wait for RPC to be ready

console.log('Waiting for RPC to be ready...')
await waitForRpc();

// if Solana validator is ready, start logging
Expand All @@ -49,6 +55,7 @@ module.exports = async function() {

async function waitForRpc(): Promise<boolean> {
while (true) {
console.log('trying....');
if (await (validateRpc())) {
return true;
}
Expand All @@ -68,5 +75,10 @@ async function validateRpc(): Promise<boolean> {
.then((res) => res.json())
.catch(() => null)

console.log(`http://localhost:${RPC_PORT}`);


console.log('result: ');
console.log(data);
return data?.result === 'ok';
}

0 comments on commit 374dae3

Please sign in to comment.