mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
This commit is contained in:
parent
2b10e68b10
commit
5f911680c0
2 changed files with 47 additions and 1 deletions
|
|
@ -122,7 +122,7 @@ func (ec *Client) PeerCount(ctx context.Context) (uint64, error) {
|
||||||
// BlockReceipts returns the receipts of a given block number or hash.
|
// BlockReceipts returns the receipts of a given block number or hash.
|
||||||
func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
|
func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
|
||||||
var r []*types.Receipt
|
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 {
|
if err == nil && r == nil {
|
||||||
return nil, ethereum.ErrNotFound
|
return nil, ethereum.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package ethclient
|
package ethclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -24,6 +25,8 @@ import (
|
||||||
|
|
||||||
ethereum "github.com/XinFinOrg/XDPoSChain"
|
ethereum "github.com/XinFinOrg/XDPoSChain"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Verify that Client implements the ethereum interfaces.
|
// Verify that Client implements the ethereum interfaces.
|
||||||
|
|
@ -167,3 +170,46 @@ func TestToFilterArg(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 := 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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue