mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
Update ethclient_test.go
This commit is contained in:
parent
c0e33ee86f
commit
bb92b1b327
1 changed files with 43 additions and 0 deletions
|
|
@ -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 {
|
func newCanceledContext() context.Context {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue