Skip to content

Commit

Permalink
feat: ci tests now set config and disconnect without explicit chain i…
Browse files Browse the repository at this point in the history
…nstance
  • Loading branch information
LeonfLK committed Jan 6, 2021
1 parent fc5498e commit eb44411
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 49 deletions.
9 changes: 3 additions & 6 deletions packages/core/src/__integrationtests__/Attestation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import { IAttestedClaim, IClaim } from '..'
import Attestation from '../attestation/Attestation'
import { revoke } from '../attestation/Attestation.chain'
import AttestedClaim from '../attestedclaim/AttestedClaim'
import { IBlockchainApi } from '../blockchain/Blockchain'
import {
IS_IN_BLOCK,
IS_READY,
submitTxWithReSign,
} from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import { config, disconnect } from '../kilt'
import Claim from '../claim/Claim'
import Credential from '../credential/Credential'
import CType from '../ctype/CType'
Expand All @@ -35,10 +33,9 @@ import {
WS_ADDRESS,
} from './utils'

let blockchain: IBlockchainApi | undefined
let alice: Identity
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
alice = await Identity.buildFromURI('//Alice')
})

Expand Down Expand Up @@ -357,5 +354,5 @@ describe('When there is an attester, claimer and ctype drivers license', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
10 changes: 4 additions & 6 deletions packages/core/src/__integrationtests__/AttestationPE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ import {
Accumulator,
AttesterAttestationSession,
} from '@kiltprotocol/portablegabi'
import { Claim, IBlockchainApi, IClaim, Message } from '..'
import { Claim, IClaim, Message } from '..'
import { Attester, Claimer, Verifier } from '../actor'
import { ClaimerAttestationSession } from '../actor/Claimer'
import { IS_IN_BLOCK, submitTxWithReSign } from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import { config, disconnect } from '../kilt'
import Credential from '../credential'
import Identity, { AttesterIdentity } from '../identity'
import constants from '../test/constants'
import { IRevocationHandle } from '../types/Attestation'
import { CtypeOnChain, DriversLicense, FaucetSeed, WS_ADDRESS } from './utils'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('Privacy enhanced claim, attestation, verification process', () => {
Expand Down Expand Up @@ -315,5 +313,5 @@ describe('Privacy enhanced claim, attestation, verification process', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
9 changes: 3 additions & 6 deletions packages/core/src/__integrationtests__/Balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import {
listenToBalanceChanges,
makeTransfer,
} from '../balance/Balance.chain'
import { IBlockchainApi } from '../blockchain/Blockchain'
import {
IS_IN_BLOCK,
IS_READY,
submitTxWithReSign,
} from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import { config, disconnect } from '../kilt'
import Identity from '../identity/Identity'
import {
MIN_TRANSACTION,
Expand All @@ -27,9 +25,8 @@ import {
WS_ADDRESS,
} from './utils'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('when there is a dev chain with a faucet', () => {
Expand Down Expand Up @@ -182,5 +179,5 @@ describe('When there are haves and have-nots', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
12 changes: 6 additions & 6 deletions packages/core/src/__integrationtests__/ChainConnectivity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
*/

import { Header } from '@polkadot/types/interfaces/types'
import { IBlockchainApi } from '../blockchain/Blockchain'
import { getCached } from '../blockchainApiConnection'
import { configuration } from '../config/ConfigService'
import { WS_ADDRESS } from './utils'
import { config, disconnect } from '../kilt'
import { getCached } from '../blockchainApiConnection'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('Blockchain', () => {
it('should get stats', async () => {
const blockchain = await getCached()
expect(blockchain).not.toBeUndefined()
const stats = await blockchain!.getStats()

Expand All @@ -29,6 +28,7 @@ describe('Blockchain', () => {
})

it('should listen to blocks', async (done) => {
const blockchain = await getCached()
const listener = (header: Header): void => {
// console.log(`Best block number ${header.number}`)
expect(Number(header.number)).toBeGreaterThanOrEqual(0)
Expand All @@ -42,5 +42,5 @@ describe('Blockchain', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
9 changes: 3 additions & 6 deletions packages/core/src/__integrationtests__/Ctypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
*/

import { Identity } from '..'
import { IBlockchainApi } from '../blockchain/Blockchain'
import { IS_IN_BLOCK, submitTxWithReSign } from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import CType from '../ctype/CType'
import { getOwner } from '../ctype/CType.chain'
import { ERROR_CTYPE_ALREADY_EXISTS } from '../errorhandling/ExtrinsicError'
import ICType from '../types/CType'
import { config, disconnect } from '../kilt'
import { wannabeFaucet, WS_ADDRESS } from './utils'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('When there is an CtypeCreator and a verifier', () => {
Expand Down Expand Up @@ -123,5 +120,5 @@ describe('When there is an CtypeCreator and a verifier', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
9 changes: 3 additions & 6 deletions packages/core/src/__integrationtests__/Delegation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import { cryptoWaitReady } from '@polkadot/util-crypto'
import { Identity } from '..'
import Attestation from '../attestation/Attestation'
import { IBlockchainApi } from '../blockchain/Blockchain'
import {
IS_IN_BLOCK,
IS_READY,
submitTxWithReSign,
} from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import { config, disconnect } from '../kilt'
import Claim from '../claim/Claim'
import Credential from '../credential/Credential'
import {
Expand All @@ -37,9 +35,8 @@ import {
WS_ADDRESS,
} from './utils'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('when there is an account hierarchy', () => {
Expand Down Expand Up @@ -197,5 +194,5 @@ describe('handling queries to data not on chain', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
9 changes: 3 additions & 6 deletions packages/core/src/__integrationtests__/Did.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
*/

import { Did, Identity } from '..'
import { IBlockchainApi } from '../blockchain/Blockchain'
import getCached from '../blockchainApiConnection'
import { configuration } from '../config/ConfigService'
import { queryByAddress, queryByIdentifier } from '../did/Did.chain'
import { WS_ADDRESS } from './utils'
import { config, disconnect } from '../kilt'

let blockchain: IBlockchainApi | undefined
beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
})

describe('querying DIDs that do not exist', () => {
Expand All @@ -35,5 +32,5 @@ describe('querying DIDs that do not exist', () => {
})

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
10 changes: 4 additions & 6 deletions packages/core/src/__integrationtests__/ErrorHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
*/

import BN from 'bn.js'
import { Attestation, IBlockchainApi } from '..'
import { Attestation } from '..'
import { makeTransfer } from '../balance/Balance.chain'
import { IS_IN_BLOCK, submitTxWithReSign } from '../blockchain/Blockchain.utils'
import { configuration } from '../config/ConfigService'
import getCached from '../blockchainApiConnection'
import { ERROR_CTYPE_NOT_FOUND, ERROR_UNKNOWN } from '../errorhandling'
import Identity from '../identity'
import { config, disconnect } from '../kilt'
import { WS_ADDRESS } from './utils'

let blockchain: IBlockchainApi | undefined
let alice: Identity

beforeAll(async () => {
blockchain = await getCached((configuration.host = WS_ADDRESS))
config({ address: WS_ADDRESS })
alice = await Identity.buildFromURI('//Alice')
})

Expand Down Expand Up @@ -48,5 +46,5 @@ it('records an extrinsic error when ctype does not exist', async () => {
}, 30_000)

afterAll(() => {
if (typeof blockchain !== 'undefined') blockchain.api.disconnect()
disconnect()
})
6 changes: 5 additions & 1 deletion packages/core/src/blockchain/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import * as gabi from '@kiltprotocol/portablegabi'
import { PgabiModName } from '@kiltprotocol/portablegabi/build/types/Chain'
import { ApiPromise, SubmittableResult } from '@polkadot/api'
import { SubmittableExtrinsic } from '@polkadot/api/promise/types'
import { Header } from '@polkadot/types/interfaces/types'
Expand Down Expand Up @@ -76,7 +77,10 @@ export default class Blockchain implements IBlockchainApi {

public constructor(api: ApiPromise) {
this.api = api
this.portablegabi = new gabi.Blockchain('portablegabi', this.api as any)
this.portablegabi = new gabi.Blockchain(
'portablegabi',
this.api as ApiPromise & gabi.IPortablegabiApi<PgabiModName>
)
this.accountNonces = new Map<Identity['address'], BN>()
}

Expand Down

0 comments on commit eb44411

Please sign in to comment.