Skip to content

Commit

Permalink
fix(api-cardano-db-hasura): Properly model and relate StakePoolRetire…
Browse files Browse the repository at this point in the history
…ments

- Adds missing relationship to the StakePool model
- inEffectFrom is an epoch number in the future, `retiredInEpoch` links to
the Epoch model for historical benefit
  • Loading branch information
rhyslbw committed Sep 7, 2020
1 parent 1a003a2 commit a5fef40
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@
name: pool_relay
column_mapping:
id: update_id
- name: retirements
using:
manual_configuration:
remote_table:
schema: public
name: pool_retire
column_mapping:
id: update_id
select_permissions:
- role: cardano-graphql
permission:
Expand Down Expand Up @@ -513,6 +521,10 @@
- table:
schema: public
name: pool_retire
configuration:
custom_root_fields: {}
custom_column_names:
retiring_epoch: inEffectFrom
object_relationships:
- name: announcedIn
using:
Expand All @@ -522,11 +534,27 @@
name: Transaction
column_mapping:
announced_tx_id: id
- name: inEffectFrom
- name: retiredInEpoch
using:
manual_configuration:
remote_table:
schema: public
name: Epoch
column_mapping:
retiring_epoch: number
- name: stakePool
using:
manual_configuration:
remote_table:
schema: public
name: StakePool
column_mapping:
update_id: id
select_permissions:
- role: cardano-graphql
permission:
columns:
- retiring_epoch
filter: {}
limit: 100
allow_aggregations: true
47 changes: 25 additions & 22 deletions packages/api-cardano-db-hasura/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ input Relay_bool_exp {
dnsSrvName: text_comparison_exp
}

type StakeDeregistration {
address: String!
transaction: Transaction!
}

