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.

51 lines
1.6 KiB

  1. package test
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/hermeznetwork/hermez-node/common"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestGenerateTestL2Txs(t *testing.T) {
  10. s := `
  11. A (1): 10
  12. A (2): 20
  13. B (1): 5
  14. A-B (1): 6 1
  15. B-C (1): 3 1
  16. C-A (1): 3 1
  17. A-B (1): 1 1
  18. A-B (2): 15 1
  19. User0 (1): 20
  20. User1 (3) : 20
  21. User0-User1 (1): 15 1
  22. User1-User0 (3): 15 1
  23. `
  24. parser := NewParser(strings.NewReader(s))
  25. instructions, err := parser.Parse()
  26. assert.Nil(t, err)
  27. l1txs, l2txs := GenerateTestTxs(t, instructions)
  28. require.Equal(t, 5, len(l1txs))
  29. require.Equal(t, 7, len(l2txs))
  30. // l1txs
  31. assert.Equal(t, common.TxTypeCreateAccountDeposit, l1txs[0].Type)
  32. assert.Equal(t, "5bac784d938067d980a9d39bdd79bf84a0cbb296977c47cc30de2d5ce9229d2f", l1txs[0].FromBJJ.String())
  33. assert.Equal(t, "323ff10c28df37ecb787fe216e111db64aa7cfa2c517509fe0057ff08a10b30c", l1txs[1].FromBJJ.String())
  34. assert.Equal(t, "f3587ad5cc7414a47545770b6c75bc71930f63c491eb2294dde8b8a6670b8e96", l1txs[2].FromBJJ.String())
  35. assert.Equal(t, "b6856a87832b182e5a9a1e738dbcd1f3c728bbc67ea1010aaff563eb5316131b", l1txs[4].FromBJJ.String())
  36. // l2txs
  37. assert.Equal(t, common.TxTypeTransfer, l2txs[0].Type)
  38. assert.Equal(t, common.Idx(1), l2txs[0].FromIdx)
  39. assert.Equal(t, common.Idx(3), l2txs[0].ToIdx)
  40. assert.Equal(t, "f3587ad5cc7414a47545770b6c75bc71930f63c491eb2294dde8b8a6670b8e96", l2txs[0].ToBJJ.String())
  41. assert.Equal(t, "0x6813Eb9362372EEF6200f3b1dbC3f819671cBA69", l2txs[0].ToEthAddr.Hex())
  42. assert.Equal(t, common.Nonce(0), l2txs[0].Nonce)
  43. assert.Equal(t, common.Nonce(1), l2txs[3].Nonce)
  44. assert.Equal(t, common.FeeSelector(1), l2txs[0].Fee)
  45. }