mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Add codec functions
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewL2Tx(t *testing.T) {
|
||||
@@ -18,3 +20,23 @@ func TestNewL2Tx(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "0x020000000156660000000090", l2Tx.TxID.String())
|
||||
}
|
||||
|
||||
func TestL2TxByteParsers(t *testing.T) {
|
||||
amount := new(big.Int)
|
||||
amount.SetString("79000000", 10)
|
||||
l2Tx := &L2Tx{
|
||||
ToIdx: 256,
|
||||
Amount: amount,
|
||||
FromIdx: 257,
|
||||
Fee: 201,
|
||||
}
|
||||
// Data from the compatibility test
|
||||
expected := "00000101000001002b16c9"
|
||||
encodedData, err := l2Tx.Bytes(32)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, expected, hex.EncodeToString(encodedData))
|
||||
|
||||
decodedData, err := L2TxFromBytes(encodedData, 32)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, l2Tx, decodedData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user