-2

when i write a testing for testing ethclient method based on go-ethereum codebase, i can't easily mock a ethclient, anyone can do me a favor? https://github.com/ethereum/go-ethereum/pull/18422/files

func TestClient_StorageAt(t *testing.T) {
var client *rpc.Client
type fields struct {
    c *rpc.Client
}
type args struct {
    ctx         context.Context
    account     common.Address
    key         common.Hash
    blockNumber *big.Int
}
tests := []struct {
    name    string
    fields  fields
    args    args
    want    []byte
    wantErr bool
}{
    {
        "call StorageAt at future block",
        fields{
            client,
        },
        args{
            context.Background(),
            common.HexToAddress("0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2"),
            common.HexToHash("0x0"),
            big.NewInt(-1),
        },
        []byte{0},
        true,
    },
}
for _, tt := range tests {
    t.Run(tt.name, func(t *testing.T) {
        ec := &Client{
            c: tt.fields.c,
        }
        got, err := ec.StorageAt(tt.args.ctx, tt.args.account, tt.args.key, tt.args.blockNumber)
        if (err != nil) != tt.wantErr {
            t.Errorf("Client.StorageAt() error = %v, wantErr %v", err, tt.wantErr)
            return
        }
        if !reflect.DeepEqual(got, tt.want) {
            t.Errorf("Client.StorageAt() = %v, want %v", got, tt.want)
        }
    })
}

}

i have try some methods in rpc module, but can't success.

This question had a bounty worth +50 reputation from xds2000 that ended 9 hours ago. Grace period ends in 14 hours

Looking for an answer drawing from credible and/or official sources.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.