import '../../setup' ; import { SignedTransaction , Swap , RollupTransaction , Transfer , State , StateReceipt , SwapTransition , InclusionProof , TransferTransition , CreateAndTransferTransition , abiEncodeSignedTransaction , abiEncodeState , abiEncodeStateReceipt , abiEncodeTransaction , abiEncodeTransition , parseSignedTransactionFromABI , parseStateFromABI , parseStateReceiptFromABI , parseTransactionFromABI , parseTransitionFromABI , UNI_TOKEN_TYPE , PIGI_TOKEN_TYPE , } from '../../../src/' ; import { AGGREGATOR_ADDRESS , BOB_ADDRESS } from '../../helpers' ; const stateRoot = '9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658' ; const inclusionProof = [ stateRoot , stateRoot , stateRoot ] ; describe ( 'RollupEncoding' , ( ) => { describe ( 'Transactions' , ( ) => { it ( 'should encoded & decode Transfer without throwing' , async ( ) => { const address = '0x' + '31' . repeat ( 20 ) ; const tx = { sender : address , recipient : address , tokenType : 1 , amount : 15 , } ; const abiEncoded = abiEncodeTransaction ( tx ) ; const transfer = parseTransactionFromABI ( abiEncoded ) ; transfer . should . deep . equal ( tx ) ; } ) ; it ( 'should encoded & decode Swap without throwing' , async ( ) => { const address = '0x' + '31' . repeat ( 20 ) ; const tx = { sender : address , tokenType : 1 , inputAmount : 15 , minOutputAmount : 4 , timeout : + new Date ( ) , } ; const abiEncoded = abiEncodeTransaction ( tx ) ; const swap = parseTransactionFromABI ( abiEncoded ) ; swap . should . deep . equal ( tx ) ; } ) ; it ( 'should encoded & decode SignedTransactions without throwing' , async ( ) => { const address = '0x' + '31' . repeat ( 20 ) ; const transfer = { sender : address , recipient : address , tokenType : 1 , amount : 15 , } ; const signedTransfer = { signature : '0x1234' , transaction : transfer , } ; const swap = { sender : address , tokenType : 1 , inputAmount : 15 , minOutputAmount : 4 , timeout : + new Date ( ) , } ; const signedSwap = { signature : '0x4321' , transaction : swap , } ; const abiEncodedSwap = abiEncodeSignedTransaction ( signedSwap ) ; const abiEncodedTransfer = abiEncodeSignedTransaction ( signedTransfer ) ; abiEncodedSwap . should . not . equal ( abiEncodedTransfer ) ; const parsedSwap = parseSignedTransactionFromABI ( abiEncodedSwap ) ; const parsedTransfer = parseSignedTransactionFromABI ( abiEncodedTransfer ) ; parsedSwap . should . not . deep . equal ( parsedTransfer ) ; parsedSwap . should . deep . equal ( signedSwap ) ; parsedTransfer . should . deep . equal ( signedTransfer ) ; } ) ; } ) ; describe ( 'State' , ( ) => { it ( 'should encoded & decode State without throwing' , async ( ) => { const state = { pubkey : BOB_ADDRESS , balances : { [ UNI_TOKEN_TYPE ] : 50 , [ PIGI_TOKEN_TYPE ] : 100 , } , } ; const stateString = abiEncodeState ( state ) ; const parsedState = parseStateFromABI ( stateString ) ; parsedState . should . deep . equal ( state ) ; } ) ; } ) ; describe ( 'State Receipt' , ( ) => { it ( 'should encoded & decode StateReceipt without throwing' , async ( ) => { const state = { pubkey : BOB_ADDRESS , balances : { [ UNI_TOKEN_TYPE ] : 50 , [ PIGI_TOKEN_TYPE ] : 100 , } , } ; const stateReceipt = { slotIndex : 0 , stateRoot , inclusionProof , blockNumber : 1 , transitionIndex : 2 , state , } ; const stateReceiptString = abiEncodeStateReceipt ( stateReceipt ) ; const parsedStateReceipt = parseStateReceiptFromABI ( stateReceiptString ) ; parsedStateReceipt . should . deep . equal ( stateReceipt ) ; } ) ; } ) ; describe ( 'Transitions' , ( ) => { const sig = '0x1234' ; it ( 'should encoded & decode Swap Transition without throwing' , async ( ) => { const transition = { stateRoot , senderSlotIndex : 2 , uniswapSlotIndex : 1 , tokenType : 0 , inputAmount : 10 , minOutputAmount : 100 , timeout : 10 , signature : sig , } ; const transitionString = abiEncodeTransition ( transition ) ; const parsedTransition = parseTransitionFromABI ( transitionString ) ; parsedTransition . should . deep . equal ( transition ) ; } ) ; it ( 'should encoded & decode Transfer Transition without throwing' , async ( ) => { const transition = { stateRoot , senderSlotIndex : 2 , recipientSlotIndex : 1 , tokenType : 0 , amount : 10 , signature : sig , } ; const transitionString = abiEncodeTransition ( transition ) ; const parsedTransition = parseTransitionFromABI ( transitionString ) ; parsedTransition . should . deep . equal ( transition ) ; } ) ; it ( 'should encoded & decode CreateAndTransfer Transition without throwing' , async ( ) => { const transition = { stateRoot , senderSlotIndex : 2 , recipientSlotIndex : 1 , tokenType : 0 , amount : 10 , signature : sig , createdAccountPubkey : AGGREGATOR_ADDRESS , } ; const transitionString = abiEncodeTransition ( transition ) ; const parsedTransition = parseTransitionFromABI ( transitionString ) ; parsedTransition . should . deep . equal ( transition ) ; } ) ; } ) ; } ) ;