-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from input-output-hk/feature/rewards
Feature/rewards
- Loading branch information
Showing
12 changed files
with
215 additions
and
24 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
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
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
19 changes: 19 additions & 0 deletions
19
packages/api-cardano-db-hasura/src/example_queries/rewards/aggregateRewards.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,19 @@ | ||
query allRewardsAggregateFields { | ||
rewards_aggregate { | ||
aggregate { | ||
avg { | ||
amount | ||
} | ||
count | ||
max { | ||
amount | ||
} | ||
min { | ||
amount | ||
} | ||
sum { | ||
amount | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/api-cardano-db-hasura/src/example_queries/rewards/rewardsForAddress.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,15 @@ | ||
query rewardsForAddress ( | ||
$limit: Int! | ||
$where: Reward_bool_exp | ||
) { | ||
rewards (limit: $limit, where: $where) { | ||
address | ||
amount | ||
stakePool { | ||
hash | ||
} | ||
earnedIn { | ||
number | ||
} | ||
} | ||
} |
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
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,41 @@ | ||
/* 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', 'rewards'), name) | ||
} | ||
|
||
describe('rewards', () => { | ||
let client: TestClient | ||
beforeAll(async () => { | ||
client = await buildClient('http://localhost:3100', 'http://localhost:8090', 5442) | ||
}) | ||
|
||
it('can return details for rewards scoped to an address', async () => { | ||
const result = await client.query({ | ||
query: await loadQueryNode('rewardsForAddress'), | ||
variables: { limit: 5, where: { address: { _eq: 'stake1uyp6rqthh9n7y4rng75tz85t7djy7hny35fw27say5mfxygq3er9k' } } } | ||
}) | ||
const { rewards } = result.data | ||
expect(rewards.length).toBe(5) | ||
expect(rewards[0].stakePool.hash).toBeDefined() | ||
expect(rewards[0].earnedIn.number).toBeDefined() | ||
}) | ||
|
||
it('can return aggregated data on all delegations', async () => { | ||
const result = await client.query({ | ||
query: await loadQueryNode('aggregateRewards') | ||
}) | ||
const { rewards_aggregate } = result.data | ||
expect(parseInt(rewards_aggregate.aggregate.avg.amount)).toBeDefined() | ||
expect(parseInt(rewards_aggregate.aggregate.max.amount)).toBeDefined() | ||
expect(parseInt(rewards_aggregate.aggregate.min.amount)).toBeDefined() | ||
expect(parseInt(rewards_aggregate.aggregate.sum.amount)).toBeDefined() | ||
expect(parseInt(rewards_aggregate.aggregate.count)).toBeGreaterThan(30000) | ||
}) | ||
}) |
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