Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (ec *Client) PeerCount(ctx context.Context) (uint64, error) {
// BlockReceipts returns the receipts of a given block number or hash.
func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
var r []*types.Receipt
err := ec.c.CallContext(ctx, &r, "eth_getBlockReceipts", blockNrOrHash.String())
err := ec.c.CallContext(ctx, &r, "eth_getBlockReceipts", blockNrOrHash)
if err == nil && r == nil {
return nil, ethereum.NotFound
}
Expand Down
43 changes: 43 additions & 0 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,49 @@ func testTransactionSender(t *testing.T, client *rpc.Client) {
}
}

func TestBlockReceiptsPreservesCanonicalFlag(t *testing.T) {
srv := rpc.NewServer()
service := &blockReceiptsTestService{calls: make(chan rpc.BlockNumberOrHash, 1)}
if err := srv.RegisterName("eth", service); err != nil {
t.Fatalf("failed to register service: %v", err)
}
defer srv.Stop()

client := rpc.DialInProc(srv)
defer client.Close()

ec := ethclient.NewClient(client)
defer ec.Close()

hash := common.HexToHash("0x01")
ref := rpc.BlockNumberOrHashWithHash(hash, true)

if _, err := ec.BlockReceipts(context.Background(), ref); err != nil {
t.Fatalf("BlockReceipts returned error: %v", err)
}

select {
case call := <-service.calls:
if call.BlockHash == nil || *call.BlockHash != hash {
t.Fatalf("unexpected block hash: got %v, want %v", call.BlockHash, hash)
}
if !call.RequireCanonical {
t.Fatalf("requireCanonical flag was lost: %+v", call)
}
default:
t.Fatal("service was not called")
}
}

type blockReceiptsTestService struct {
calls chan rpc.BlockNumberOrHash
}

func (s *blockReceiptsTestService) GetBlockReceipts(ctx context.Context, block rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
s.calls <- block
return []*types.Receipt{}, nil
}

func newCanceledContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand Down