Skip to content

Commit

Permalink
column widths and style
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Oct 17, 2022
1 parent ba0d223 commit f2b6301
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 26 deletions.
60 changes: 47 additions & 13 deletions chain/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var (
}
)

func newMockNeutrinoClient(t *testing.T, opts ...func(*mockRescanner)) *NeutrinoClient {
func newMockNeutrinoClient(t *testing.T,
opts ...func(*mockRescanner)) *NeutrinoClient {
t.Helper()
var (
chainParams = &chaincfg.Params{}
Expand Down Expand Up @@ -108,7 +109,9 @@ func (m *mockChainService) GetBlockHash(int64) (*chainhash.Hash, error) {
return nil, ErrNotImplemented
}

func (m *mockChainService) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error) {
func (m *mockChainService) GetBlockHeader(
*chainhash.Hash,
) (*wire.BlockHeader, error) {
return &wire.BlockHeader{}, nil
}

Expand All @@ -128,19 +131,50 @@ func (m *mockChainService) GetCFilter(
return nil, ErrNotImplemented
}

func (m *mockChainService) GetUtxo(_ ...neutrino.RescanOption) (*neutrino.SpendReport, error) {
func (m *mockChainService) GetUtxo(
_ ...neutrino.RescanOption,
) (*neutrino.SpendReport, error) {
return nil, ErrNotImplemented
}

func (m *mockChainService) BanPeer(string, banman.Reason) error { return ErrNotImplemented }
func (m *mockChainService) IsBanned(addr string) bool { panic(ErrNotImplemented) }
func (m *mockChainService) AddPeer(*neutrino.ServerPeer) { panic(ErrNotImplemented) }
func (m *mockChainService) AddBytesSent(uint64) { panic(ErrNotImplemented) }
func (m *mockChainService) AddBytesReceived(uint64) { panic(ErrNotImplemented) }
func (m *mockChainService) NetTotals() (uint64, uint64) { panic(ErrNotImplemented) }
func (m *mockChainService) UpdatePeerHeights(*chainhash.Hash, int32, *neutrino.ServerPeer) {
func (m *mockChainService) BanPeer(string, banman.Reason) error {
return ErrNotImplemented
}

func (m *mockChainService) IsBanned(addr string) bool {
panic(ErrNotImplemented)
}

func (m *mockChainService) AddPeer(*neutrino.ServerPeer) {
panic(ErrNotImplemented)
}

func (m *mockChainService) AddBytesSent(uint64) {
panic(ErrNotImplemented)
}

func (m *mockChainService) AddBytesReceived(uint64) {
panic(ErrNotImplemented)
}

func (m *mockChainService) NetTotals() (uint64, uint64) {
panic(ErrNotImplemented)
}

func (m *mockChainService) UpdatePeerHeights(
*chainhash.Hash, int32, *neutrino.ServerPeer,
) {
panic(ErrNotImplemented)
}

func (m *mockChainService) ChainParams() chaincfg.Params {
panic(ErrNotImplemented)
}

func (m *mockChainService) Stop() error {
panic(ErrNotImplemented)
}

func (m *mockChainService) PeerByAddr(string) *neutrino.ServerPeer {
panic(ErrNotImplemented)
}
func (m *mockChainService) ChainParams() chaincfg.Params { panic(ErrNotImplemented) }
func (m *mockChainService) Stop() error { panic(ErrNotImplemented) }
func (m *mockChainService) PeerByAddr(string) *neutrino.ServerPeer { panic(ErrNotImplemented) }
33 changes: 20 additions & 13 deletions chain/neutrino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ func TestNeutrinoClientSequentialStartStop(t *testing.T) {
}
}

// TestNeutrinoClientNotifyReceived verifies that a call to NotifyReceived sets the client into
// the scanning state and that subsequent calls while scanning will call Update on the
// client's Rescanner
// TestNeutrinoClientNotifyReceived verifies that a call to NotifyReceived sets
// the client into the scanning state and that subsequent calls while scanning
// will call Update on the client's Rescanner.
func TestNeutrinoClientNotifyReceived(t *testing.T) {
var (
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
ctx, cancel = context.WithTimeout(context.Background(),
1*time.Second)
addrs []btcutil.Address
done = make(chan struct{})
nc = newMockNeutrinoClient(t)
Expand All @@ -64,20 +65,25 @@ func TestNeutrinoClientNotifyReceived(t *testing.T) {
}
}()

// wait for all calls to complete or test failure
// Wait for all calls to complete or test to time out.
select {
case <-ctx.Done():
t.Fatal("timed out")
case <-done:
rescanner := <-nc.rescannerCh
mockRescan := rescanner.(*mockRescanner)
require.Equal(t, wantUpdateCalls, mockRescan.updateArgs.Len())
// Require that the expected number of calls to Update were made
// once done sending all NotifyReceived calls.
var (
rescanner = <-nc.rescannerCh
mockRescan = rescanner.(*mockRescanner)
gotUpdateCalls = mockRescan.updateArgs.Len()
)
require.Equal(t, wantUpdateCalls, gotUpdateCalls)
}
}

// TestNeutrinoClientNotifyReceivedRescan verifies concurrent calls to
// NotifyReceived and Rescan
// do not result in a data race and that there is no panic on replacing the Rescanner.
// NotifyReceived and Rescan do not result in a data race and that there is no
// panic on replacing the Rescanner.
func TestNeutrinoClientNotifyReceivedRescan(t *testing.T) {
var (
ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
Expand Down Expand Up @@ -110,11 +116,12 @@ func TestNeutrinoClientNotifyReceivedRescan(t *testing.T) {

t.Cleanup(cancel)

// start the client
// Start the client.
err := nc.Start()
require.NoError(t, err)

// launch wantRoutines, wait for them to finish and signal all done
// Launch the wanted number of goroutines, wait for them to finish and
// signal all done.
wg.Add(wantRoutines)
go func() {
defer close(done)
Expand All @@ -134,7 +141,7 @@ func TestNeutrinoClientNotifyReceivedRescan(t *testing.T) {
}
}()

// wait for all calls to complete or test failure
// Wait for all calls to complete or test to time out.
select {
case <-ctx.Done():
t.Fatal("timed out")
Expand Down

0 comments on commit f2b6301

Please sign in to comment.