@@ -756,4 +756,113 @@ suite('chain', function () {
756756 } )
757757 assert . instanceOf ( compressedSuccess . getTransaction ( ) , Transaction )
758758 } )
759+
760+ test ( 'fixed size array' , function ( ) {
761+ const data = {
762+ version : 'eosio::abi/1.2' ,
763+ types : [ ] ,
764+ structs : [
765+ {
766+ name : 'basic' ,
767+ base : '' ,
768+ fields : [
769+ {
770+ name : 'input' ,
771+ type : 'int32' ,
772+ } ,
773+ ] ,
774+ } ,
775+ {
776+ name : 'array' ,
777+ base : '' ,
778+ fields : [
779+ {
780+ name : 'input' ,
781+ type : 'int32[]' ,
782+ } ,
783+ ] ,
784+ } ,
785+ {
786+ name : 'fixed' ,
787+ base : '' ,
788+ fields : [
789+ {
790+ name : 'input' ,
791+ type : 'int32[4]' ,
792+ } ,
793+ ] ,
794+ } ,
795+ ] ,
796+ actions : [
797+ {
798+ name : 'basic' ,
799+ type : 'basic' ,
800+ ricardian_contract : '' ,
801+ } ,
802+ {
803+ name : 'array' ,
804+ type : 'array' ,
805+ ricardian_contract : '' ,
806+ } ,
807+ {
808+ name : 'fixed' ,
809+ type : 'fixed' ,
810+ ricardian_contract : '' ,
811+ } ,
812+ ] ,
813+ tables : [ ] ,
814+ ricardian_clauses : [ ] ,
815+ error_messages : [ ] ,
816+ abi_extensions : [ ] ,
817+ variants : [ ] ,
818+ action_results : [
819+ {
820+ name : 'basic' ,
821+ result_type : 'int32' ,
822+ } ,
823+ {
824+ name : 'array' ,
825+ result_type : 'int32[]' ,
826+ } ,
827+ {
828+ name : 'fixed' ,
829+ result_type : 'int32[4]' ,
830+ } ,
831+ ] ,
832+ }
833+
834+ const abi = ABI . from ( data )
835+ assert . isTrue ( abi . equals ( data ) )
836+ assert . equal ( abi . structs [ 0 ] . fields [ 0 ] . type , 'int32' )
837+ assert . equal ( abi . structs [ 1 ] . fields [ 0 ] . type , 'int32[]' )
838+ assert . equal ( abi . structs [ 2 ] . fields [ 0 ] . type , 'int32[4]' )
839+ assert . equal ( abi . action_results [ 0 ] . result_type , 'int32' )
840+ assert . equal ( abi . action_results [ 1 ] . result_type , 'int32[]' )
841+ assert . equal ( abi . action_results [ 2 ] . result_type , 'int32[4]' )
842+
843+ const encoded = Serializer . encode ( { object : abi } )
844+ const decoded = Serializer . decode ( { data : encoded , type : ABI } )
845+ assert . isTrue ( decoded . equals ( data ) )
846+ assert . equal ( decoded . structs [ 0 ] . fields [ 0 ] . type , 'int32' )
847+ assert . equal ( decoded . structs [ 1 ] . fields [ 0 ] . type , 'int32[]' )
848+ assert . equal ( decoded . structs [ 2 ] . fields [ 0 ] . type , 'int32[4]' )
849+ assert . equal ( decoded . action_results [ 0 ] . result_type , 'int32' )
850+ assert . equal ( decoded . action_results [ 1 ] . result_type , 'int32[]' )
851+ assert . equal ( decoded . action_results [ 2 ] . result_type , 'int32[4]' )
852+
853+ assert . equal (
854+ '01000000' ,
855+ Serializer . encode ( { object : { input : 1 } , abi, type : 'basic' } ) . hexString
856+ )
857+
858+ assert . equal (
859+ '0401000000020000000300000004000000' ,
860+ Serializer . encode ( { object : { input : [ 1 , 2 , 3 , 4 ] } , abi, type : 'array' } ) . hexString
861+ )
862+
863+ assert . equal (
864+ '01000000020000000300000004000000' ,
865+ Serializer . encode ( { object : { input : [ 1 , 2 , 3 , 4 ] } , abi, type : 'fixed' } ) . hexString
866+ )
867+ } )
759868} )
0 commit comments