You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
880 B

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