coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

Add support for mock RPC Client in anchor_client #3050

Open cryptopapi997 opened 6 days ago

cryptopapi997 commented 6 days ago

Solana client has a a feature that allows you to generate and use a mock rpc client, which is supremely useful when doing unit tests. Anchor client (as far as I can tell) doesn't support this when using RequestBuilder and instead always uses the passed cluster under the hood:

(https://github.com/coral-xyz/anchor/blob/master/client/src/lib.rs#L641) (https://github.com/coral-xyz/anchor/blob/master/client/src/lib.rs#L650) ... and more

It would be cool if we could pass in an RPCClient instead of a cluster when creating a client to allow for mocking.

acheroncrypto commented 6 days ago

I agree, mocking is useful, and this would be a nice feature to have.

cryptopapi997 commented 6 days ago

Sweet, working on a PR rn.

cryptopapi997 commented 5 days ago

Done, feel free to take a look @acheroncrypto https://github.com/coral-xyz/anchor/pull/3053/