Skip to content

Commit

Permalink
test: add github action yaml
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nick-bisonai committed Dec 7, 2023
1 parent 7c20632 commit 180e77f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 15 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/cli.test.yaml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions cli/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 21 additions & 8 deletions cli/test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Check failure on line 5 in cli/test/chain.test.ts

View workflow job for this annotation

GitHub Actions / build-publish

Delete `⏎··`
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)
})
Expand Down
13 changes: 6 additions & 7 deletions cli/test/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
organizationInsertHandler,
organizationRemoveHandler,
reporterInsertHandler,
reporterRemoveHandler,
signHandler
reporterRemoveHandler
} from '../src/delegator'

const unsignedTx = {

Check warning on line 14 in cli/test/delegator.ts

View workflow job for this annotation

GitHub Actions / build-publish

'unsignedTx' is assigned a value but never used
Expand All @@ -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)
Expand Down Expand Up @@ -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 })
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"l2-api",
"monitor",
"vrf"
],
"nohoist": [
"**/prisma", "**/prisma/**", "**/@prisma/client", "@prisma/client"
]
},
"dependencies": {},
Expand Down

0 comments on commit 180e77f

Please sign in to comment.