From fe178cf4d76a706ced6859d0664d4b897e554b9f Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Tue, 26 Dec 2023 13:48:02 -0500 Subject: [PATCH] setup action (#1) --- .github/workflows/tests.yml | 34 ++++++++++++++++++++++++++++++++++ e2e/down.ts | 3 ++- e2e/package.json | 2 +- e2e/setup.ts | 7 +------ e2e/tests/counter.test.ts | 3 +-- 5 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..402412b --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/e2e/down.ts b/e2e/down.ts index 6611f55..239371c 100644 --- a/e2e/down.ts +++ b/e2e/down.ts @@ -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'); } } diff --git a/e2e/package.json b/e2e/package.json index c281e43..dc449d5 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -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", diff --git a/e2e/setup.ts b/e2e/setup.ts index 2f110c9..7c9b005 100644 --- a/e2e/setup.ts +++ b/e2e/setup.ts @@ -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')) { @@ -56,7 +51,7 @@ async function waitForRpc(): Promise { } async function validateRpc(): Promise { - 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", diff --git a/e2e/tests/counter.test.ts b/e2e/tests/counter.test.ts index e206d0a..04ed229 100644 --- a/e2e/tests/counter.test.ts +++ b/e2e/tests/counter.test.ts @@ -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);