import * as fixture from '../fixtures/transaction_merkle_root/transaction_merkle_root.json' ; import { MerkleTree } from '../../src/merkle_tree/merkle_tree' ; import { calculateMerkleRoot } from '../../src/merkle_tree/utils' ; describe ( 'utils' , ( ) => { describe ( 'calculateMerkleRoot' , ( ) => { describe ( 'should generate correct merkle root info' , ( ) => { for ( const test of fixture . testCases . slice ( 1 ) ) { describe ( test . description , ( ) => { const fullTree = new MerkleTree ( ) ; const partialTree = new MerkleTree ( ) ; const transactionIds = test . input . transactionIds . map ( hexString => Buffer . from ( hexString , 'hex' ) ) ; let valueToAppend ; beforeAll ( async ( ) => { await fullTree . init ( transactionIds ) ; valueToAppend = transactionIds . pop ( ) as Buffer ; await partialTree . init ( transactionIds ) ; } ) ; it ( 'should return correct merkle root, appendPath and size' , async ( ) => { const previousAppendPath = await partialTree [ '_getAppendPathHashes' ] ( ) ; const previousSize = partialTree . size ; const { root , appendPath , size } = calculateMerkleRoot ( { value : valueToAppend , appendPath : previousAppendPath , size : previousSize , } ) ; expect ( root ) . toEqual ( fullTree . root ) ; expect ( appendPath ) . toEqual ( await fullTree [ '_getAppendPathHashes' ] ( ) ) ; expect ( size ) . toEqual ( fullTree . size ) ; } ) ; } ) ; } } ) ; } ) ; } ) ;