diff --git a/packages/core/src/__integrationtests__/Attestation.spec.ts b/packages/core/src/__integrationtests__/Attestation.spec.ts index 000c9864aa..7591bc175c 100644 --- a/packages/core/src/__integrationtests__/Attestation.spec.ts +++ b/packages/core/src/__integrationtests__/Attestation.spec.ts @@ -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' @@ -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') }) @@ -357,5 +354,5 @@ describe('When there is an attester, claimer and ctype drivers license', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/AttestationPE.spec.ts b/packages/core/src/__integrationtests__/AttestationPE.spec.ts index 4d4a342b5b..a3f5c5e2e4 100644 --- a/packages/core/src/__integrationtests__/AttestationPE.spec.ts +++ b/packages/core/src/__integrationtests__/AttestationPE.spec.ts @@ -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', () => { @@ -315,5 +313,5 @@ describe('Privacy enhanced claim, attestation, verification process', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/Balance.spec.ts b/packages/core/src/__integrationtests__/Balance.spec.ts index 4c69042afc..652c332858 100644 --- a/packages/core/src/__integrationtests__/Balance.spec.ts +++ b/packages/core/src/__integrationtests__/Balance.spec.ts @@ -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, @@ -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', () => { @@ -182,5 +179,5 @@ describe('When there are haves and have-nots', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/ChainConnectivity.spec.ts b/packages/core/src/__integrationtests__/ChainConnectivity.spec.ts index bc5a4db12c..f6814e3432 100644 --- a/packages/core/src/__integrationtests__/ChainConnectivity.spec.ts +++ b/packages/core/src/__integrationtests__/ChainConnectivity.spec.ts @@ -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() @@ -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) @@ -42,5 +42,5 @@ describe('Blockchain', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/Ctypes.spec.ts b/packages/core/src/__integrationtests__/Ctypes.spec.ts index 37afdb101d..a4e2e9ccb3 100644 --- a/packages/core/src/__integrationtests__/Ctypes.spec.ts +++ b/packages/core/src/__integrationtests__/Ctypes.spec.ts @@ -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', () => { @@ -123,5 +120,5 @@ describe('When there is an CtypeCreator and a verifier', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/Delegation.spec.ts b/packages/core/src/__integrationtests__/Delegation.spec.ts index 78b6164597..19a24ef4d4 100644 --- a/packages/core/src/__integrationtests__/Delegation.spec.ts +++ b/packages/core/src/__integrationtests__/Delegation.spec.ts @@ -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 { @@ -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', () => { @@ -197,5 +194,5 @@ describe('handling queries to data not on chain', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/Did.spec.ts b/packages/core/src/__integrationtests__/Did.spec.ts index 18068f1178..7b740a55ae 100644 --- a/packages/core/src/__integrationtests__/Did.spec.ts +++ b/packages/core/src/__integrationtests__/Did.spec.ts @@ -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', () => { @@ -35,5 +32,5 @@ describe('querying DIDs that do not exist', () => { }) afterAll(() => { - if (typeof blockchain !== 'undefined') blockchain.api.disconnect() + disconnect() }) diff --git a/packages/core/src/__integrationtests__/ErrorHandler.spec.ts b/packages/core/src/__integrationtests__/ErrorHandler.spec.ts index 1bbf670686..3bea81740d 100644 --- a/packages/core/src/__integrationtests__/ErrorHandler.spec.ts +++ b/packages/core/src/__integrationtests__/ErrorHandler.spec.ts @@ -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') }) @@ -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() }) diff --git a/packages/core/src/blockchain/Blockchain.ts b/packages/core/src/blockchain/Blockchain.ts index 4215192a2a..a973f158d1 100644 --- a/packages/core/src/blockchain/Blockchain.ts +++ b/packages/core/src/blockchain/Blockchain.ts @@ -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' @@ -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 + ) this.accountNonces = new Map() }