diff --git a/sharding/collator.go b/sharding/collator.go index 42db582f76..a4662643b4 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -9,7 +9,7 @@ import ( "math/big" ) -// subscribeBlockHeaders checks incoming block headers and determines if +// SubscribeBlockHeaders checks incoming block headers and determines if // we are an eligible proposer for collations. Then, it finds the pending tx's // from the running geth node and sorts them by descending order of gas price, // eliminates those that ask for too much gas, and routes them over diff --git a/sharding/collator_test.go b/sharding/collator_test.go index 274ebc2d4d..584be3b19d 100644 --- a/sharding/collator_test.go +++ b/sharding/collator_test.go @@ -1,19 +1,29 @@ package sharding import ( - "github.com/ethereum/go-ethereum/common/hexutil" - "sync" + "context" + "fmt" "testing" + + "github.com/ethereum/go-ethereum/core/types" ) -// FakeEthService based on implementation of internal/ethapi.Client -type FakeEthService struct { - mu sync.Mutex +type FakeClient struct { + client *FakeEthClient +} - getCodeResp hexutil.Bytes - getCodeErr error +type FakeEthClient struct{} + +type FakeSubscription struct{} + +func (ec *FakeEthClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (FakeSubscription, error) { + return FakeSubscription{}, fmt.Errorf("error, network disconnected!") } func TestSubscribeHeaders(t *testing.T) { - + client := &FakeClient{client: &FakeEthClient{}} + err := subscribeBlockHeaders(client) + if err != nil { + t.Errorf("subscribe new headers should work", "no error", err) + } }