-
Notifications
You must be signed in to change notification settings - Fork 2
/
tx_test.go
77 lines (66 loc) · 1.73 KB
/
tx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package wendy
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTxs(t *testing.T) {
txs := NewTxs(allTestTxs...)
t.Run("List", func(t *testing.T) {
require.Equal(t,
allTestTxs,
txs.List(),
)
})
t.Run("ByHash", func(t *testing.T) {
for _, tx := range allTestTxs {
require.Equal(t, tx, txs.ByHash(tx.Hash()))
}
someHash := Hash{0, 1, 2, 3, 4}
require.Nil(t, txs.ByHash(someHash))
})
}
func TestTxsPush(t *testing.T) {
allTxs := []Tx{testTx0, testTx1}
txs := NewTxs(allTxs...)
require.False(t, txs.Push(testTx0), "Push should return False when adding an existing Tx")
require.Equal(t, allTxs, txs.List())
require.True(t, txs.Push(testTx2), "Push should return True when adding a new Tx")
require.Equal(t, append(allTxs, testTx2), txs.List())
}
func TestTxsRemoval(t *testing.T) {
testCases := []struct {
name string
allTxs []Tx
removedTxs []Tx
expectedTxs []Tx
}{
{
name: "Single",
allTxs: []Tx{testTx0},
removedTxs: []Tx{testTx0},
expectedTxs: []Tx{},
},
{
name: "Borders",
allTxs: []Tx{testTx0, testTx1, testTx2, testTx3, testTx4, testTx5},
removedTxs: []Tx{testTx0, testTx5},
expectedTxs: []Tx{testTx1, testTx2, testTx3, testTx4},
},
{
name: "Middle",
allTxs: []Tx{testTx0, testTx1, testTx2, testTx3, testTx4, testTx5},
removedTxs: []Tx{testTx3},
expectedTxs: []Tx{testTx0, testTx1, testTx2, testTx4, testTx5},
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
txs := NewTxs(test.allTxs...)
for _, tx := range test.removedTxs {
txs.RemoveByHash(tx.Hash())
require.Nil(t, txs.ByHash(tx.Hash()))
}
require.Equal(t, test.expectedTxs, txs.List())
})
}
}