'use strict' ; import * as chai from 'chai' ; import * as sinonChai from 'sinon-chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as fs from 'fs-extra' ; import * as path from 'path' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; module . exports = function ( ) : any { /**
     * Given
     */ this . Given ( /^a ?(.+) smart contract for (.+) assets with the name (.+) and version (.\S+) ?(.+)?$/ , this . timeout , async ( language , assetType , name , version , _ignore ) => { this . contractLanguage = language ; if ( assetType === 'null' ) { assetType = null ; } this . contractAssetType = assetType ; this . namespace = `${ this . contractAssetType }Contract` ; this . contractDefinitionName = name ; this . contractDefinitionVersion = version ; } ) ; this . Given ( /a smart contract definition with the name (.+) and version (.\S+)/ , this . timeout , async ( name , version ) => { this . contractDefinitionName = name ; this . contractDefinitionVersion = version ; } ) ; this . Given ( /the contract hasn't been created already/ , this . timeout , async ( ) => { const contractDirectory = this . smartContractHelper . getContractDirectory ( this . contractDefinitionName , this . contractLanguage ) ; const exists = await fs . pathExists ( contractDirectory ) ; if ( exists ) { await fs . remove ( contractDirectory ) ; } } ) ; this . Given ( /the contract has been created/ , this . timeout , async ( ) => { const contractDirectory = this . smartContractHelper . getContractDirectory ( this . contractDefinitionName , this . contractLanguage , this . capability ) ; const exists = await fs . pathExists ( contractDirectory ) ; if ( ! exists ) { this . contractDirectory = await this . smartContractHelper . createSmartContract ( this . contractLanguage , this . contractAssetType , this . contractDefinitionName , this . capability ) ; } else { this . contractDirectory = contractDirectory ; } } ) ; this . Given ( "the contract version has been updated to '{string}'" , this . timeout , async ( version ) => { this . contractDefinitionVersion = version ; if ( this . contractLanguage === 'JavaScript' || this . contractLanguage === 'TypeScript' ) { const contractDirectory = this . smartContractHelper . getContractDirectory ( this . contractDefinitionName , this . contractLanguage ) ; const fileContents = await fs . readFile ( path . join ( contractDirectory , 'package.json' ) ) ; const packageObject = JSON . parse ( fileContents . toString ( ) ) ; packageObject . version = version ; const packageJsonString = JSON . stringify ( packageObject , null , 4 ) ; return fs . writeFile ( path . join ( contractDirectory , 'package.json' ) , packageJsonString , 'utf8' ) ; } } ) ; this . Given ( /the contract has been deleted/ , this . timeout , async ( ) => { const contractDirectory = this . smartContractHelper . getContractDirectory ( this . contractDefinitionName , this . contractLanguage ) ; const exists = await fs . pathExists ( contractDirectory ) ; if ( exists ) { await fs . remove ( contractDirectory ) ; } } ) ; this . Given ( /the contract has been installed and instantiated with the transaction '(.*?)' and args '(.*?)', (not )?using private data on channel '(.*?)'/ , this . timeout , async ( transaction , args , usingPrivateData , channel ) => { let privateData ; if ( usingPrivateData === 'not ' ) { privateData = false ; } else { privateData = true ; } await this . smartContractHelper . instantiateSmartContract ( this . contractDefinitionName , this . contractDefinitionVersion , transaction , args , privateData , channel ) ; } ) ; /**
     * When
     */ this . When ( /I create the contract/ , this . timeout , async ( ) => { this . contractDirectory = await this . smartContractHelper . createSmartContract ( this . contractLanguage , this . contractAssetType , this . contractDefinitionName ) ; } ) ; this . When ( /I install and instantiate the package with the transaction '(.*?)' and args '(.*?)', (not )?using private data on channel '(.*?)'/ , this . timeout , async ( transaction , args , usingPrivateData , channel ) => { let privateData ; if ( usingPrivateData === 'not ' ) { privateData = false ; } else { privateData = true ; } await this . smartContractHelper . instantiateSmartContract ( this . contractDefinitionName , this . contractDefinitionVersion , transaction , args , privateData , channel ) ; } ) ; this . When ( /I upgrade the installed package with the transaction '(.*?)' and args '(.*?)', (not )?using private data on channel '(.*?)'/ , this . timeout , async ( transaction , args , usingPrivateData , channel ) => { let privateData ; if ( usingPrivateData === 'not ' ) { privateData = false ; } else { privateData = true ; } await this . smartContractHelper . upgradeSmartContract ( this . contractDefinitionName , this . contractDefinitionVersion , transaction , args , privateData , channel ) ; } ) ; /**
     * Then
     */ this . Then ( 'a new contract directory should exist' , this . timeout , async ( ) => { const exists = await fs . pathExists ( this . contractDirectory ) ; exists . should . equal ( true ) ; } ) ; } ;