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.

59 lines
1.8 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. accounts := GenerateKeys(t, instructions.Accounts)
  37. // l1txs
  38. assert.Equal(t, common.TxTypeCreateAccountDeposit, l1txs[0][0].Type)
  39. assert.Equal(t, accounts["A1"].BJJ.Public().String(), l1txs[0][0].FromBJJ.String())
  40. assert.Equal(t, accounts["A2"].BJJ.Public().String(), l1txs[0][1].FromBJJ.String())
  41. assert.Equal(t, accounts["B1"].BJJ.Public().String(), l1txs[0][2].FromBJJ.String())
  42. assert.Equal(t, accounts["User13"].BJJ.Public().String(), l1txs[1][1].FromBJJ.String())
  43. // l2txs
  44. assert.Equal(t, common.TxTypeTransfer, l2txs[0][0].Type)
  45. assert.Equal(t, common.Idx(256), l2txs[0][0].FromIdx)
  46. assert.Equal(t, common.Idx(258), *l2txs[0][0].ToIdx)
  47. assert.Equal(t, accounts["B1"].BJJ.Public().String(), l2txs[0][0].ToBJJ.String())
  48. assert.Equal(t, accounts["B1"].Addr.Hex(), l2txs[0][0].ToEthAddr.Hex())
  49. assert.Equal(t, common.Nonce(0), l2txs[0][0].Nonce)
  50. assert.Equal(t, common.Nonce(1), l2txs[1][1].Nonce)
  51. assert.Equal(t, common.FeeSelector(1), l2txs[0][0].Fee)
  52. }