-
Notifications
You must be signed in to change notification settings - Fork 5
/
peer_manager_mock.go
60 lines (49 loc) · 1.7 KB
/
peer_manager_mock.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
package p2p
import (
"github.com/libsv/go-p2p/chaincfg/chainhash"
)
type PeerManagerMock struct {
Peers []PeerI
AnnouncedTransactions []*chainhash.Hash
RequestTransactions []*chainhash.Hash
AnnouncedBlocks []*chainhash.Hash
RequestBlocks []*chainhash.Hash
peerCreator func(peerAddress string, peerHandler PeerHandlerI) (PeerI, error)
}
func NewPeerManagerMock() *PeerManagerMock {
return &PeerManagerMock{
Peers: make([]PeerI, 0),
AnnouncedTransactions: make([]*chainhash.Hash, 0),
RequestTransactions: make([]*chainhash.Hash, 0),
AnnouncedBlocks: make([]*chainhash.Hash, 0),
RequestBlocks: make([]*chainhash.Hash, 0),
}
}
func (p *PeerManagerMock) RequestTransaction(hash *chainhash.Hash) PeerI {
p.RequestTransactions = append(p.RequestTransactions, hash)
return nil
}
func (p *PeerManagerMock) AnnounceTransaction(hash *chainhash.Hash, _ []PeerI) []PeerI {
p.AnnouncedTransactions = append(p.AnnouncedTransactions, hash)
return nil
}
func (p *PeerManagerMock) AnnounceBlock(blockHash *chainhash.Hash, _ []PeerI) []PeerI {
p.AnnouncedBlocks = append(p.AnnouncedBlocks, blockHash)
return nil
}
func (p *PeerManagerMock) RequestBlock(blockHash *chainhash.Hash) PeerI {
p.RequestBlocks = append(p.RequestBlocks, blockHash)
return nil
}
func (p *PeerManagerMock) PeerCreator(peerCreator func(peerAddress string, peerHandler PeerHandlerI) (PeerI, error)) {
p.peerCreator = peerCreator
}
func (p *PeerManagerMock) AddPeer(peer PeerI) error {
p.Peers = append(p.Peers, peer)
return nil
}
func (p *PeerManagerMock) GetPeers() []PeerI {
peers := make([]PeerI, 0, len(p.Peers))
peers = append(peers, p.Peers...)
return peers
}