import { objects } from '@liskhq/lisk-utils' ; import { testCases as objectsTestCases } from '../fixtures/objects_encodings.json' ; import { codec } from '../src/codec' ; describe ( 'addSchema' , ( ) => { const objectFixtureInput = objectsTestCases [ 0 ] . input ; it ( 'should add schema and keep it in cache' , ( ) => { const object = { ... objectFixtureInput . object , balance : BigInt ( ( objectFixtureInput . object . balance as unknown ) as string ) , address : Buffer . from ( ( objectFixtureInput . object . address as unknown ) as string , 'hex' ) , } ; codec . encode ( objectFixtureInput . schema , object ) ; expect ( ( codec as any ) . _compileSchemas . object11 ) . toMatchSnapshot ( ) ; } ) ; it ( 'should throw if schema does not have fieldNumber in properties at root level' , ( ) => { const { schema } = objectFixtureInput ; const customSchema = objects . cloneDeep ( schema ) ; delete ( customSchema as any ) . properties . asset . fieldNumber ; expect ( ( ) => codec . addSchema ( customSchema ) ) . toThrow ( 'Invalid schema. Missing "fieldNumber" in properties' ) ; } ) ; it ( 'should throw if schema does not have fieldNumber in properties at nested level 1' , ( ) => { const { schema } = objectFixtureInput ; const customSchema = objects . cloneDeep ( schema ) ; delete ( customSchema as any ) . properties . asset . properties . fooBar . fieldNumber ; expect ( ( ) => codec . addSchema ( customSchema ) ) . toThrow ( 'Invalid schema. Missing "fieldNumber" in properties' ) ; } ) ; it ( 'should throw if schema does not have fieldNumber in properties at nested level 2' , ( ) => { const { schema } = objectFixtureInput ; const customSchema = objects . cloneDeep ( schema ) ; delete ( customSchema as any ) . properties . asset . properties . fooBar . properties . foo . fieldNumber ; expect ( ( ) => codec . addSchema ( customSchema ) ) . toThrow ( 'Invalid schema. Missing "fieldNumber" in properties' ) ; } ) ; } ) ;