Skip to content

Commit

Permalink
test: restore skipped cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 8, 2023
1 parent d0a7a45 commit 8dbd97d
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 48 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/cli.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: "cli: test"

on:
push:
branches:
i-985/test/add-cli-test-yaml
branches: i-985/test/add-cli-test-yaml
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -44,7 +43,7 @@ jobs:
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:
Expand All @@ -60,7 +59,7 @@ jobs:
APP_PORT: "3000"

- name: Run tests
run: yarn cli build && yarn cli test ./cli/test/chain.test.ts ./cli/test/delegator.ts
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"
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
3 changes: 2 additions & 1 deletion cli/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ describe('CLI Adapter', function () {

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

test('Should not allow to insert the same adapter more than once', async function () {
Expand Down
3 changes: 2 additions & 1 deletion cli/test/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ describe('CLI Aggregator', function () {

test('Should insert new aggregator', async function () {
const aggregatorBefore = await listHandler()({})
await insertHandler()({ data: AGGREGATOR_1, chain: 'localhost' })
const result = await insertHandler()({ data: AGGREGATOR_1, chain: 'localhost' })
const aggregatorAfter = await listHandler()({})
expect(aggregatorAfter.length).toEqual(aggregatorBefore.length + 1)
await removeHandler()({ id: result.id })
})

test('Should not allow to insert the same aggregator more than once', async function () {
Expand Down
52 changes: 46 additions & 6 deletions cli/test/listener.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
import { describe, expect, test } from '@jest/globals'
import {
insertHandler as chainInsertHandler,
listHandler as chainListHandler,
removeHandler as chainRemoveHandler
} from '../src/chain'
import { insertHandler, listHandler, removeHandler } from '../src/listener'
import {
insertHandler as serviceInsertHandler,
listHandler as serviceListHandler,
removeHandler as serviceRemoveHandler
} from '../src/service'

describe('CLI Listener', function () {
const LISTENER = {
const LISTENER_0 = {
chain: 'localhost',
service: 'VRF',
address: '0x0000000000000000000000000000000000000000',
eventName: 'Event'
}

test.skip('Should list all listeners', async function () {
const LISTENER_1 = {
chain: 'localhost',
service: 'VRF',
address: '0x0000000000000000000000000000000000000001',
eventName: 'Event'
}

let initialListenerId
beforeAll(async () => {
await chainInsertHandler()({ name: 'localhost' })
await serviceInsertHandler()({ name: 'VRF' })
const insertResult = await insertHandler()(LISTENER_0)
initialListenerId = insertResult.id
})

afterAll(async () => {
const listeners = await listHandler()({})
for (const listener of listeners) {
await removeHandler()({ id: listener.id })
}
const chains = await chainListHandler()()
for (const chain of chains) {
await chainRemoveHandler()({ id: chain.id })
}
const services = await serviceListHandler()()
for (const service of services) {
await serviceRemoveHandler()({ id: service.id })
}
})

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

test.skip('Should insert new listener', async function () {
test('Should insert new listener', async function () {
const listenerBefore = await listHandler()({})
await insertHandler()(LISTENER)
await insertHandler()(LISTENER_1)
const listenerAfter = await listHandler()({})
expect(listenerAfter.length).toEqual(listenerBefore.length + 1)
})

test.skip('Should delete listener based on id', async function () {
test('Should delete listener based on id', async function () {
const listenerBefore = await listHandler()({})
await removeHandler()({ id: 1 })
await removeHandler()({ id: initialListenerId })
const listenerAfter = await listHandler()({})
expect(listenerAfter.length).toEqual(listenerBefore.length - 1)
})
Expand Down
59 changes: 38 additions & 21 deletions cli/test/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
import { describe, expect, test } from '@jest/globals'
import { insertHandler, listHandler, removeHandler } from '../src/proxy'

const proxyData = {
protocol: 'http',
host: '127.0.0.1',
port: 80
}

describe('CLI Proxy', function () {
test.skip('Should insert new proxy', async function () {
const proxyBefore = await listHandler()()
await insertHandler()(proxyData)
const proxyAfter = await listHandler()()
expect(proxyAfter.length).toEqual(proxyBefore.length + 1)
})
const proxyData_0 = {
protocol: 'http',
host: '127.0.0.1',
port: 80
}

const proxyData_1 = {
protocol: 'http',
host: '127.0.0.2',
port: 80
}

test.skip('Should not allow to insert the same proxy more than once', async function () {
await insertHandler()(proxyData)
await expect(async () => {
await insertHandler()(proxyData)
}).rejects.toThrow()
let initialProxyId
beforeAll(async () => {
const insertResult = await insertHandler()(proxyData_0)
initialProxyId = insertResult.id
})
afterAll(async () => {
const proxies = await listHandler()()
for (const proxy of proxies) {
await removeHandler()({ id: proxy.id })
}
})

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

test.skip('Should delete proxy based on id', async function () {
test('Should insert new proxy', async function () {
const proxyBefore = await listHandler()()
const result = await insertHandler()(proxyData_1)
const proxyAfter = await listHandler()()
expect(proxyAfter.length).toEqual(proxyBefore.length + 1)
await removeHandler()({ id: result.id })
})

test('Should not allow to insert the same proxy more than once', async function () {
await insertHandler()(proxyData_1)
const msg = await insertHandler()(proxyData_1)
expect(msg).toEqual('Internal server error')
})

test('Should delete proxy based on id', async function () {
const proxyBefore = await listHandler()()
const lastInstance = proxyBefore[proxyBefore.length - 1]
await removeHandler()({ id: Number(lastInstance.id) })
await removeHandler()({ id: initialProxyId })
const proxyAfter = await listHandler()()
expect(proxyAfter.length).toEqual(proxyBefore.length - 1)
})
Expand Down
30 changes: 21 additions & 9 deletions cli/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,40 @@ import { describe, expect, test } from '@jest/globals'
import { insertHandler, listHandler, removeHandler } from '../src/service'

describe('CLI Service', function () {
test.skip('Should list service', async function () {
let initialServiceId
beforeAll(async () => {
const result = await insertHandler()({ name: 'VRF' })
initialServiceId = result.id
})
afterAll(async () => {
const services = await listHandler()()
for (const service of services) {
await removeHandler()({ id: service.id })
}
})

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

test.skip('Should insert new service', async function () {
test('Should insert new service', async function () {
const serviceBefore = await listHandler()()
await insertHandler()({ name: 'Automation' })
const result = await insertHandler()({ name: 'Automation' })
const serviceAfter = await listHandler()()
expect(serviceAfter.length).toEqual(serviceBefore.length + 1)
await removeHandler()({ id: result.id })
})

test.skip('Should not allow to insert the same service more than once', async function () {
test('Should not allow to insert the same service more than once', async function () {
await insertHandler()({ name: 'Automation' })
await expect(async () => {
await insertHandler()({ name: 'Automation' })
}).rejects.toThrow()
const msg = await insertHandler()({ name: 'Automation' })
expect(msg).toEqual('Internal server error')
})

test.skip('Should delete service based on id', async function () {
test('Should delete service based on id', async function () {
const serviceBefore = await listHandler()()
await removeHandler()({ id: 1 })
await removeHandler()({ id: initialServiceId })
const serviceAfter = await listHandler()()
expect(serviceAfter.length).toEqual(serviceBefore.length - 1)
})
Expand Down
46 changes: 40 additions & 6 deletions cli/test/vrf.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { describe, expect, test } from '@jest/globals'
import {
insertHandler as chainInsertHandler,
listHandler as chainListHandler,
removeHandler as chainRemoveHandler
} from '../src/chain'
import { insertHandler, listHandler, removeHandler } from '../src/vrf'

describe('CLI Vrf', function () {
const VRF = {
const VRF_0 = {
chain: 'baobab',
sk: 'adcfaf9a860722a89472884a2aab4a62f06a42fd4bee55f2fc7f2f11b07f1d81',
pk: '041f058731839e8c2fb3a77a4be788520f1743f1298a84bd138871f31ffdee04e42b4f962995ba0135eed67f3ebd1739d4b09f1b84224c0d6765e5f426b25443a4',
Expand All @@ -11,21 +16,50 @@ describe('CLI Vrf', function () {
keyHash: '0x956506aeada5568c80c984b908e9e1af01bd96709977b0b5cb1957736e80e883'
}

test.skip('Should list all VRF keys', async function () {
const VRF_1 = {
chain: 'localhost',
sk: '123',
pk: '456',
pkX: '789',
pkY: '101112',
keyHash: '0x'
}

let initialVrfId
beforeAll(async () => {
await chainInsertHandler()({ name: 'baobab' })
await chainInsertHandler()({ name: 'localhost' })
const insertResult = await insertHandler()(VRF_0)
initialVrfId = insertResult.id
})
afterAll(async () => {
const vrfs = await listHandler()({})
for (const vrf of vrfs) {
await removeHandler()({ id: vrf.id })
}

const chains = await chainListHandler()()
for (const chain of chains) {
await chainRemoveHandler()({ id: chain.id })
}
})

test('Should list all VRF keys', async function () {
const vrf = await listHandler()({})
expect(vrf.length).toBeGreaterThan(0)
})

test.skip('Should insert new VRF keys', async function () {
test('Should insert new VRF keys', async function () {
const vrfBefore = await listHandler()({})
await insertHandler()(VRF)
const insertResult = await insertHandler()(VRF_1)
const vrfAfter = await listHandler()({})
expect(vrfAfter.length).toEqual(vrfBefore.length + 1)
await removeHandler()({ id: insertResult.id })
})

test.skip('Should delete VRF based on id', async function () {
test('Should delete VRF based on id', async function () {
const vrfBefore = await listHandler()({})
await removeHandler()({ id: 1 })
await removeHandler()({ id: initialVrfId })
const vrfAfter = await listHandler()({})
expect(vrfAfter.length).toEqual(vrfBefore.length - 1)
})
Expand Down

0 comments on commit 8dbd97d

Please sign in to comment.