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.

46 lines
1.4 KiB

  1. package test
  2. import (
  3. "testing"
  4. "github.com/hermeznetwork/hermez-node/common"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestGeneratePoolL2Txs(t *testing.T) {
  8. set := `
  9. Transfer(1) A-B: 6 (1)
  10. Transfer(1) B-C: 3 (1)
  11. Transfer(1) C-A: 3 (1)
  12. Transfer(1) A-B: 1 (1)
  13. Transfer(2) A-B: 15 (1)
  14. Transfer(1) User0-User1: 15 (1)
  15. Transfer(3) User1-User0: 15 (1)
  16. Transfer(2) B-D: 3 (1)
  17. Exit(1) A: 3
  18. `
  19. tc := NewTestContext(t)
  20. poolL2Txs := tc.GeneratePoolL2Txs(set)
  21. assert.Equal(t, 9, len(poolL2Txs))
  22. assert.Equal(t, common.TxTypeTransfer, poolL2Txs[0].Type)
  23. assert.Equal(t, common.TxTypeExit, poolL2Txs[8].Type)
  24. assert.Equal(t, tc.accounts["B1"].Addr.Hex(), poolL2Txs[0].ToEthAddr.Hex())
  25. assert.Equal(t, tc.accounts["B1"].BJJ.Public().String(), poolL2Txs[0].ToBJJ.String())
  26. assert.Equal(t, tc.accounts["User11"].Addr.Hex(), poolL2Txs[5].ToEthAddr.Hex())
  27. assert.Equal(t, tc.accounts["User11"].BJJ.Public().String(), poolL2Txs[5].ToBJJ.String())
  28. assert.Equal(t, common.Nonce(1), poolL2Txs[0].Nonce)
  29. assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce)
  30. assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
  31. // load another set in the same TestContext
  32. set = `
  33. Transfer(1) A-B: 6 (1)
  34. Transfer(1) B-C: 3 (1)
  35. Transfer(1) A-C: 3 (1)
  36. `
  37. poolL2Txs = tc.GeneratePoolL2Txs(set)
  38. assert.Equal(t, common.Nonce(4), poolL2Txs[0].Nonce)
  39. assert.Equal(t, common.Nonce(2), poolL2Txs[1].Nonce)
  40. assert.Equal(t, common.Nonce(5), poolL2Txs[2].Nonce)
  41. }