|
| 1 | +package headerfs |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/btcsuite/btcd/blockchain" |
| 5 | + "github.com/btcsuite/btcd/chaincfg/chainhash" |
| 6 | + "github.com/btcsuite/btcd/wire" |
| 7 | + "github.com/stretchr/testify/mock" |
| 8 | +) |
| 9 | + |
| 10 | +// MockBlockHeaderStore is a mock implementation of the BlockHeaderStore. |
| 11 | +type MockBlockHeaderStore struct { |
| 12 | + mock.Mock |
| 13 | +} |
| 14 | + |
| 15 | +// ChainTip returns the current chain tip for the mock block header store. |
| 16 | +func (m *MockBlockHeaderStore) ChainTip() (*wire.BlockHeader, uint32, error) { |
| 17 | + args := m.Called() |
| 18 | + return args.Get(0).(*wire.BlockHeader), |
| 19 | + args.Get(1).(uint32), |
| 20 | + args.Error(2) |
| 21 | +} |
| 22 | + |
| 23 | +// LatestBlockLocator returns the latest block locator for the mock block header |
| 24 | +// store. |
| 25 | +// |
| 26 | +//nolint:lll |
| 27 | +func (m *MockBlockHeaderStore) LatestBlockLocator() (blockchain.BlockLocator, error) { |
| 28 | + args := m.Called() |
| 29 | + return args.Get(0).(blockchain.BlockLocator), args.Error(1) |
| 30 | +} |
| 31 | + |
| 32 | +// FetchHeaderByHeight fetches a block header by height for the mock block |
| 33 | +// header store. |
| 34 | +func (m *MockBlockHeaderStore) FetchHeaderByHeight( |
| 35 | + height uint32) (*wire.BlockHeader, error) { |
| 36 | + |
| 37 | + args := m.Called(height) |
| 38 | + if args.Get(0) == nil { |
| 39 | + return nil, args.Error(1) |
| 40 | + } |
| 41 | + return args.Get(0).(*wire.BlockHeader), args.Error(1) |
| 42 | +} |
| 43 | + |
| 44 | +// FetchHeaderAncestors fetches block header ancestors for the mock block header |
| 45 | +// store. |
| 46 | +func (m *MockBlockHeaderStore) FetchHeaderAncestors(numHeaders uint32, |
| 47 | + stopHash *chainhash.Hash) ([]wire.BlockHeader, uint32, error) { |
| 48 | + |
| 49 | + args := m.Called(numHeaders, stopHash) |
| 50 | + return args.Get(0).([]wire.BlockHeader), |
| 51 | + args.Get(1).(uint32), |
| 52 | + args.Error(2) |
| 53 | +} |
| 54 | + |
| 55 | +// HeightFromHash returns the height from a hash for the mock block header |
| 56 | +// store. |
| 57 | +func (m *MockBlockHeaderStore) HeightFromHash( |
| 58 | + hash *chainhash.Hash) (uint32, error) { |
| 59 | + |
| 60 | + args := m.Called(hash) |
| 61 | + return args.Get(0).(uint32), args.Error(1) |
| 62 | +} |
| 63 | + |
| 64 | +// FetchHeader fetches a block header by hash for the mock block header store. |
| 65 | +func (m *MockBlockHeaderStore) FetchHeader( |
| 66 | + hash *chainhash.Hash) (*wire.BlockHeader, uint32, error) { |
| 67 | + |
| 68 | + args := m.Called(hash) |
| 69 | + if args.Get(0) == nil { |
| 70 | + return nil, args.Get(1).(uint32), args.Error(2) |
| 71 | + } |
| 72 | + return args.Get(0).(*wire.BlockHeader), |
| 73 | + args.Get(1).(uint32), |
| 74 | + args.Error(2) |
| 75 | +} |
| 76 | + |
| 77 | +// WriteHeaders writes block headers to the mock block header store. |
| 78 | +func (m *MockBlockHeaderStore) WriteHeaders(hdrs ...BlockHeader) error { |
| 79 | + args := m.Called(hdrs) |
| 80 | + return args.Error(0) |
| 81 | +} |
| 82 | + |
| 83 | +// RollbackLastBlock rolls back the last block in the mock block header store. |
| 84 | +func (m *MockBlockHeaderStore) RollbackLastBlock() (*BlockStamp, error) { |
| 85 | + args := m.Called() |
| 86 | + if args.Get(0) == nil { |
| 87 | + return nil, args.Error(1) |
| 88 | + } |
| 89 | + return args.Get(0).(*BlockStamp), args.Error(1) |
| 90 | +} |
| 91 | + |
| 92 | +// MockFilterHeaderStore is a mock implementation of the FilterHeaderStore. |
| 93 | +type MockFilterHeaderStore struct { |
| 94 | + mock.Mock |
| 95 | +} |
| 96 | + |
| 97 | +// ChainTip returns the current chain tip for the mock filter header store. |
| 98 | +func (m *MockFilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error) { |
| 99 | + args := m.Called() |
| 100 | + return args.Get(0).(*chainhash.Hash), |
| 101 | + args.Get(1).(uint32), |
| 102 | + args.Error(2) |
| 103 | +} |
| 104 | + |
| 105 | +// FetchHeader fetches a filter header by hash for the mock filter header store. |
| 106 | +func (m *MockFilterHeaderStore) FetchHeader( |
| 107 | + hash *chainhash.Hash) (*chainhash.Hash, error) { |
| 108 | + |
| 109 | + args := m.Called(hash) |
| 110 | + if args.Get(0) == nil { |
| 111 | + return nil, args.Error(1) |
| 112 | + } |
| 113 | + return args.Get(0).(*chainhash.Hash), args.Error(1) |
| 114 | +} |
| 115 | + |
| 116 | +// FetchHeaderAncestors fetches filter header ancestors for the mock filter |
| 117 | +// header store. |
| 118 | +func (m *MockFilterHeaderStore) FetchHeaderAncestors(numHeaders uint32, |
| 119 | + stopHash *chainhash.Hash) ([]chainhash.Hash, uint32, error) { |
| 120 | + |
| 121 | + args := m.Called(numHeaders, stopHash) |
| 122 | + return args.Get(0).([]chainhash.Hash), |
| 123 | + args.Get(1).(uint32), |
| 124 | + args.Error(2) |
| 125 | +} |
| 126 | + |
| 127 | +// FetchHeaderByHeight fetches a filter header by height for the mock filter |
| 128 | +// header store. |
| 129 | +func (m *MockFilterHeaderStore) FetchHeaderByHeight( |
| 130 | + height uint32) (*chainhash.Hash, error) { |
| 131 | + |
| 132 | + args := m.Called(height) |
| 133 | + if args.Get(0) == nil { |
| 134 | + return nil, args.Error(1) |
| 135 | + } |
| 136 | + return args.Get(0).(*chainhash.Hash), args.Error(1) |
| 137 | +} |
| 138 | + |
| 139 | +// WriteHeaders writes filter headers to the mock filter header store. |
| 140 | +func (m *MockFilterHeaderStore) WriteHeaders(headers ...FilterHeader) error { |
| 141 | + args := m.Called(headers) |
| 142 | + return args.Error(0) |
| 143 | +} |
| 144 | + |
| 145 | +// RollbackLastBlock rolls back the last block in the mock filter header store. |
| 146 | +func (m *MockFilterHeaderStore) RollbackLastBlock( |
| 147 | + newTip *chainhash.Hash) (*BlockStamp, error) { |
| 148 | + |
| 149 | + args := m.Called(newTip) |
| 150 | + if args.Get(0) == nil { |
| 151 | + return nil, args.Error(1) |
| 152 | + } |
| 153 | + return args.Get(0).(*BlockStamp), args.Error(1) |
| 154 | +} |
0 commit comments