hermez-node/common/l2tx_test.go
common/l2tx_test.goRaw
1package common
2
3import (
4 "encoding/hex"
5 "math/big"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10)
11
12func TestNewL2Tx(t *testing.T) {
13 l2Tx := &L2Tx{
14 FromIdx: 87654,
15 ToIdx: 300,
16 Amount: big.NewInt(4),
17 Nonce: 144,
18 }
19 l2Tx, err := NewL2Tx(l2Tx)
20 assert.Nil(t, err)
21 assert.Equal(t, "0x020000000156660000000090", l2Tx.TxID.String())
22}
23
24func TestL2TxByteParsers(t *testing.T) {
25 amount := new(big.Int)
26 amount.SetString("79000000", 10)
27 l2Tx := &L2Tx{
28 ToIdx: 256,
29 Amount: amount,
30 FromIdx: 257,
31 Fee: 201,
32 }
33 // Data from the compatibility test
34 expected := "00000101000001002b16c9"
35 encodedData, err := l2Tx.BytesDataAvailability(32)
36 require.Nil(t, err)
37 assert.Equal(t, expected, hex.EncodeToString(encodedData))
38
39 decodedData, err := L2TxFromBytes(encodedData, 32)
40 require.Nil(t, err)
41 assert.Equal(t, l2Tx, decodedData)
42}