-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api-cardano-db-hasura): Properly model and relate StakePoolRetire…
…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
Showing
7 changed files
with
181 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...s/api-cardano-db-hasura/src/example_queries/stake_pools/aggregateStakePoolSummary.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/api-cardano-db-hasura/src/example_queries/stake_pools/allStakePoolFields.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/api-cardano-db-hasura/test/stakePool.query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |