import * as ABIDecoder from "abi-decoder" ; import * as Web3 from "web3" ; import { expect } from "chai" ; import { REVERT_ERROR } from "../../../../test_utils/constants" ; import { RegisterTermStartScenario } from "../scenarios" ; import { LogSimpleInterestTermStart } from "../../../../logs/simple_interest_terms_contract" ; import { ERC721CollateralLocked } from "../../../../logs/collateralized_contract" ; import { ERC721CollateralizedSimpleInterestTermsContractRunner as Runner , } from "./erc_721_collateralized_simple_interest_terms_contract" ; export class RegisterTermStartRunner extends Runner { constructor ( web3 ) { super ( web3 ) ; } public testScenario ( scenario ) { let txHash ; describe ( scenario . description , ( ) => { before ( async ( ) => { await this . setupDebtOrder ( scenario ) ; if ( ! scenario . permissionToCollateralize ) { await this . contracts . erc721CollateralizerContract . revokeCollateralizeAuthorization . sendTransactionAsync ( this . contracts . erc721CollateralizedSimpleInterestTermsContract . address , { from : this . accounts . CONTRACT_OWNER } ) ; } if ( scenario . invokedByDebtKernel && ! scenario . reverts ) { txHash = await this . fillDebtOrder ( ) ; } ABIDecoder . addABI ( this . contracts . erc721CollateralizedSimpleInterestTermsContract . abi ) ; ABIDecoder . addABI ( this . contracts . erc721CollateralizerContract . abi ) ; } ) ; after ( async ( ) => { if ( ! scenario . permissionToCollateralize ) { await this . contracts . erc721CollateralizerContract . addAuthorizedCollateralizeAgent . sendTransactionAsync ( this . contracts . erc721CollateralizedSimpleInterestTermsContract . address , { from : this . accounts . CONTRACT_OWNER } ) ; } ABIDecoder . removeABI ( this . contracts . erc721CollateralizedSimpleInterestTermsContract . abi ) ; ABIDecoder . removeABI ( this . contracts . erc721CollateralizerContract . abi ) ; } ) ; if ( scenario . succeeds ) { it ( "should emit a LogSimpleInterestTermStart event" , async ( ) => { const { erc721CollateralizedSimpleInterestTermsContract } = this . contracts ; const debtOrder = this . debtOrder ; const expectedLog = LogSimpleInterestTermStart ( erc721CollateralizedSimpleInterestTermsContract . 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 ) ; } ) ; it ( "should emit a CollateralLocked event" , async ( ) => { const { erc721CollateralizerContract , erc721TokenContract , cryptoKittyContract } = this . contracts ; const contractAddress = scenario . isCryptoKitty ? cryptoKittyContract . address : erc721TokenContract . address ; const expectedLog = ERC721CollateralLocked ( erc721CollateralizerContract . address , this . agreementId , contractAddress , scenario . collateralId ) ; const returnedLog = await this . getLogs ( txHash , "CollateralLocked" ) ; expect ( expectedLog ) . to . deep . equal ( returnedLog ) ; } ) ; } 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 { erc721CollateralizedSimpleInterestTermsContract } = this . contracts ; return erc721CollateralizedSimpleInterestTermsContract . registerTermStart . sendTransactionAsync ( this . agreementId , DEBTOR_1 , { from : UNDERWRITER } ) ; } }