Skip to content

Commit

Permalink
fix(jellyfish-api-core): Disallow any type by default (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyi2811 authored May 17, 2022
1 parent bb99161 commit d7dc74f
Show file tree
Hide file tree
Showing 39 changed files with 133 additions and 89 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
"@typescript-eslint/no-non-null-assertion": "off",
"no-lone-blocks": "off"
}
},
{
"files": [
"**/jellyfish-api-core/__tests__/**/*.ts",
"**/jellyfish-api-core/src/**/*.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": "error"
}
}
]
}
3 changes: 2 additions & 1 deletion docs/node/CATEGORIES/05-wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Identical to getBalance to get untrusted pending balance.
```ts title="client.wallet.getUnconfirmedBalance()"
interface wallet {
getUnconfirmedBalance (): Promise<BigNumber>
}
```

## getBalances
Expand Down Expand Up @@ -338,7 +339,7 @@ List groups of addresses which have had their common ownership made public by co

```ts title="client.wallet.listAddressGroupings()"
interface wallet {
listAddressGroupings (): Promise<any[][][]>
listAddressGroupings (): Promise<string | BigNumber[][][]>
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface account {
}

interface AccountPagination {
start?: number
start?: number | string
including_start?: boolean
limit?: number
}
Expand Down Expand Up @@ -98,7 +98,7 @@ interface AccountAmount {
}

interface AccountPagination {
start?: string | number
start?: number | string
including_start?: boolean
limit?: number
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import waitForExpect from 'wait-for-expect'
import { AccountOwner, AccountResult } from '@defichain/jellyfish-api-core/dist/category/account'

const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)
Expand Down Expand Up @@ -42,7 +43,7 @@ it('should getAccount', async () => {
})

it('should getAccount with pagination start and including_start', async () => {
let accounts: any[] = []
let accounts: Array<AccountResult<AccountOwner, string>> = []
let beforeAccountCount = 0

await waitForExpect(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { Testing } from '@defichain/jellyfish-testing'
import { RpcApiError } from '@defichain/jellyfish-api-core'
import { AccountOwner, AccountResult } from '@defichain/jellyfish-api-core/dist/category/account'

describe('Account', () => {
const testing = Testing.create(new MasterNodeRegTestContainer())
Expand Down Expand Up @@ -28,7 +29,7 @@ describe('Account', () => {
})

it('should getAccountHistory with owner CScript', async () => {
const accounts: any[] = await testing.rpc.account.listAccounts()
const accounts: Array<AccountResult<AccountOwner, string>> = await testing.rpc.account.listAccounts()

const { owner } = accounts[0]
const { hex, addresses } = owner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import waitForExpect from 'wait-for-expect'
import { DfTxType, BalanceTransferPayload } from '../../../src/category/account'
import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner } from '../../../src/category/account'

function createTokenForContainer (container: MasterNodeRegTestContainer) {
return async (address: string, symbol: string, amount: number) => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Account', () => {
})

it('should listAccountHistory with owner CScript', async () => {
const accounts: any[] = await client.account.listAccounts()
const accounts: Array<AccountResult<AccountOwner, string>> = await client.account.listAccounts()

const { owner } = accounts[0]
const { hex, addresses } = owner
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('Account', () => {
})

it('should listAccountHistory with owner CScript options block height and txn 1', async () => {
const accounts: any[] = await client.account.listAccounts()
const accounts: Array<AccountResult<AccountOwner, string>> = await client.account.listAccounts()

const { owner } = accounts[0]
const { hex, addresses } = owner
Expand All @@ -284,7 +284,7 @@ describe('Account', () => {
})

it('should listAccountHistory with owner CScript options block height and txn 0', async () => {
const accounts: any[] = await client.account.listAccounts()
const accounts: Array<AccountResult<AccountOwner, string>> = await client.account.listAccounts()

const { owner } = accounts[0]
const { hex, addresses } = owner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import waitForExpect from 'wait-for-expect'
import BigNumber from 'bignumber.js'
import { AccountOwner, AccountResult } from '@defichain/jellyfish-api-core/dist/category/account'

describe('Account', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('Account', () => {
})

it('should listAccounts with pagination start and including_start', async () => {
const accounts: any[] = await client.account.listAccounts()
const accounts: Array<AccountResult<AccountOwner, string>> = await client.account.listAccounts()

const pagination = {
start: accounts[accounts.length - 1].key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('BlockHash', () => {
expect.assertions(1)
try {
await client.blockchain.getBlockHash(10000)
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (err: any) {
expect(err.payload).toStrictEqual({
code: -8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export class ICXSetup {
async setTakerFee (fee: number): Promise<void> {
await this.container.call('setgov', [{ ICX_TAKERFEE_PER_BTC: fee }])
await this.container.generate(1)
const result: any = await this.container.call('getgov', ['ICX_TAKERFEE_PER_BTC'])
expect(result.ICX_TAKERFEE_PER_BTC as number).toStrictEqual(fee)
ICX_TAKERFEE_PER_BTC = result.ICX_TAKERFEE_PER_BTC as number
const result: { ICX_TAKERFEE_PER_BTC: number } = await this.container.call('getgov', ['ICX_TAKERFEE_PER_BTC'])
expect(result.ICX_TAKERFEE_PER_BTC).toStrictEqual(fee)
ICX_TAKERFEE_PER_BTC = result.ICX_TAKERFEE_PER_BTC
}

async closeAllOpenOffers (): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LoanMasterNodeRegTestContainer } from './loan_container'
import { Testing } from '@defichain/jellyfish-testing'
import BigNumber from 'bignumber.js'
import { VaultActive, VaultState } from '../../../src/category/loan'
import { Interest, VaultActive, VaultState } from '../../../src/category/loan'

describe('Loan getVault', () => {
const container = new LoanMasterNodeRegTestContainer()
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Loan getVault', () => {
await testing.generate(1)

// interest info.
const interestInfo: any = await testing.rpc.call('getinterest', ['default', 'TSLA'], 'bignumber')
const interestInfo: Interest[] = await testing.rpc.call('getinterest', ['default', 'TSLA'], 'bignumber')

const data = await testing.rpc.loan.getVault(vaultId) as VaultActive
const informativeRatio: BigNumber = data.collateralValue.dividedBy(data.loanValue).multipliedBy(100)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js'
import { TestingGroup } from '@defichain/jellyfish-testing'
import { GenesisKeys, MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ListAuctionHistoryDetail } from '../../../src/category/loan'
import { ListAuctionHistoryDetail, VaultLiquidation } from '../../../src/category/loan'

describe('Loan listAuctionHistory', () => {
const tGroup = TestingGroup.create(2, i => new MasterNodeRegTestContainer(GenesisKeys[i]))
Expand Down Expand Up @@ -326,8 +326,8 @@ describe('Loan listAuctionHistory', () => {
await alice.generate(1)

// When there is liquidation
const list = await alice.container.call('listauctions', [])
list.forEach((l: { state: any }) =>
const list: VaultLiquidation[] = await alice.container.call('listauctions', [])
list.forEach(l =>
expect(l.state).toStrictEqual('inLiquidation')
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Masternode', () => {
const ownerAddress = await client.wallet.getNewAddress()
await container.fundAddress(ownerAddress, 10)
const utxos = await container.call('listunspent')
const utxo = utxos.find((utxo: any) => utxo.address === ownerAddress)
const utxo = utxos.find((utxo: { address: string }) => utxo.address === ownerAddress)

const txid = await client.masternode.createMasternode(
ownerAddress, ownerAddress, { utxos: [{ txid: utxo.txid, vout: utxo.vout }] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Masternode', () => {

const govsBefore = await client.masternode.listGovs()
expect(govsBefore.length).toBeGreaterThan(0)
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govsBefore.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(Object.keys(liqSplits[0].LP_SPLITS).length).toStrictEqual(0)
Expand All @@ -33,6 +34,7 @@ describe('Masternode', () => {

const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(1)
Expand All @@ -53,6 +55,7 @@ describe('Masternode', () => {

const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GenesisKeys, MasterNodeRegTestContainer } from '@defichain/testcontaine
import { createPoolPair, createToken } from '@defichain/testing'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { Testing } from '@defichain/jellyfish-testing'
import { UTXO } from '@defichain/jellyfish-api-core/dist/category/masternode'

describe('Masternode', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -40,7 +41,7 @@ describe('Masternode', () => {

{ // before utxo spent
const utxos = await container.call('listunspent')
const found = utxos.find((u: any) => u.txid === utxo.txid && u.vout === utxo.vout)
const found = utxos.find((u: UTXO) => u.txid === utxo.txid && u.vout === utxo.vout)
expect(found).not.toStrictEqual(undefined)
}

Expand All @@ -53,7 +54,7 @@ describe('Masternode', () => {

{ // after utxo spent
const utxos = await container.call('listunspent')
const found = utxos.find((u: any) => u.txid === utxo.txid && u.vout === utxo.vout)
const found = utxos.find((u: UTXO) => u.txid === utxo.txid && u.vout === utxo.vout)
expect(found).toStrictEqual(undefined)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RpcApiError } from '@defichain/jellyfish-api-core'
import { GenesisKeys, LoanMasterNodeRegTestContainer } from '@defichain/testcontainers'
import { createPoolPair, createToken } from '@defichain/testing'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { UTXO } from '@defichain/jellyfish-api-core/dist/category/masternode'

describe('Masternode', () => {
let container!: LoanMasterNodeRegTestContainer
Expand Down Expand Up @@ -31,6 +32,7 @@ describe('Masternode', () => {
const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(1)
Expand All @@ -53,6 +55,7 @@ describe('Masternode', () => {
const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(2)
Expand All @@ -68,6 +71,7 @@ describe('Masternode', () => {
const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(1)
Expand All @@ -81,7 +85,7 @@ describe('Masternode', () => {

{ // before utxo spent
const utxos = await client.wallet.listUnspent(1, 99999, { addresses: [GenesisKeys[0].owner.address] })
const found = utxos.find((u: any) => u.txid === utxo.txid && u.vout === utxo.vout)
const found = utxos.find((u: UTXO) => u.txid === utxo.txid && u.vout === utxo.vout)
expect(found).not.toStrictEqual(undefined)
}

Expand All @@ -94,6 +98,7 @@ describe('Masternode', () => {
const govVars = await client.masternode.listGovs()
expect(govVars.length).toBeGreaterThan(0)

/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const liqSplits = govVars.find(l => l[0]?.LP_SPLITS !== undefined) as Array<Record<string, any>>
expect(liqSplits).toBeDefined()
expect(liqSplits.length).toStrictEqual(2)
Expand All @@ -104,7 +109,7 @@ describe('Masternode', () => {

{ // after utxo spent
const utxos = await client.wallet.listUnspent(1, 99999, { addresses: [GenesisKeys[0].owner.address] })
const found = utxos.find((u: any) => u.txid === utxo.txid && u.vout === utxo.vout)
const found = utxos.find((u: UTXO) => u.txid === utxo.txid && u.vout === utxo.vout)
expect(found).toStrictEqual(undefined)
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { UTXO } from '@defichain/jellyfish-api-core/dist/category/poolpair'

describe('Poolpair', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -33,7 +34,7 @@ describe('Poolpair', () => {
await container.generate(1)
}

async function createPoolPair (tokenB: string, metadata?: any): Promise<void> {
async function createPoolPair (tokenB: string): Promise<void> {
const address = await container.call('getnewaddress')
const defaultMetadata = {
tokenA: 'DFI',
Expand All @@ -42,7 +43,7 @@ describe('Poolpair', () => {
status: true,
ownerAddress: address
}
await client.poolpair.createPoolPair({ ...defaultMetadata, ...metadata })
await client.poolpair.createPoolPair({ ...defaultMetadata })
await container.generate(1)
}

Expand Down Expand Up @@ -99,7 +100,7 @@ describe('Poolpair', () => {
await container.generate(1)

const utxos = await container.call('listunspent')
const inputs = utxos.filter((utxo: any) => utxo.txid === txid).map((utxo: any) => {
const inputs = utxos.filter((utxo: UTXO) => utxo.txid === txid).map((utxo: UTXO) => {
return {
txid: utxo.txid,
vout: utxo.vout
Expand All @@ -126,7 +127,7 @@ describe('Poolpair', () => {
const tokenBAddress = await container.call('getnewaddress')

const utxos = await container.call('listunspent')
const inputs = utxos.map((utxo: any) => {
const inputs = utxos.map((utxo: UTXO) => {
return {
txid: utxo.txid,
vout: utxo.vout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Poolpair', () => {
await container.generate(1)
}

async function createPoolPair (tokenB: string, metadata?: any): Promise<void> {
async function createPoolPair (tokenB: string): Promise<void> {
const address = await container.call('getnewaddress')
const defaultMetadata = {
tokenA: 'DFI',
Expand All @@ -41,7 +41,7 @@ describe('Poolpair', () => {
status: true,
ownerAddress: address
}
await client.poolpair.createPoolPair({ ...defaultMetadata, ...metadata })
await client.poolpair.createPoolPair({ ...defaultMetadata })
await container.generate(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Poolpair', () => {
await container.generate(1)
}

async function createPoolPair (tokenB: string, metadata?: any): Promise<void> {
async function createPoolPair (tokenB: string, metadata?: { commission?: number, status?: boolean}): Promise<void> {
const address = await container.call('getnewaddress')
const defaultMetadata = {
tokenA: 'DFI',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Poolpair', () => {
await container.generate(1)
}

async function createPoolPair (tokenB: string, metadata?: any): Promise<void> {
async function createPoolPair (tokenB: string, metadata?: { isDAT?: boolean, mintable?: boolean, tradeable?: boolean}): Promise<void> {
const address = await container.call('getnewaddress')
const defaultMetadata = {
tokenA: 'DFI',
Expand Down
Loading

0 comments on commit d7dc74f

Please sign in to comment.