@@ -18,14 +18,11 @@ package catchup
1818
1919import (
2020 "context"
21- "errors"
2221 "net"
2322 "net/http"
24- "net/rpc"
2523 "net/url"
2624 "strings"
2725 "testing"
28- "time"
2926
3027 "github.com/gorilla/mux"
3128 "github.com/stretchr/testify/require"
@@ -41,134 +38,8 @@ import (
4138 "github.com/algorand/go-algorand/logging"
4239 "github.com/algorand/go-algorand/network"
4340 "github.com/algorand/go-algorand/protocol"
44- "github.com/algorand/go-algorand/rpcs"
45- "github.com/algorand/go-algorand/util/bloom"
4641)
4742
48- type mockRunner struct {
49- ran bool
50- done chan * rpc.Call
51- failWithNil bool
52- failWithError bool
53- txgroups [][]transactions.SignedTxn
54- }
55-
56- type mockRPCClient struct {
57- client * mockRunner
58- closed bool
59- rootURL string
60- log logging.Logger
61- }
62-
63- func (client * mockRPCClient ) Close () error {
64- client .closed = true
65- return nil
66- }
67-
68- func (client * mockRPCClient ) Address () string {
69- return "mock.address."
70- }
71- func (client * mockRPCClient ) Sync (ctx context.Context , bloom * bloom.Filter ) (txgroups [][]transactions.SignedTxn , err error ) {
72- client .log .Info ("MockRPCClient.Sync" )
73- select {
74- case <- ctx .Done ():
75- return nil , errors .New ("cancelled" )
76- default :
77- }
78- if client .client .failWithNil {
79- return nil , errors .New ("old failWithNil" )
80- }
81- if client .client .failWithError {
82- return nil , errors .New ("failing call" )
83- }
84- return client .client .txgroups , nil
85- }
86- func (client * mockRPCClient ) getBlockBytes (ctx context.Context , r basics.Round ) (data []byte , err error ) {
87- return nil , nil
88- }
89-
90- // network.HTTPPeer interface
91- func (client * mockRPCClient ) GetAddress () string {
92- return client .rootURL
93- }
94- func (client * mockRPCClient ) GetHTTPClient () * http.Client {
95- return nil
96- }
97-
98- type mockClientAggregator struct {
99- mocks.MockNetwork
100- peers []network.Peer
101- }
102-
103- func (mca * mockClientAggregator ) GetPeers (options ... network.PeerOption ) []network.Peer {
104- return mca .peers
105- }
106-
107- const numberOfPeers = 10
108-
109- func makeMockClientAggregator (t * testing.T , failWithNil bool , failWithError bool ) * mockClientAggregator {
110- clients := make ([]network.Peer , 0 )
111- for i := 0 ; i < numberOfPeers ; i ++ {
112- runner := mockRunner {failWithNil : failWithNil , failWithError : failWithError , done : make (chan * rpc.Call )}
113- clients = append (clients , & mockRPCClient {client : & runner , log : logging .TestingLog (t )})
114- }
115- t .Logf ("len(mca.clients) = %d" , len (clients ))
116- return & mockClientAggregator {peers : clients }
117- }
118-
119- type dummyFetcher struct {
120- failWithNil bool
121- failWithError bool
122- fetchTimeout time.Duration
123- }
124-
125- // FetcherClient interface
126- func (df * dummyFetcher ) getBlockBytes (ctx context.Context , r basics.Round ) (data []byte , err error ) {
127- if df .failWithNil {
128- return nil , nil
129- }
130- if df .failWithError {
131- return nil , errors .New ("failing call" )
132- }
133-
134- timer := time .NewTimer (df .fetchTimeout )
135- defer timer .Stop ()
136-
137- // Fill in the dummy response with the correct round
138- dummyBlock := rpcs.EncodedBlockCert {
139- Block : bookkeeping.Block {
140- BlockHeader : bookkeeping.BlockHeader {
141- Round : r ,
142- },
143- },
144- Certificate : agreement.Certificate {
145- Round : r ,
146- },
147- }
148-
149- encodedData := protocol .Encode (& dummyBlock )
150-
151- select {
152- case <- timer .C :
153- case <- ctx .Done ():
154- return nil , ctx .Err ()
155- }
156-
157- return encodedData , nil
158- }
159-
160- // FetcherClient interface
161- func (df * dummyFetcher ) Address () string {
162- //logging.Base().Debug("dummyFetcher Address")
163- return "dummyFetcher address"
164- }
165-
166- // FetcherClient interface
167- func (df * dummyFetcher ) Close () error {
168- //logging.Base().Debug("dummyFetcher Close")
169- return nil
170- }
171-
17243func buildTestLedger (t * testing.T , blk bookkeeping.Block ) (ledger * data.Ledger , next basics.Round , b bookkeeping.Block , err error ) {
17344 var user basics.Address
17445 user [0 ] = 123
0 commit comments