import { ActionJSON , CallReceiptJSON , common , ConfirmedTransaction , Contract , ContractABI , ContractABIJSON , ContractGroup , ContractGroupJSON , ContractJSON , ContractManifest , ContractManifestJSON , ContractPermission , ContractPermissionDescriptor , ContractPermissionDescriptorJSON , ContractPermissionJSON , InvocationResultJSON , RawAction , RawCallReceipt , RawInvocationResult , RawInvocationResultJSON , scriptHashToAddress , Transaction , TransactionJSON , } from '@neo-one/client-common' ; const verifyInvocationResultSuccess = ( invocationResult , invocationResultJSON ) => { if ( invocationResult . state !== 'HALT' || invocationResultJSON . state !== 'HALT' ) { throw new Error ( 'For TS' ) ; } expect ( invocationResult . gasConsumed . toString ( 10 ) ) . toEqual ( invocationResultJSON . gas_consumed ) ; const firstStack = invocationResult . stack [ 0 ] ; const firstStackJSON = invocationResultJSON . stack [ 0 ] ; if ( firstStack . type !== 'Integer' || firstStackJSON . type !== 'Integer' ) { throw new Error ( 'For TS' ) ; } expect ( firstStack . value . toString ( 10 ) ) . toEqual ( firstStackJSON . value ) ; } ; const verifyDefaultActions = ( actions , actionsJSON , blockIndex , blockHash , index , txid ) => { expect ( actions . length ) . toEqual ( actionsJSON . length ) ; const verifyAction = ( actionResult , action , idx ) => { expect ( actionResult . type ) . toEqual ( action . type ) ; expect ( actionResult . version ) . toEqual ( action . version ) ; expect ( actionResult . blockIndex ) . toEqual ( blockIndex ) ; expect ( actionResult . blockHash ) . toEqual ( blockHash ) ; expect ( actionResult . transactionIndex ) . toEqual ( index ) ; expect ( actionResult . transactionHash ) . toEqual ( txid ) ; expect ( actionResult . index ) . toEqual ( idx ) ; expect ( actionResult . globalIndex . toString ( 10 ) ) . toEqual ( action . index ) ; expect ( actionResult . address ) . toEqual ( scriptHashToAddress ( action . scriptHash ) ) ; } ; verifyAction ( actions [ 0 ] , actionsJSON [ 0 ] , 0 ) ; verifyAction ( actions [ 1 ] , actionsJSON [ 1 ] , 1 ) ; } ; const verifyAbi = ( abi , abiJSON ) => { } ; const verifyContractPermissionDescriptor = ( desc , descJSON ) => { expect ( desc . isHash ) . toEqual ( descJSON . isHash ) ; expect ( desc . isGroup ) . toEqual ( descJSON . isGroup ) ; expect ( desc . isWildcard ) . toEqual ( descJSON . isWildcard ) ; } ; const verifyPermission = ( permission , permissionJSON ) => { verifyContractPermissionDescriptor ( permission . contract , permissionJSON . contract ) ; expect ( permission . methods ) . toEqual ( permissionJSON . methods ) ; } ; const verifyGroup = ( group , groupJSON ) => { expect ( group . publicKey ) . toEqual ( common . stringToECPoint ( groupJSON . publicKey ) ) ; expect ( group . signature ) . toEqual ( Buffer . from ( groupJSON . signature , 'hex' ) ) ; } ; const verifyManifest = ( manifest , manifestJSON ) => { expect ( manifest . hash ) . toEqual ( scriptHashToAddress ( manifestJSON . hash ) ) ; expect ( manifest . trusts ) . toEqual ( manifestJSON . trusts ) ; expect ( manifest . supportedStandards ) . toEqual ( manifestJSON . supportedStandards ) ; expect ( manifest . extra ) . toEqual ( manifestJSON . extra ) ; verifyAbi ( manifest . abi , manifestJSON . abi ) ; expect ( manifest . permissions . length ) . toEqual ( manifestJSON . permissions . length ) ; manifest . permissions . forEach ( ( perm , idx ) => { verifyPermission ( perm , manifestJSON . permissions [ idx ] ) ; } ) ; expect ( manifest . groups . length ) . toEqual ( manifestJSON . groups . length ) ; manifest . groups . forEach ( ( group , idx ) => { verifyGroup ( group , manifestJSON . groups [ idx ] ) ; } ) ; } ; const verifyContract = ( contract , contractJSON , returnType = 'Buffer' ) => { expect ( contract . id ) . toEqual ( contractJSON . id ) ; expect ( contract . script ) . toEqual ( contractJSON . script ) ; verifyManifest ( contract . manifest , contractJSON . manifest ) ; } ; const verifyTransaction = ( transaction , transactionJSON ) => { expect ( transaction . hash ) . toEqual ( transactionJSON . hash ) ; expect ( transaction . size ) . toEqual ( transactionJSON . size ) ; expect ( transaction . version ) . toEqual ( transactionJSON . version ) ; expect ( transaction . nonce ) . toEqual ( transactionJSON . nonce ) ; expect ( transaction . sender ) . toEqual ( transactionJSON . sender ) ; expect ( transaction . systemFee . toString ( 10 ) ) . toEqual ( transactionJSON . sysfee ) ; expect ( transaction . networkFee . toString ( 10 ) ) . toEqual ( transactionJSON . netfee ) ; expect ( transaction . validUntilBlock ) . toEqual ( transactionJSON . validuntilblock ) ; expect ( transaction . attributes . length ) . toEqual ( transactionJSON . attributes . length ) ; expect ( transaction . attributes ) . toEqual ( transactionJSON . attributes ) ; expect ( transaction . signers . length ) . toEqual ( transactionJSON . signers . length ) ; expect ( transaction . script ) . toEqual ( transactionJSON . script ) ; expect ( transaction . witnesses ) . toEqual ( transactionJSON . witnesses ) ; } ; const verifyConfirmedTransaction = ( transaction , transactionJSON ) => { if ( transactionJSON . data === undefined ) { throw new Error ( 'For TS' ) ; } expect ( transaction . receipt . blockHash ) . toEqual ( transactionJSON . data . blockHash ) ; expect ( transaction . receipt . blockIndex ) . toEqual ( transactionJSON . data . blockIndex ) ; expect ( transaction . receipt . transactionIndex ) . toEqual ( transactionJSON . data . transactionIndex ) ; expect ( transaction . receipt . globalIndex . toString ( 10 ) ) . toEqual ( transactionJSON . data . globalIndex ) ; } ; const verifyCallReceipt = ( receipt , receiptJSON ) => { verifyInvocationResultSuccess ( receipt . result , receiptJSON . result ) ; verifyDefaultActions ( receipt . actions , receiptJSON . actions , 0 , '0x​​​​​0000000000000000000000000000000000000000000000000000000000000000​​​​​' , 0 , '0x​​​​​0000000000000000000000000000000000000000000000000000000000000000​​​​​' ) ; } ; export const verifyDataProvider = { verifyInvocationResultSuccess , verifyDefaultActions , verifyContract , verifyTransaction , verifyConfirmedTransaction , verifyCallReceipt } ;