import fs from 'fs' ; import path from 'path' ; import { MongoClient } from 'mongodb' ; import Web3 from 'web3' ; import { EthereumLedger } from '@sidetree/ethereum' ; import { MockCas } from '@sidetree/cas' ; import Element from '../Element' ; import config from '../configs/element-ganache-config.json' ; const writeFixture = ( filename , object ) => { fs . writeFileSync ( path . resolve ( __dirname , '../__fixtures__/' , filename ) , JSON . stringify ( object , null , 2 ) ) ; } ; const getTestLedger = async ( ) => { const web3 = new Web3 ( config . ethereumRpcUrl ) ; const ledger = new EthereumLedger ( web3 , ( config as any ) . elementAnchorContract ) ; return ledger ; } ; const getTestCas = async ( ) => { const cas = new MockCas ( ) ; await cas . initialize ( ) ; return cas ; } ; const getTestElement = async ( ) => { const ledger = await getTestLedger ( ) ; const cas = await getTestCas ( ) ; const element = new Element ( config as any , config . versions , cas , ledger ) ; await element . initialize ( ) ; return element ; } ; const clearCollection = async ( collectionName ) => { const client = await MongoClient . connect ( config . mongoDbConnectionString , { useUnifiedTopology : true , useNewUrlParser : true } as any ) ; const db = await client . db ( config . databaseName ) ; const collection = db . collection ( collectionName ) ; await collection . deleteMany ( { } ) ; await client . close ( ) ; } ; export { getTestLedger , getTestCas , getTestElement , writeFixture , clearCollection , } ;