From 959fa48ead3b0fea6f6af1d182515bdf06763c97 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 6 Dec 2023 19:36:06 +0900 Subject: [PATCH] test: add github action yaml test: add test codes test: fix typo test: update yaml for test purpose fix: fix typo fix: remove test.txt fix: use single db with different schemas fix: fix port test fix: update test yaml test test: remove sign test fix: lint test codes fix: add api app port fix: add cli build process into yaml test fix: update test remove delegator test test remove delegator test test test update yaml for easier test test test test: seperate migration steps fix: remove multiple db script wip nohoist setup fix typo rollback nohoist fix: no hoist required for separated prisma client --- .github/workflows/cli.test.yaml | 66 +++++++++++++++++++++++++++++++++ cli/src/chain.ts | 2 + cli/test/chain.test.ts | 29 +++++++++++---- cli/test/delegator.ts | 13 +++---- 4 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/cli.test.yaml diff --git a/.github/workflows/cli.test.yaml b/.github/workflows/cli.test.yaml new file mode 100644 index 000000000..641b0c5f6 --- /dev/null +++ b/.github/workflows/cli.test.yaml @@ -0,0 +1,66 @@ +name: "cli: test" + +on: + push: + branches: + i-985/test/add-cli-test-yaml + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 3 + + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: orakl-test + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: "18.12" + + - name: Install dependencies + run: yarn install + + - name: Delegator db migrate + run: yarn delegator prisma-migrate dev --name init-delegator + env: + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/delegator?schema=public" + + - name: Api db migrate + run: yarn api prisma-migrate dev --name init-api + env: + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/orakl?schema=public" + + - name: Run delegator + run: yarn delegator build && yarn delegator start & + env: + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/delegator?schema=public" + PROVIDER_URL: "https://api.baobab.klaytn.net:8651" + APP_PORT: "3002" + + - name: Run api + run: yarn api build && yarn api start & + env: + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/orakl?schema=public" + ENCRYPT_PASSWORD: "abc123" + APP_PORT: "3000" + + - name: Run tests + run: yarn cli build && yarn cli test ./cli/test/chain.test.ts ./cli/test/delegator.ts + env: + ORAKL_NETWORK_API_URL: "http://127.0.0.1:3000/api/v1" + ORAKL_NETWORK_DELEGATOR_URL: "http://127.0.0.1:3002/api/v1" diff --git a/cli/src/chain.ts b/cli/src/chain.ts index eadb871fd..3eb3dc048 100644 --- a/cli/src/chain.ts +++ b/cli/src/chain.ts @@ -65,9 +65,11 @@ export function insertHandler() { try { const response = (await axios.post(CHAIN_ENDPOINT, { name }))?.data console.dir(response, { depth: null }) + return response } catch (e) { console.error('Chain was not inserted. Reason:') console.error(e?.response?.data?.message) + return e?.response?.data?.message } } return wrapper diff --git a/cli/test/chain.test.ts b/cli/test/chain.test.ts index d2dcc813f..4502e3cf6 100644 --- a/cli/test/chain.test.ts +++ b/cli/test/chain.test.ts @@ -2,28 +2,41 @@ import { describe, expect, test } from '@jest/globals' import { insertHandler, listHandler, removeHandler } from '../src/chain' describe('CLI Chain', function () { - test.skip('Should list chain', async function () { + + let initalChainId + beforeAll(async () => { + const insertResult = await insertHandler()({ name: 'boabab' }) + initalChainId = insertResult.id + }) + + afterAll(async () => { + const chains = await listHandler()() + for (const chain of chains) { + await removeHandler()({ id: chain.id }) + } + }) + + test('Should list chain', async function () { const chain = await listHandler()() expect(chain.length).toBeGreaterThan(0) }) - test.skip('Should insert new chain', async function () { + test('Should insert new chain', async function () { const chainBefore = await listHandler()() await insertHandler()({ name: 'ethereum' }) const chainAfter = await listHandler()() expect(chainAfter.length).toEqual(chainBefore.length + 1) }) - test.skip('Should not allow to insert the same chain more than once', async function () { + test('Should not allow to insert the same chain more than once', async function () { await insertHandler()({ name: 'ethereum' }) - await expect(async () => { - await insertHandler()({ name: 'ethereum' }) - }).rejects.toThrow() + const msg = await insertHandler()({ name: 'ethereum' }) + expect(msg).toEqual('Internal server error') }) - test.skip('Should delete chain based on id', async function () { + test('Should delete chain based on id', async function () { const chainBefore = await listHandler()() - await removeHandler()({ id: 1 }) + await removeHandler()({ id: initalChainId }) const chainAfter = await listHandler()() expect(chainAfter.length).toEqual(chainBefore.length - 1) }) diff --git a/cli/test/delegator.ts b/cli/test/delegator.ts index 91082aef0..98e9da836 100644 --- a/cli/test/delegator.ts +++ b/cli/test/delegator.ts @@ -8,8 +8,7 @@ import { organizationInsertHandler, organizationRemoveHandler, reporterInsertHandler, - reporterRemoveHandler, - signHandler + reporterRemoveHandler } from '../src/delegator' const unsignedTx = { @@ -32,8 +31,8 @@ const reporterAddress = '0x260836ac4f046b6887bbe16b322e7f1e5f9a0452' const contractAddress = '0x93120927379723583c7a0dd2236fcb255e96949f' const functionName = 'increment()' -describe('CLI Aggregator', function () { - test.skip('Test Organization', async function () { +describe('CLI Delegator', function () { + test('Test Delegator', async function () { // Insert Organization const organization = await organizationInsertHandler()({ name: organizationName }) expect(organization.name).toBe(organizationName) @@ -64,9 +63,9 @@ describe('CLI Aggregator', function () { }) // Sign Transaction - const signedTx = await signHandler()({ txData: unsignedTx }) - expect(signedTx.succeed).toBe(true) - console.log(signedTx) + // const signedTx = await signHandler()({ txData: unsignedTx }) + // expect(signedTx.succeed).toBe(true) + // console.log(signedTx) await functionRemoveHandler()({ id: functions.id }) await contractRemoveHandler()({ id: contract.id })