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

feat: gql staking #347

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
184 changes: 65 additions & 119 deletions src/gql/heart-monitor/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import {
QueryStatsArgs,
GQLStatsFields,
communityPoolQueryString,
delegationsQueryString,
QueryWasmArgs,
GqlWasmFields,
GqlOutCommunityPool,
GqlOutDelegations,
checkFields,
cleanResponse,
defaultDelegations,
defaultDistributionCommission,
defaultGovDeposit,
defaultGovProposal,
Expand All @@ -36,19 +33,16 @@ import {
defaultPerpPosition,
defaultPerpPositionChanges,
defaultPool,
defaultRedelegations,
defaultSpotLpPosition,
defaultSpotPool,
defaultSpotPoolSwap,
defaultStatsFees,
defaultToken,
defaultTotals,
defaultTvl,
defaultUnbondings,
defaultUser,
defaultUserContract,
defaultUsers,
defaultValidator,
defaultVolume,
GQLDelegation,
GQLDistributionCommission,
Expand All @@ -58,20 +52,15 @@ import {
GQLPerpMarket,
GQLPerpPosition,
GQLQueryGqlCommunityPoolArgs,
GQLQueryGqlDelegationsArgs,
GQLQueryGqlDistributionCommissionsArgs,
GQLQueryGqlMarkPriceCandlesArgs,
GQLQueryGqlRedelegationsArgs,
GQLQueryGqlSpotLpPositionsArgs,
GQLQueryGqlSpotPoolCreatedArgs,
GQLQueryGqlSpotPoolExitedArgs,
GQLQueryGqlSpotPoolJoinedArgs,
GQLQueryGqlSpotPoolSwapArgs,
GQLQueryGqlSpotPoolsArgs,
GQLQueryGqlUnbondingsArgs,
GQLQueryGqlUsersArgs,
GQLQueryGqlValidatorsArgs,
GQLRedelegation,
GQLSpotLpPosition,
GQLSpotPool,
GQLSpotPoolCreated,
Expand All @@ -83,9 +72,7 @@ import {
GQLSubscriptionGqlPerpMarketArgs,
GQLSubscriptionGqlPerpPositionsArgs,
GQLToken,
GQLUnbonding,
GQLUser,
GQLValidator,
InflationFields,
QueryInflationArgs,
defaultInflationInfo,
Expand All @@ -95,6 +82,11 @@ import {
defaultProxy,
GQLProxies,
defaultInflationReward,
QueryStakingArgs,
GQLStakingFields,
GQLValidatorOrder,
GQLStakingQueryString,
GQLStakingActionType,
} from ".."

const nibiruUrl = "testnet-1"
Expand Down Expand Up @@ -151,25 +143,6 @@ test("communityPool", async () => {
await testCommunityPool({}, defaultToken)
})

const testDelegations = async (
args: GQLQueryGqlDelegationsArgs,
fields?: GQLDelegation
) => {
const resp = await heartMonitor.delegations(args, fields)
expect(resp).toHaveProperty("delegations")

if ((resp.delegations?.length ?? 0) > 0) {
const [delegation] = resp.delegations ?? []

checkFields([delegation], ["amount", "delegator", "validator"])
}
}

test("delegations", async () => {
await testDelegations({ limit: 1 })
await testDelegations({}, defaultDelegations)
})

const testDistributionCommissions = async (
args: GQLQueryGqlDistributionCommissionsArgs,
fields?: GQLDistributionCommission
Expand Down Expand Up @@ -760,64 +733,39 @@ test("queryBatchHandler", async () => {
// TODO: Make a partial type that includes all of these
const resp = await heartMonitor.GQLQueryGqlBatchHandler<{
communityPool: GqlOutCommunityPool[]
delegations: GqlOutDelegations[]
staking: {
delegations: GQLDelegation[]
}
}>([
communityPoolQueryString({}, true),
delegationsQueryString(
GQLStakingQueryString(
{ delegations: { limit: 1 } },
{
limit: 1,
},
true
delegations: {
delegator: { address: "" },
validator: { operator_address: "" },
amount: 0,
},
}
),
])

expect(resp).toHaveProperty("communityPool")
expect(resp).toHaveProperty("delegations")
expect(resp.staking).toHaveProperty("delegations")

if ((resp.communityPool?.length ?? 0) > 0) {
const [communityPool] = resp.communityPool ?? []

checkFields([communityPool], ["amount", "denom"])
}

if ((resp.delegations?.length ?? 0) > 0) {
const [delegation] = resp.delegations ?? []
if ((resp.staking.delegations?.length ?? 0) > 0) {
const [delegation] = resp.staking.delegations ?? []

checkFields([delegation], ["amount", "delegator", "validator"])
}
})

const testRedelegations = async (
args: GQLQueryGqlRedelegationsArgs,
fields?: GQLRedelegation
) => {
const resp = await heartMonitor.redelegations(args, fields)
expect(resp).toHaveProperty("redelegations")

if ((resp.redelegations?.length ?? 0) > 0) {
const [redelegations] = resp.redelegations ?? []

checkFields(
[redelegations],
[
"delegator",
"source_validator",
"destination_validator",
"amount",
"creation_block",
"completion_time",
]
)
}
}

test("redelegations", async () => {
await testRedelegations({
limit: 1,
})
await testRedelegations({}, defaultRedelegations)
})

const testSpotLpPositions = async (
args: GQLQueryGqlSpotLpPositionsArgs,
fields?: GQLSpotLpPosition
Expand Down Expand Up @@ -1097,28 +1045,6 @@ test("wasm", async () => {
)
})

const testUnbondings = async (
args: GQLQueryGqlUnbondingsArgs,
fields?: GQLUnbonding
) => {
const resp = await heartMonitor.unbondings(args, fields)
expect(resp).toHaveProperty("unbondings")

if ((resp.unbondings?.length ?? 0) > 0) {
const [unbonding] = resp.unbondings ?? []

checkFields(
[unbonding],
["delegator", "validator", "amount", "creation_block", "completion_time"]
)
}
}

test("unbondings", async () => {
await testUnbondings({ limit: 1 })
await testUnbondings({}, defaultUnbondings)
})

const testUsers = async (args: GQLQueryGqlUsersArgs, fields?: GQLUser) => {
const resp = await heartMonitor.users(args, fields)

Expand All @@ -1136,39 +1062,59 @@ test("users", async () => {
await testUsers({}, defaultUser)
})

const testValidators = async (
args: GQLQueryGqlValidatorsArgs,
fields?: GQLValidator
const testStaking = async (
args: QueryStakingArgs,
fields: GQLStakingFields
) => {
const resp = await heartMonitor.validators(args, fields)
expect(resp).toHaveProperty("validators")
const resp = await heartMonitor.staking(args, fields)
expect(resp).toHaveProperty("staking")

if ((resp.validators?.length ?? 0) > 0) {
const [validator] = resp.validators ?? []
if (resp.staking) {
const { staking } = resp

checkFields(
[validator],
[
"commission_rates",
"commission_update_time",
"delegator_shares",
"description",
"jailed",
"min_self_delegation",
"operator_address",
"status",
"tokens",
"unbonding_block",
"unbonding_time",
]
[staking],
["delegations", "history", "redelegations", "unbondings", "validators"]
)
}
}
test("validators", async () => {
await testValidators({
limit: 1,
})
await testValidators({}, defaultValidator)

test("staking", async () => {
await testStaking(
ruslan-sh-r marked this conversation as resolved.
Show resolved Hide resolved
{
delegations: {
limit: 10,
order_desc: true,
},
history: {
limit: 10,
order_desc: true,
where: {
delegator: {
like: "nibi",
},
},
},
redelegations: {
limit: 10,
},
unbondings: {
limit: 10,
},
validators: {
limit: 10,
order_by: GQLValidatorOrder.GQLTokens,
order_desc: true,
},
},
{
delegations: { amount: 0 },
redelegations: { amount: 0 },
unbondings: { amount: 0 },
validators: { operator_address: "" },
history: { action: GQLStakingActionType.GQLUnbond, amount: 0 },
}
)
})

describe("gql cleanResponse", () => {
Expand Down
Loading
Loading