6 "github.com/bytom/consensus"
7 "github.com/bytom/protocol/bc/legacy"
10 func TestTxPool(t *testing.T) {
13 txA := mockCoinbaseTx(1000, 6543)
14 txB := mockCoinbaseTx(2000, 2324)
15 txC := mockCoinbaseTx(3000, 9322)
17 p.AddTransaction(txA, false, 1000, 5000000000)
18 if !p.IsTransactionInPool(&txA.ID) {
19 t.Errorf("fail to find added txA in tx pool")
21 i, _ := p.GetTransaction(&txA.ID)
22 if i.Height != 1000 || i.Fee != 5000000000 || i.FeePerKB != 5000000000 {
23 t.Errorf("incorrect data of TxDesc structure")
27 if p.IsTransactionInPool(&txB.ID) {
28 t.Errorf("shouldn't find txB in tx pool")
30 p.AddTransaction(txB, false, 1, 5000000000)
31 if !p.IsTransactionInPool(&txB.ID) {
32 t.Errorf("shouldn find txB in tx pool")
36 t.Errorf("get wrong number of tx in the pool")
38 p.RemoveTransaction(&txB.ID)
39 if p.IsTransactionInPool(&txB.ID) {
40 t.Errorf("shouldn't find txB in tx pool")
43 p.AddErrCache(&txC.ID, nil)
44 if !p.IsTransactionInErrCache(&txC.ID) {
45 t.Errorf("shouldn find txC in tx err cache")
47 if !p.HaveTransaction(&txC.ID) {
48 t.Errorf("shouldn find txC in tx err cache")
52 func mockCoinbaseTx(serializedSize uint64, amount uint64) *legacy.Tx {
53 oldTx := &legacy.TxData{
54 SerializedSize: serializedSize,
55 Outputs: []*legacy.TxOutput{
56 legacy.NewTxOutput(*consensus.BTMAssetID, amount, []byte{1}, nil),
62 Tx: legacy.MapTx(oldTx),