type SlotLeader {
description: String!
hash: Hash32HexString!
Expand All @@ -215,16 +220,13 @@ type StakePool {
owners: [StakePoolOwner!]!
pledge: String!
relays: [Relay]
retirement: StakePoolRetirement
retirements: [StakePoolRetirement]
rewardAddress: String!
updatedIn: Transaction!
url: URL
withdrawals: [Withdrawal]
}

input StakePoolOwner_bool_exp {
hash: Hash32HexString_comparison_exp
}

input StakePool_order_by {
fixedCost: order_by
Expand All @@ -246,7 +248,7 @@ input StakePool_bool_exp {
pledge: text_comparison_exp
registrationTransaction: Transaction_bool_exp
relays: Relay_bool_exp
retirement: Relay_bool_exp
retirements: StakePoolRetirement_bool_exp
rewardAddress: text_comparison_exp
url: text_comparison_exp
withdrawals: Withdrawal_bool_exp
Expand Down Expand Up @@ -288,11 +290,26 @@ type StakePool_sum_fields {
pledge: String
}

type StakeDeregistration {
address: String!
transaction: Transaction!
input StakePoolOwner_bool_exp {
hash: Hash32HexString_comparison_exp
}

type StakePoolRetirement {
announcedIn: Transaction
inEffectFrom: Int!
retiredInEpoch: Epoch
}

input StakePoolRetirement_bool_exp {
announcedIn: Transaction_bool_exp
inEffectFrom: Epoch_bool_exp
}

type StakePoolOwner {
hash: Hash32HexString!
}


type StakeRegistration {
address: String!
transaction: Transaction!
Expand Down Expand Up @@ -339,20 +356,6 @@ type StakeRegistration_sum_fields {
transaction: Transaction_sum_fields
}

type StakePoolRetirement {
announcedIn: Transaction!
inEffectFrom: Epoch!
}

input StakePoolRetirement_bool_exp {
announcedIn: Transaction_bool_exp
inEffectFrom: Epoch_bool_exp
}

type StakePoolOwner {
hash: Hash32HexString!
}

type Transaction {
block: Block
blockIndex: Int!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
query stakePoolsSummary (
$where: StakePool_bool_exp
) {
stakePools_aggregate (where: $where){
aggregate {
count
avg {
fixedCost
margin
pledge
}
max {
fixedCost
margin
pledge
}
sum {
fixedCost
margin
pledge
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
query allStakePoolFields (
$limit: Int!
$where: StakePool_bool_exp
) {
stakePools (limit: $limit, where: $where) {
fixedCost
hash
margin
metadataHash
owners {
hash
}
pledge
relays {
ipv4
ipv6
dnsName
dnsSrvName
}
retirements {
announcedIn {
hash
}
inEffectFrom
}
rewardAddress
updatedIn {
hash
}
url
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,6 @@ query shelleyEraQueries {
}
}
}
stakePools (limit:10) {
fixedCost
hash
margin
metadataHash
owners {
hash
}
pledge
relays {
ipv4
ipv6
dnsName
dnsSrvName
}
retirement {
announcedIn {
hash
}
inEffectFrom {
number
}
}
rewardAddress
updatedIn {
hash
}
url
withdrawals {
address
amount
transaction {
hash
}
}
}
stakePools_aggregate {
aggregate {
count
avg {
margin
}
max {
margin
}
sum {
margin
}
}
}
stakeRegistrations (limit:10) {
address
transaction {
Expand Down
8 changes: 4 additions & 4 deletions packages/api-cardano-db-hasura/test/shelley.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ describe('Shelley era queries', () => {
}, 15000)

it('will not throw errors during the Byron era', async () => {
const result = await client.query({
await client.query({
query: await loadQueryNode('shelleyEraQueries')
})
console.log(result)
// console.log(result)
// expect(result.data).toMatchSnapshot()
})
it('Shelley era smoke test', async () => {
const result = await client.query({
await client.query({
query: await loadQueryNode('shelleyEraQueries')
})
console.log(result)
// console.log(result)
// expect(result.data).toMatchSnapshot()
})
})
67 changes: 67 additions & 0 deletions packages/api-cardano-db-hasura/test/stakePool.query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable camelcase */
import path from 'path'

import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { buildClient } from './util'

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'stake_pools'), name)
}

describe('stakePools', () => {
let client: TestClient
beforeAll(async () => {
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442)
}, 15000)

it('can return details on active stake pools', async () => {
const result = await client.query({
query: await loadQueryNode('allStakePoolFields'),
variables: { limit: 5 }
})
const { stakePools } = result.data
expect(stakePools.length).toBe(5)
expect(stakePools[0].fixedCost).toBeDefined()
expect(stakePools[0].hash).toBeDefined()
expect(stakePools[0].margin).toBeDefined()
expect(stakePools[0].metadataHash).toBeDefined()
expect(stakePools[0].owners).toBeDefined()
expect(stakePools[0].pledge).toBeDefined()
expect(stakePools[0].relays).toBeDefined()
expect(stakePools[0].retirements).toBeDefined()
expect(stakePools[0].rewardAddress.slice(0, 6)).toBe('stake1')
expect(stakePools[0].updatedIn.hash).toBeDefined()
expect(stakePools[0].url).toBeDefined()
})

it('can return aggregated data on all stake pools', async () => {
const result = await client.query({
query: await loadQueryNode('aggregateStakePoolSummary')
})
const { stakePools_aggregate } = result.data
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(900)
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeLessThan(1000)
})

it('can return aggregated data on active stake pools', async () => {
const result = await client.query({
query: await loadQueryNode('aggregateStakePoolSummary'),
variables: { where: { _not: { retirements: {} } } }
})
const { stakePools_aggregate } = result.data
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(800)
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeLessThan(1000)
})

it('can return aggregated data on retiring stake pools', async () => {
const result = await client.query({
query: await loadQueryNode('aggregateStakePoolSummary'),
variables: { where: { retirements: {} } }
})
const { stakePools_aggregate } = result.data
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeGreaterThan(0)
expect(parseInt(stakePools_aggregate.aggregate.count)).toBeLessThan(100)
})
})

0 comments on commit a5fef40

Please sign in to comment.