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.

57 lines
1.9 KiB

  1. package test
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/hermeznetwork/hermez-node/common"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestGenerateTestL2Txs(t *testing.T) {
  9. s := `
  10. A (1): 10
  11. A (2): 20
  12. B (1): 5
  13. A-B (1): 6 1
  14. B-C (1): 3 1
  15. > advance batch
  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. B-D (2): 3 1
  24. `
  25. parser := NewParser(strings.NewReader(s))
  26. instructions, err := parser.Parse()
  27. assert.Nil(t, err)
  28. l1txs, coordinatorL1txs, l2txs, _ := GenerateTestTxs(t, instructions)
  29. assert.Equal(t, 2, len(l1txs))
  30. assert.Equal(t, 3, len(l1txs[0]))
  31. assert.Equal(t, 1, len(coordinatorL1txs[0]))
  32. assert.Equal(t, 2, len(l2txs[0]))
  33. assert.Equal(t, 2, len(l1txs[1]))
  34. assert.Equal(t, 4, len(coordinatorL1txs[1]))
  35. assert.Equal(t, 6, len(l2txs[1]))
  36. // l1txs
  37. assert.Equal(t, common.TxTypeCreateAccountDeposit, l1txs[0][0].Type)
  38. assert.Equal(t, "5bac784d938067d980a9d39bdd79bf84a0cbb296977c47cc30de2d5ce9229d2f", l1txs[0][0].FromBJJ.String())
  39. assert.Equal(t, "323ff10c28df37ecb787fe216e111db64aa7cfa2c517509fe0057ff08a10b30c", l1txs[0][1].FromBJJ.String())
  40. assert.Equal(t, "f3587ad5cc7414a47545770b6c75bc71930f63c491eb2294dde8b8a6670b8e96", l1txs[0][2].FromBJJ.String())
  41. assert.Equal(t, "750a24a874a81c6c6f8aaa168ff2ee88c58263fee9ddd96d9717bcffc809b027", l1txs[1][1].FromBJJ.String())
  42. // l2txs
  43. assert.Equal(t, common.TxTypeTransfer, l2txs[0][0].Type)
  44. assert.Equal(t, common.Idx(1), l2txs[0][0].FromIdx)
  45. assert.Equal(t, common.Idx(3), l2txs[0][0].ToIdx)
  46. assert.Equal(t, "f3587ad5cc7414a47545770b6c75bc71930f63c491eb2294dde8b8a6670b8e96", l2txs[0][0].ToBJJ.String())
  47. assert.Equal(t, "0x6813Eb9362372EEF6200f3b1dbC3f819671cBA69", l2txs[0][0].ToEthAddr.Hex())
  48. assert.Equal(t, common.Nonce(0), l2txs[0][0].Nonce)
  49. assert.Equal(t, common.Nonce(1), l2txs[1][1].Nonce)
  50. assert.Equal(t, common.FeeSelector(1), l2txs[0][0].Fee)
  51. }