Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CLI) Fix cli test, update print list #1113

Merged
merged 19 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli.test.yaml
This conversation was marked as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
cd ./go-api
go run main.go &
env:
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/orakl?schema=public"
DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/orakl-test?search_path=public"
ENCRYPT_PASSWORD: "abc123"
APP_PORT: "3000"
REDIS_HOST: "localhost"
Expand Down
4 changes: 2 additions & 2 deletions cli/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export function insertHandler() {
return response
} catch (e) {
console.error('Adapter was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
console.error(e?.response?.data)
return e?.response?.data
}
}
return wrapper
Expand Down
4 changes: 2 additions & 2 deletions cli/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export function insertHandler() {
return result
} catch (e) {
console.error('Aggregator was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
console.error(e?.response?.data)
return e?.response?.data
}
}
return wrapper
Expand Down
4 changes: 2 additions & 2 deletions cli/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function insertHandler() {
return response
} catch (e) {
console.error('Chain was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
console.error(e?.response?.data)
return e?.response?.data
}
}
return wrapper
Expand Down
20 changes: 14 additions & 6 deletions cli/src/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,27 @@ export function reporterListHandler() {
const endpoint = buildUrl(ORAKL_NETWORK_DELEGATOR_URL, `reporter`)
const result = (await axios.get(endpoint)).data

const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data

for (const reporter of result) {
if (!reporter.contract) {
printResult.push({ ...reporter })
continue
}
const url = new URL(AGGREGATOR_ENDPOINT)
url.searchParams.append('address', reporter.contract[0])
const aggregatorResult = (await axios.get(url.toString())).data
if (aggregatorResult && aggregatorResult.name) {
reporter.name = aggregatorResult.name

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.contract[0]
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
}

console.log(result)
console.log(printResult)
return result
} catch (e) {
console.error('Delegator Reporter was not listed. Reason:')
Expand Down
19 changes: 13 additions & 6 deletions cli/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,27 @@ export function listHandler(print?: boolean) {

try {
const result = (await axios.get(LISTENER_ENDPOINT, { data: { chain, service } }))?.data
const printResult: any[] = []
const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
if (print) {
for (const listener of result) {
if (listener.service != 'DATA_FEED') {
printResult.push({ ...listener })
continue
}
const url = new URL(AGGREGATOR_ENDPOINT)
url.searchParams.append('address', listener.address)
const aggregatorResult = (await axios.get(url.toString())).data
if (aggregatorResult && aggregatorResult.name) {
listener.name = aggregatorResult.name

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === listener.address
)
if (aggregator) {
printResult.push({ ...listener, name: aggregator.name })
} else {
printResult.push({ ...listener })
}
}

console.dir(result, { depth: null })
console.dir(printResult, { depth: null })
}
return result
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function insertHandler() {
return response
} catch (e) {
console.error('Proxy was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
console.error(e?.response?.data)
return e?.response?.data
}
}
return wrapper
Expand Down
20 changes: 14 additions & 6 deletions cli/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,28 @@ export function listHandler(print?: boolean) {

try {
const result = (await axios.get(REPORTER_ENDPOINT, { data: { chain, service } }))?.data

const printResult: any[] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution much more than before! 🚀

const aggregatorUrl = new URL(AGGREGATOR_ENDPOINT)
const aggregatorResult = (await axios.get(aggregatorUrl.toString())).data
if (print) {
for (const reporter of result) {
if (reporter.service != 'DATA_FEED') {
printResult.push({ ...reporter })
continue
}
const url = new URL(AGGREGATOR_ENDPOINT)
url.searchParams.append('address', reporter.oracleAddress)
const aggregatorResult = (await axios.get(url.toString())).data
if (aggregatorResult && aggregatorResult.name) {
reporter.name = aggregatorResult.name

const aggregator = aggregatorResult.find(
(aggregator) => aggregator.address === reporter.oracleAddress
)
if (aggregator) {
printResult.push({ ...reporter, name: aggregator.name })
} else {
printResult.push({ ...reporter })
}
}

console.dir(result, { depth: null })
console.dir(printResult, { depth: null })
}
return result
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function insertHandler() {
return response
} catch (e) {
console.error('Service was not inserted. Reason:')
console.error(e?.response?.data?.message)
return e?.response?.data?.message
console.error(e?.response?.data)
return e?.response?.data
}
}
return wrapper
Expand Down
7 changes: 7 additions & 0 deletions cli/src/vrf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export function listHandler(print?: boolean) {
if (!(await isOraklNetworkApiHealthy())) return

try {
if (!chain) {
const result = (await axios.get(VRF_ENDPOINT)).data
nick-bisonai marked this conversation as resolved.
Show resolved Hide resolved
if (print) {
console.dir(result, { depth: null })
}
return result
}
const result = (await axios.get(VRF_ENDPOINT, { data: { chain } }))?.data
if (print) {
console.dir(result, { depth: null })
Expand Down
4 changes: 3 additions & 1 deletion cli/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe('CLI Adapter', function () {
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')
expect(msg).toEqual(
'ERROR: duplicate key value violates unique constraint "adapters_adapter_hash_key" (SQLSTATE 23505)'
)
})

test('Should delete adapter based on id', async function () {
Expand Down
4 changes: 3 additions & 1 deletion cli/test/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe('CLI Aggregator', function () {
await insertHandler()({ data: AGGREGATOR_1, chain: 'localhost' })

const msg = await insertHandler()({ data: AGGREGATOR_1, chain: 'localhost' })
expect(msg).toEqual('Unique constraint failed on the address')
expect(msg).toEqual(
'ERROR: duplicate key value violates unique constraint "aggregators_address_key" (SQLSTATE 23505)'
)
})

test('Should delete aggregator based on id', async function () {
Expand Down
4 changes: 3 additions & 1 deletion cli/test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ describe('CLI Chain', function () {
test('Should not allow to insert the same chain more than once', async function () {
await insertHandler()({ name: 'ethereum' })
const msg = await insertHandler()({ name: 'ethereum' })
expect(msg).toEqual('Internal server error')
expect(msg).toEqual(
'ERROR: duplicate key value violates unique constraint "chains_name_key" (SQLSTATE 23505)'
)
})

test('Should delete chain based on id', async function () {
Expand Down
12 changes: 6 additions & 6 deletions cli/test/datafeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ describe('CLI datafeed', function () {
const afterReporterList = await reporterListHandler()({})
const afterFunctionList = await functionListHandler()()

for (const reporter of afterReporterList) {
await reporterRemoveHandler()({ id: reporter.id })
}
for (const listener of afterListenerList) {
await listenerRemoveHandler()({ id: listener.id })
}
for (const _function of afterFunctionList) {
await functionRemoveHandler()({ id: Number(_function.id) })
}
Expand All @@ -88,12 +94,6 @@ describe('CLI datafeed', function () {
for (const contract of afterContractList) {
await contractRemoveHandler()({ id: contract.id })
}
for (const listener of afterListenerList) {
await listenerRemoveHandler()({ id: listener.id })
}
for (const reporter of afterReporterList) {
await reporterRemoveHandler()({ id: reporter.id })
}
})

test('datafeed bulk insert with default values', async function () {
Expand Down
12 changes: 6 additions & 6 deletions cli/test/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const ADAPTER_0 = {
active: true,
name: 'X-Y',
decimals: 8,
adapterHash: '0x020e150749af3bffaec9ae337da0b9b00c3cfe0b46b854a8e2f5922f6ba2c5db',
adapterHash: '0x78514506aa9d275a66ad8c2480ca60769ba2c597dcd28742e80c50bae56f59ca',
feeds: [
{
name: 'data-X-Y',
Expand All @@ -24,7 +24,7 @@ export const ADAPTER_1 = {
active: true,
name: 'Z-X',
decimals: 8,
adapterHash: '0x12da2f5119ba624ed025303b424d637349c0d120d02bd66a9cfff57e98463a81',
adapterHash: '0xfdcd2236964e2d7b7e308ff3f0631e4a0e12df3c1f6eae896279c5c10d4a90c7',
feeds: [
{
name: 'data-Z-X',
Expand All @@ -44,22 +44,22 @@ export const ADAPTER_1 = {

export const AGGREGATOR_0 = {
name: 'X-Y',
aggregatorHash: '0x5bcc6c18d584dc54a666f9212229226f02f65b8dcda3ed72836b6c901f2d18e1',
aggregatorHash: '0xf49b12c34c575369168e0ca822653186546343f7abcbd6ae6fc6c8325bec1f52',
address: '0x0000000000000000000000000000000000000000',
heartbeat: 15000,
threshold: 0.05,
absoluteThreshold: 0.1,
adapterHash: '0x020e150749af3bffaec9ae337da0b9b00c3cfe0b46b854a8e2f5922f6ba2c5db'
adapterHash: '0x78514506aa9d275a66ad8c2480ca60769ba2c597dcd28742e80c50bae56f59ca'
}

export const AGGREGATOR_1 = {
name: 'Z-X',
aggregatorHash: '0x11ca65b539221125a64b38653f65dbbf961ed2ea16bcaf54408a5d2ebdc13a0b',
aggregatorHash: '0x3cd7a87af54adcced76d090d975212f0974fd531b1c982b10db4ca22323da30b',
address: '0x0000000000000000000000000000000000000001',
heartbeat: 15000,
threshold: 0.05,
absoluteThreshold: 0.1,
adapterHash: '0x12da2f5119ba624ed025303b424d637349c0d120d02bd66a9cfff57e98463a81'
adapterHash: '0xfdcd2236964e2d7b7e308ff3f0631e4a0e12df3c1f6eae896279c5c10d4a90c7'
}

export const VRF_0 = {
Expand Down
4 changes: 3 additions & 1 deletion cli/test/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('CLI Proxy', function () {
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')
expect(msg).toEqual(
'ERROR: duplicate key value violates unique constraint "proxies_protocol_host_port_key" (SQLSTATE 23505)'
)
})

test('Should delete proxy based on id', async function () {
Expand Down
4 changes: 3 additions & 1 deletion cli/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ describe('CLI Service', function () {
test('Should not allow to insert the same service more than once', async function () {
await insertHandler()({ name: 'Automation' })
const msg = await insertHandler()({ name: 'Automation' })
expect(msg).toEqual('Internal server error')
expect(msg).toEqual(
'ERROR: duplicate key value violates unique constraint "services_name_key" (SQLSTATE 23505)'
)
})

test('Should delete service based on id', async function () {
Expand Down
5 changes: 5 additions & 0 deletions go-api/migrations/000001_initialize_tables.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ CREATE TABLE IF NOT EXISTS "adapters" (
adapter_id BIGSERIAL NOT NULL,
decimals INTEGER NOT NULL,
name TEXT NOT NULL,
CONSTRAINT "adapters_adapter_hash_key" UNIQUE ("adapter_hash"),
CONSTRAINT "adapters_pkey" PRIMARY KEY ("adapter_id")
);

CREATE TABLE IF NOT EXISTS "chains" (
chain_id BIGSERIAL NOT NULL,
name TEXT NOT NULL,
CONSTRAINT "chains_name_key" UNIQUE ("name"),
CONSTRAINT "chains_pkey" PRIMARY KEY ("chain_id")
);

CREATE TABLE IF NOT EXISTS "services" (
name TEXT NOT NULL,
service_id BIGSERIAL NOT NULL,
CONSTRAINT "services_name_key" UNIQUE ("name"),
CONSTRAINT "services_pkey" PRIMARY KEY ("service_id")
);

Expand All @@ -30,6 +33,7 @@ CREATE TABLE IF NOT EXISTS "aggregators" (
heartbeat INTEGER NOT NULL,
name TEXT NOT NULL,
threshold DOUBLE PRECISION NOT NULL,
CONSTRAINT "aggregators_address_key" UNIQUE ("address"),
CONSTRAINT "aggregators_adapter_id_fkey" FOREIGN KEY ("adapter_id") REFERENCES "public"."adapters" ("adapter_id"),
CONSTRAINT "aggregators_chain_id_fkey" FOREIGN KEY ("chain_id") REFERENCES "public"."chains" ("chain_id"),
CONSTRAINT "aggregators_pkey" PRIMARY KEY ("aggregator_id")
Expand Down Expand Up @@ -91,6 +95,7 @@ CREATE TABLE IF NOT EXISTS "proxies" (
location TEXT,
port INTEGER NOT NULL,
protocol TEXT NOT NULL,
CONSTRAINT "proxies_protocol_host_port_key" UNIQUE ("protocol", "host", "port"),
CONSTRAINT "proxies_pkey" PRIMARY KEY ("id")
);

Expand Down
Loading