import * as ABIDecoder from "abi-decoder" ; import { expect } from "chai" ; import { REVERT_ERROR } from "../../../../test_utils/constants" ; import { RegisterTermStartScenario } from "../scenarios" ; import { LogSimpleInterestTermStart } from "../../../../logs/simple_interest_terms_contract" ; import { SimpleInterestTermsContractRunner } from "./simple_interest_terms_contract" ; export class RegisterTermStartRunner extends SimpleInterestTermsContractRunner { public testScenario ( scenario ) { let txHash ; describe ( scenario . description , ( ) => { before ( async ( ) => { await this . setupDebtOrder ( scenario ) ; if ( scenario . invokedByDebtKernel && ! scenario . reverts ) { txHash = await this . fillDebtOrder ( ) ; } ABIDecoder . addABI ( this . contracts . simpleInterestTermsContract . abi ) ; } ) ; after ( ( ) => { ABIDecoder . removeABI ( this . contracts . simpleInterestTermsContract . abi ) ; } ) ; if ( scenario . succeeds ) { it ( "should emit a LogSimpleInterestTermStart event" , async ( ) => { const { simpleInterestTermsContract } = this . contracts ; const debtOrder = this . debtOrder ; const expectedLog = LogSimpleInterestTermStart ( simpleInterestTermsContract . address , this . agreementId , debtOrder . getPrincipalTokenAddress ( ) , debtOrder . getPrincipalAmount ( ) , scenario . interestRateFixedPoint , scenario . amortizationUnitType , scenario . termLengthUnits ) ; const returnedLog = await this . getLogs ( txHash , "LogSimpleInterestTermStart" ) ; expect ( returnedLog ) . to . deep . equal ( expectedLog ) ; } ) ; } else { if ( scenario . reverts ) { it ( "should revert the transaction" , async ( ) => { if ( ! scenario . invokedByDebtKernel ) { expect ( this . registerTermsStart ( ) ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ; } else { expect ( this . fillDebtOrder ( ) ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ; } } ) ; } else { it ( "should not emit a LogSimpleInterestTermStart event" , async ( ) => { const returnedLog = await this . getLogs ( txHash , "LogSimpleInterestTermStart" ) ; expect ( returnedLog ) . to . be . undefined ; } ) ; } } } ) ; } private registerTermsStart ( ) { const { DEBTOR_1 , UNDERWRITER } = this . accounts ; const { simpleInterestTermsContract } = this . contracts ; return simpleInterestTermsContract . registerTermStart . sendTransactionAsync ( this . agreementId , DEBTOR_1 , { from : UNDERWRITER } ) ; } }