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.

43 lines
980 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. TokenID: 5,
  14. Amount: big.NewInt(4),
  15. Nonce: 144,
  16. }
  17. l2Tx, err := NewL2Tx(l2Tx)
  18. assert.NoError(t, err)
  19. assert.Equal(t, "0x024f67ec893467419cdfacfc9152e55dc7ce16088952bf2b3442732fd046bd031c", l2Tx.TxID.String())
  20. }
  21. func TestL2TxByteParsers(t *testing.T) {
  22. amount := new(big.Int)
  23. amount.SetString("79000000", 10)
  24. l2Tx := &L2Tx{
  25. ToIdx: 256,
  26. Amount: amount,
  27. FromIdx: 257,
  28. Fee: 201,
  29. }
  30. // Data from the compatibility test
  31. expected := "00000101000001002b16c9"
  32. encodedData, err := l2Tx.BytesDataAvailability(32)
  33. require.NoError(t, err)
  34. assert.Equal(t, expected, hex.EncodeToString(encodedData))
  35. decodedData, err := L2TxFromBytesDataAvailability(encodedData, 32)
  36. require.NoError(t, err)
  37. assert.Equal(t, l2Tx, decodedData)
  38. }