import { createPrivateKey } from '@neo-one/client' ; import BigNumber from 'bignumber.js' ; import { getTokenInfo , handleMint } from '../utils' ; import { withContracts } from '../../one/generated/test' ; describe ( 'utils' , ( ) => { test ( 'getTokenInfo returns token info' , async ( ) => { await withContracts ( async ( { token , networkName } ) => { expect ( token ) . toBeDefined ( ) ; const toWallet = await token . client . providers . memory . keystore . addUserAccount ( { network : networkName , privateKey : createPrivateKey ( ) } ) ; const { name , symbol , amountPerNEO , totalSupply , remaining , icoStartTimeSeconds , icoDurationSeconds , balance , } = await getTokenInfo ( token , toWallet . userAccount . id . address ) ; expect ( name ) . toEqual ( 'Eon' ) ; expect ( symbol ) . toEqual ( 'EON' ) ; expect ( amountPerNEO . toNumber ( ) ) . toEqual ( 100000 ) ; expect ( totalSupply . toNumber ( ) ) . toEqual ( 0 ) ; expect ( remaining . toNumber ( ) ) . toEqual ( 10000000000 ) ; expect ( icoStartTimeSeconds ) . toBeDefined ( ) ; expect ( icoDurationSeconds . toNumber ( ) ) . toEqual ( 24 * 60 * 60 ) ; expect ( balance . toNumber ( ) ) . toEqual ( 0 ) ; } ) ; } ) ; test ( 'handleMint mints tokens' , async ( ) => { await withContracts ( async ( { developerClient , token , masterAccountID } ) => { let error ; try { await handleMint ( token , new BigNumber ( 10 ) ) ; } catch ( err ) { error = err ; } expect ( error ) . toBeDefined ( ) ; await developerClient . fastForwardOffset ( 60 * 60 ) ; const mintReceipt = await handleMint ( token , new BigNumber ( 10 ) ) ; if ( mintReceipt . result . state === 'FAULT' ) { throw new Error ( mintReceipt . result . message ) ; } expect ( mintReceipt . result . state ) . toEqual ( 'HALT' ) ; expect ( mintReceipt . result . value ) . toBeUndefined ( ) ; expect ( mintReceipt . events ) . toHaveLength ( 1 ) ; let event = mintReceipt . events [ 0 ] ; expect ( event . name ) . toEqual ( 'transfer' ) ; if ( event . name !== 'transfer' ) { throw new Error ( 'For TS' ) ; } expect ( event . parameters . from ) . toBeUndefined ( ) ; expect ( event . parameters . to ) . toEqual ( masterAccountID . address ) ; expect ( event . parameters . amount . toNumber ( ) ) . toEqual ( 1000000 ) ; await developerClient . fastForwardOffset ( 24 * 60 * 60 ) ; error = undefined ; try { await handleMint ( token , new BigNumber ( 10 ) ) ; } catch ( err ) { error = err ; } expect ( error ) . toBeDefined ( ) ; } ) ; } ) ; } ) ;