Skip to content

Commit

Permalink
Restore cli tests (#998)
Browse files Browse the repository at this point in the history
sets up test codes and github action yaml file
  • Loading branch information
nick-bisonai authored Dec 8, 2023
1 parent 00fdf29 commit b6de4cb
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 83 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/cli.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "cli: test"

on:
push:
branches-ignore:
- "master"
paths:
- "cli/**"
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: "20.10.0"

- 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
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"
4 changes: 4 additions & 0 deletions cli/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export function insertHandler() {
try {
const response = (await axios.post(ADAPTER_ENDPOINT, data)).data
console.dir(response, { depth: null })
return response
} catch (e) {
console.error('Adapter was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down Expand Up @@ -114,11 +116,13 @@ export function hashHandler() {
const adapterWithCorrectHash = (await axios.post(endpoint, adapter, { params: { verify } }))
.data
console.dir(adapterWithCorrectHash, { depth: null })
return adapterWithCorrectHash
} catch (e) {
console.error('Adapter hash could not be computed. Reason:')
const errMsg = e?.response?.data?.message ? e.response.data.message : e.message

console.error(errMsg)
return errMsg
}
}
return wrapper
Expand Down
7 changes: 6 additions & 1 deletion cli/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ export function insertHandler() {
try {
const result = (await axios.post(AGGREGATOR_ENDPOINT, { ...data, chain, fetcherType })).data
console.dir(result, { depth: null })
return result
} catch (e) {
console.error('Aggregator was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down Expand Up @@ -227,9 +229,12 @@ export function hashHandler() {
})
).data
console.dir(aggregatorWithCorrectHash, { depth: null })
return aggregatorWithCorrectHash
} catch (e) {
console.error('Aggregator hash could not be computed. Reason:')
console.error(e.message)
const errMsg = e?.response?.data?.message ? e.response.data.message : e.message
console.error(errMsg)
return errMsg
}
}
return wrapper
Expand Down
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
2 changes: 2 additions & 0 deletions cli/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ export function insertHandler() {
const result = (await axios.post(LISTENER_ENDPOINT, { chain, service, address, eventName }))
.data
console.dir(result, { depth: null })
return result
} catch (e) {
console.error('Listener was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ export function insertHandler() {
try {
const response = (await axios.post(PROXY_ENDPOINT, { protocol, host, port, location }))?.data
console.dir(response, { depth: null })
return response
} catch (e) {
console.error('Proxy was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/service.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(SERVICE_ENDPOINT, { name }))?.data
console.dir(response, { depth: null })
return response
} catch (e) {
console.error('Service was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/vrf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ export function insertHandler() {
try {
const result = (await axios.post(VRF_ENDPOINT, { chain, pk, sk, pkX, pkY, keyHash })).data
console.dir(result, { depth: null })
return result
} catch (e) {
console.error('VRF key was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
}
}
return wrapper
Expand Down
61 changes: 49 additions & 12 deletions cli/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { describe, expect, test } from '@jest/globals'
import { insertHandler, listHandler, removeHandler } from '../src/adapter'

describe('CLI Adapter', function () {
const ADAPTER = {
const ADAPTER_0 = {
active: true,
name: 'X-Y',
decimals: '8',
decimals: 8,
adapterHash: '0x020e150749af3bffaec9ae337da0b9b00c3cfe0b46b854a8e2f5922f6ba2c5db',
feeds: [
{
name: 'data-X-Y',
Expand All @@ -23,28 +24,64 @@ describe('CLI Adapter', function () {
]
}

test.skip('Should list Adapters', async function () {
const ADAPTER_1 = {
active: true,
name: 'Z-X',
decimals: 8,
adapterHash: '0x12da2f5119ba624ed025303b424d637349c0d120d02bd66a9cfff57e98463a81',
feeds: [
{
name: 'data-Z-X',
definition: {
url: 'https://data.com',
headers: { 'Content-Type': 'application/json' },
method: 'GET',
reducers: [
{ function: 'PARSE', args: ['PRICE'] },
{ function: 'POW10', args: '8' },
{ function: 'ROUND' }
]
}
}
]
}

let initalAdapterId
beforeAll(async () => {
// insert default adapter
const insertResult = await insertHandler()({ data: ADAPTER_0 })
initalAdapterId = insertResult.id
})

afterAll(async () => {
const adapters = await listHandler()()
for (const adapter of adapters) {
await removeHandler()({ id: adapter.id })
}
})

test('Should list Adapters', async function () {
const adapter = await listHandler()()
expect(adapter.length).toBeGreaterThan(0)
})

test.skip('Should insert new adapter', async function () {
test('Should insert new adapter', async function () {
const adapterBefore = await listHandler()()
await insertHandler()({ data: ADAPTER })
const result = await insertHandler()({ data: ADAPTER_1 })
const adapterAfter = await listHandler()()
expect(adapterAfter.length).toEqual(adapterBefore.length + 1)
await removeHandler()({ id: result.id })
})

test.skip('Should not allow to insert the same adapter more than once', async function () {
await insertHandler()({ data: ADAPTER })
await expect(async () => {
await insertHandler()({ data: ADAPTER })
}).rejects.toThrow()
test('Should not allow to insert the same adapter more than once', async function () {
await insertHandler()({ data: ADAPTER_1 })
const msg = await insertHandler()({ data: ADAPTER_1 })
expect(msg).toEqual('Unique constraint failed on the adapter_hash')
})

test.skip('Should delete adapter based on id', async function () {
test('Should delete adapter based on id', async function () {
const adapterBefore = await listHandler()()
await removeHandler()({ id: 1 })
await removeHandler()({ id: initalAdapterId })
const adapterAfter = await listHandler()()
expect(adapterAfter.length).toEqual(adapterBefore.length - 1)
})
Expand Down
Loading

0 comments on commit b6de4cb

Please sign in to comment.