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