6 "github.com/bytom/consensus"
7 "github.com/bytom/protocol/bc/types"
8 "github.com/bytom/protocol/vm/vmutil"
11 func TestTxPool(t *testing.T) {
14 txA := mockCoinbaseTx(1000, 6543)
15 txB := mockCoinbaseTx(2000, 2324)
16 txC := mockCoinbaseTx(3000, 9322)
18 p.AddTransaction(txA, false, 1000, 5000000000)
19 if !p.IsTransactionInPool(&txA.ID) {
20 t.Errorf("fail to find added txA in tx pool")
22 i, _ := p.GetTransaction(&txA.ID)
23 if i.Height != 1000 || i.Fee != 5000000000 || i.FeePerKB != 5000000000 {
24 t.Errorf("incorrect data of TxDesc structure")
28 if p.IsTransactionInPool(&txB.ID) {
29 t.Errorf("shouldn't find txB in tx pool")
31 p.AddTransaction(txB, false, 1, 5000000000)
32 if !p.IsTransactionInPool(&txB.ID) {
33 t.Errorf("shouldn find txB in tx pool")
37 t.Errorf("get wrong number of tx in the pool")
39 p.RemoveTransaction(&txB.ID)
40 if p.IsTransactionInPool(&txB.ID) {
41 t.Errorf("shouldn't find txB in tx pool")
44 p.AddErrCache(&txC.ID, nil)
45 if !p.IsTransactionInErrCache(&txC.ID) {
46 t.Errorf("shouldn find txC in tx err cache")
48 if !p.HaveTransaction(&txC.ID) {
49 t.Errorf("shouldn find txC in tx err cache")
53 func mockCoinbaseTx(serializedSize uint64, amount uint64) *types.Tx {
54 cp, _ := vmutil.DefaultCoinbaseProgram()
55 oldTx := &types.TxData{
56 SerializedSize: serializedSize,
57 Inputs: []*types.TxInput{
58 types.NewCoinbaseInput(nil),
60 Outputs: []*types.TxOutput{
61 types.NewTxOutput(*consensus.BTMAssetID, amount, cp),
66 Tx: types.MapTx(oldTx),