Skip to content

Commit

Permalink
setup action (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaviderb authored Dec 26, 2023
1 parent ec97115 commit fe178cf
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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
3 changes: 2 additions & 1 deletion e2e/down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ 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);
console.log('Solana Validator Killed');
}
}
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": "npm run build-bpf && COPYFILE_DISABLE=1 jest --forceExit"
},
"author": "",
"license": "ISC",
Expand Down
7 changes: 1 addition & 6 deletions e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ module.exports = async function() {

// 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.on('close', () => {
throw new Error('solana-test-validator closed unexpectedly')
});

// Wait for RPC to be ready

await waitForRpc();

// if Solana validator is ready, start logging

spawn('solana', ["logs"])
.stdout.on('data', (data: Buffer) => {
if (!fs.existsSync('./program.log')) {
Expand All @@ -56,7 +51,7 @@ async function waitForRpc(): Promise<boolean> {
}

async function validateRpc(): Promise<boolean> {
const data = await fetch(`http://localhost:${RPC_PORT}`, {
const data = await fetch(`http://127.0.0.1:${RPC_PORT}`, {
method: 'post',
body: JSON.stringify({
jsonrpc: "2.0",
Expand Down
3 changes: 1 addition & 2 deletions e2e/tests/counter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ describe('Counter Program', () => {
const programId = new PublicKey(process.env['SOLANA_PROGRAM_ID'] as string);
const wallet = Keypair.generate();
const port = process.env['RPC_PORT'];
const connection = new Connection(`http://localhost:${port}`, 'confirmed');

const connection = new Connection(`http://127.0.0.1:${port}`, 'confirmed');

test('Initialize Counter', async () => {
await connection.requestAirdrop(wallet.publicKey, 5000000000);
Expand Down

0 comments on commit fe178cf

Please sign in to comment.