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(indexer-nibi 99% coverage): coverage #243

Merged
merged 10 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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/test-ts-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
paths: ["**.js", "**.ts", "**.tsx", "**.json"]

jobs:
test-nibijs:
test-ts-sdk:
runs-on: ubuntu-latest
env:
CHAIN_HOST: ${{ secrets.CHAIN_HOST }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The entrypoint for `nibijs` is the `Sdk` object, which is meant to mimic the roo
```js
import { newRandomWallet, WalletHD } from "@nibiruchain/nibijs"

const wallet: WalletHD = await newRandomWallet()
const wallet = await newRandomWallet()
const [{ address }] = await wallet.getAccounts()

// Save the mnemonic somewhere to re-use the account
Expand Down
3 changes: 1 addition & 2 deletions examples/01_new-wallet-and-faucet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {
useFaucet,
WalletHD,
newRandomWallet,
IncentivizedTestnet,
} from "@nibiruchain/nibijs"

const TEST_CHAIN = IncentivizedTestnet(2)

async function runExample() {
const wallet: WalletHD = await newRandomWallet()
const wallet = await newRandomWallet()
const [{ address }] = await wallet.getAccounts()

// Save the mnemonic somewhere to re-use the account
Expand Down
10 changes: 6 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = function (root = __dirname) {
"packages/nibijs/src/**/*.{js,jsx,ts,tsx}",
"!**/node_modules/**",
"!**/dist/**",
"!**/index.ts",
"!**/nibijs/src/test/helpers.ts",
],

// The directory where Jest should output its coverage files
Expand All @@ -45,10 +47,10 @@ module.exports = function (root = __dirname) {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 50,
functions: 50,
lines: 50,
statements: 50,
branches: 75,
functions: 75,
lines: 75,
statements: 75,
},
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"clean": "lerna run --parallel clean",
"commit": "cz",
"publish:all": "lerna publish from-package",
"test": "jest --verbose",
"test": "jest --verbose --detectOpenHandles",
"lint": "eslint -c './.eslintrc.js' './packages/**/*.{ts,js}'",
"lint:ci": "yarn lint . --format junit",
"lint:md": "markdownlint --ignore node_modules --ignore .git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CodegenConfig } from "@graphql-codegen/cli"

const config: CodegenConfig = {
export default {
schema: {
"indexer-nibi": {
loader: "./src/graphql-codegen/codegen-loader.js",
Expand All @@ -26,6 +26,4 @@ const config: CodegenConfig = {
},
},
},
}

export default config
} as CodegenConfig
2 changes: 1 addition & 1 deletion packages/indexer-nibi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"build": "tsc --build",
"build:watch": "tsc --build --watch",
"gql-generate": "rm -rf src/gql && graphql-code-generator --config ./src/graphql-codegen/codegen.ts",
"gql-generate": "rm -rf src/gql && graphql-code-generator --config codegen.ts",
"clean": "tsc --clean",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
43 changes: 43 additions & 0 deletions packages/indexer-nibi/src/batchHandlers/queryBatchHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { queryBatchHandler } from "./queryBatchHandler"
import { communityPoolQueryString } from "../query/communityPool"
import { delegationsQueryString } from "../query"

const checkFields = (objects: any[], fields: any[]) => {
objects.forEach((obj: any) => {
fields.forEach((field: string | any[]) => {
expect(obj).toHaveProperty(field)
})
})
}

describe("queryBatchHandler tests", () => {
test("queryBatchHandler", async () => {
const resp = await queryBatchHandler(
[
communityPoolQueryString({}, true),
delegationsQueryString(
{
limit: 1,
},
true
),
],
"https://hm-graphql.itn-3.nibiru.fi/query"
)

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

if (resp.communityPool?.length) {
const [communityPool] = resp.communityPool
const communityPoolFields = ["amount", "denom"]
checkFields([communityPool], communityPoolFields)
}

if (resp.delegations?.length) {
const [delegation] = resp.delegations
const delegationFields = ["amount", "delegator", "validator"]
checkFields([delegation], delegationFields)
}
})
})
19 changes: 0 additions & 19 deletions packages/indexer-nibi/src/enum.ts

This file was deleted.

43 changes: 8 additions & 35 deletions packages/indexer-nibi/src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,17 @@ export const gqlQuery = <T>(
properties: string,
excludeParentObject?: boolean
) => {
let queryArgList = []

if (
typedQueryArgs.where !== undefined ||
typedQueryArgs.limit !== undefined ||
typedQueryArgs.order_by !== undefined ||
typedQueryArgs.order_desc !== undefined ||
typedQueryArgs.order !== undefined ||
typedQueryArgs.orderDesc !== undefined
) {
if (typedQueryArgs.where !== undefined) {
queryArgList.push(getWhereArgArr(typedQueryArgs.where))
}

if (typedQueryArgs.limit !== undefined) {
queryArgList.push(arg("limit", typedQueryArgs.limit))
}
const queryArgList = []

if (typedQueryArgs.order_by !== undefined) {
queryArgList.push(arg("order_by", typedQueryArgs.order_by, true))
}

if (typedQueryArgs.order !== undefined) {
queryArgList.push(arg("order", typedQueryArgs.order, true))
}
if (typedQueryArgs.where !== undefined) {
queryArgList.push(getWhereArgArr(typedQueryArgs.where))
}

if (typedQueryArgs.order_desc !== undefined) {
queryArgList.push(arg("order_desc", typedQueryArgs.order_desc))
}
delete typedQueryArgs.where

if (typedQueryArgs.orderDesc !== undefined) {
queryArgList.push(arg("orderDesc", typedQueryArgs.orderDesc))
}
} else {
queryArgList = Object.keys(typedQueryArgs).map((key) =>
arg(key, typedQueryArgs[key])
)
}
Object.keys(typedQueryArgs).forEach((key) =>
queryArgList.push(arg(key, typedQueryArgs[key], true))
)

const hasQueryList = (char: string) => (queryArgList.length > 0 ? char : "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module.exports = async () => {
return buildClientSchema(data)
} catch (error) {
console.error(error)
throw error
return undefined
}
}
10 changes: 10 additions & 0 deletions packages/indexer-nibi/src/graphql-codegen/codegen-loader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GraphQLSchema } from "graphql"

const loader = require("./codegen-loader")

describe("codegen-loader tests", () => {
test("codegen-loader", async () => {
const testResult = await loader()
expect(testResult).toBeInstanceOf(GraphQLSchema)
})
})
Loading