OSDN Git Service

txpool: periodically sweep pool for stale Txs (#337)
[bytom/vapor.git] / protocol / txpool_test.go
index 05eff7f..a2e63a2 100644 (file)
@@ -113,13 +113,19 @@ type mockStore struct{}
 
 func (s *mockStore) BlockExist(hash *bc.Hash) bool                                { return false }
 func (s *mockStore) GetBlock(*bc.Hash) (*types.Block, error)                      { return nil, nil }
+func (s *mockStore) GetBlockHeader(*bc.Hash) (*types.BlockHeader, error)          { return nil, nil }
 func (s *mockStore) GetStoreStatus() *BlockStoreState                             { return nil }
 func (s *mockStore) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
 func (s *mockStore) GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error     { return nil }
 func (s *mockStore) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)                 { return nil, nil }
-func (s *mockStore) LoadBlockIndex(uint64) (*state.BlockIndex, error)             { return nil, nil }
+func (s *mockStore) GetConsensusResult(uint64) (*state.ConsensusResult, error)    { return nil, nil }
+func (s *mockStore) GetMainChainHash(uint64) (*bc.Hash, error)                    { return nil, nil }
+func (s *mockStore) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error)            { return nil, nil }
 func (s *mockStore) SaveBlock(*types.Block, *bc.TransactionStatus) error          { return nil }
-func (s *mockStore) SaveChainStatus(*state.BlockNode, *state.UtxoViewpoint) error { return nil }
+func (s *mockStore) SaveBlockHeader(*types.BlockHeader) error                     { return nil }
+func (s *mockStore) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error {
+       return nil
+}
 
 func TestAddOrphan(t *testing.T) {
        cases := []struct {
@@ -416,7 +422,7 @@ func TestExpireOrphan(t *testing.T) {
                },
        }
 
-       before.ExpireOrphan(time.Unix(1633479701, 0))
+       before.expireOrphan(time.Unix(1633479701, 0))
        if !testutil.DeepEqual(before, want) {
                t.Errorf("got %v want %v", before, want)
        }
@@ -652,18 +658,25 @@ type mockStore1 struct{}
 
 func (s *mockStore1) BlockExist(hash *bc.Hash) bool                                { return false }
 func (s *mockStore1) GetBlock(*bc.Hash) (*types.Block, error)                      { return nil, nil }
+func (s *mockStore1) GetBlockHeader(*bc.Hash) (*types.BlockHeader, error)          { return nil, nil }
 func (s *mockStore1) GetStoreStatus() *BlockStoreState                             { return nil }
 func (s *mockStore1) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) { return nil, nil }
 func (s *mockStore1) GetTransactionsUtxo(utxoView *state.UtxoViewpoint, tx []*bc.Tx) error {
+       // TODO:
        for _, hash := range testTxs[2].SpentOutputIDs {
-               utxoView.Entries[hash] = &storage.UtxoEntry{IsCoinBase: false, Spent: false}
+               utxoView.Entries[hash] = &storage.UtxoEntry{Type: storage.NormalUTXOType, Spent: false}
        }
        return nil
 }
-func (s *mockStore1) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)                 { return nil, nil }
-func (s *mockStore1) LoadBlockIndex(uint64) (*state.BlockIndex, error)             { return nil, nil }
-func (s *mockStore1) SaveBlock(*types.Block, *bc.TransactionStatus) error          { return nil }
-func (s *mockStore1) SaveChainStatus(*state.BlockNode, *state.UtxoViewpoint) error { return nil }
+func (s *mockStore1) GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)              { return nil, nil }
+func (s *mockStore1) GetConsensusResult(uint64) (*state.ConsensusResult, error) { return nil, nil }
+func (s *mockStore1) GetMainChainHash(uint64) (*bc.Hash, error)                 { return nil, nil }
+func (s *mockStore1) GetBlockHashesByHeight(uint64) ([]*bc.Hash, error)         { return nil, nil }
+func (s *mockStore1) SaveBlock(*types.Block, *bc.TransactionStatus) error       { return nil }
+func (s *mockStore1) SaveBlockHeader(*types.BlockHeader) error                  { return nil }
+func (s *mockStore1) SaveChainStatus(*types.BlockHeader, *types.BlockHeader, []*types.BlockHeader, *state.UtxoViewpoint, []*state.ConsensusResult) error {
+       return nil
+}
 
 func TestProcessTransaction(t *testing.T) {
        txPool := &TxPool{
@@ -682,22 +695,6 @@ func TestProcessTransaction(t *testing.T) {
                {
                        want: &TxPool{},
                        addTx: &TxDesc{
-                               Tx:         testTxs[3],
-                               StatusFail: false,
-                       },
-               },
-               //Dust tx
-               {
-                       want: &TxPool{},
-                       addTx: &TxDesc{
-                               Tx:         testTxs[4],
-                               StatusFail: false,
-                       },
-               },
-               //Dust tx
-               {
-                       want: &TxPool{},
-                       addTx: &TxDesc{
                                Tx:         testTxs[5],
                                StatusFail: false,
                        },