@@ -3677,7 +3677,7 @@ impl RpcClient {
3677
3677
/// Mocks for documentation examples
3678
3678
#[ doc( hidden) ]
3679
3679
pub fn create_rpc_client_mocks ( ) -> crate :: mock_sender:: Mocks {
3680
- let mut mocks = crate :: mock_sender:: Mocks :: default ( ) ;
3680
+ let mut mocks = crate :: mock_sender:: Mocks :: new ( ) ;
3681
3681
3682
3682
let get_account_request = RpcRequest :: GetAccountInfo ;
3683
3683
let get_account_response = serde_json:: to_value ( Response {
@@ -3948,7 +3948,7 @@ mod tests {
3948
3948
pubkey : pubkey. to_string ( ) ,
3949
3949
account : encode_ui_account ( & pubkey, & account, UiAccountEncoding :: Base64 , None , None ) ,
3950
3950
} ;
3951
- let expected_result = vec ! [ ( pubkey, account) ] ;
3951
+ let expected_result = vec ! [ ( pubkey, account. clone ( ) ) ] ;
3952
3952
// Test: without context
3953
3953
{
3954
3954
let mocks: Mocks = [ (
@@ -3987,7 +3987,7 @@ mod tests {
3987
3987
slot : 1 ,
3988
3988
api_version : None ,
3989
3989
} ,
3990
- value : vec ! [ keyed_account] ,
3990
+ value : vec ! [ keyed_account. clone ( ) ] ,
3991
3991
} ) )
3992
3992
. unwrap ( ) ,
3993
3993
) ]
@@ -4012,5 +4012,73 @@ mod tests {
4012
4012
. unwrap ( ) ;
4013
4013
assert_eq ! ( expected_result, result) ;
4014
4014
}
4015
+
4016
+ // Test: Mock with same requests
4017
+ {
4018
+ let expected_result = vec ! [ ( pubkey, account. clone( ) ) , ( pubkey, account. clone( ) ) ] ;
4019
+ let mocks: Mocks = [
4020
+ (
4021
+ RpcRequest :: GetProgramAccounts ,
4022
+ serde_json:: to_value ( OptionalContext :: Context ( Response {
4023
+ context : RpcResponseContext {
4024
+ slot : 1 ,
4025
+ api_version : None ,
4026
+ } ,
4027
+ value : vec ! [ keyed_account. clone( ) ] ,
4028
+ } ) )
4029
+ . unwrap ( ) ,
4030
+ ) ,
4031
+ (
4032
+ RpcRequest :: GetProgramAccounts ,
4033
+ serde_json:: to_value ( OptionalContext :: Context ( Response {
4034
+ context : RpcResponseContext {
4035
+ slot : 1 ,
4036
+ api_version : None ,
4037
+ } ,
4038
+ value : vec ! [ keyed_account. clone( ) ] ,
4039
+ } ) )
4040
+ . unwrap ( ) ,
4041
+ ) ,
4042
+ ]
4043
+ . into_iter ( )
4044
+ . collect ( ) ;
4045
+ let rpc_client = RpcClient :: new_mock_with_mocks ( "mock_client" . to_string ( ) , mocks) ;
4046
+ let mut result1 = rpc_client
4047
+ . get_program_accounts_with_config (
4048
+ & program_id,
4049
+ RpcProgramAccountsConfig {
4050
+ filters : None ,
4051
+ account_config : RpcAccountInfoConfig {
4052
+ encoding : Some ( UiAccountEncoding :: Base64 ) ,
4053
+ data_slice : None ,
4054
+ commitment : None ,
4055
+ min_context_slot : None ,
4056
+ } ,
4057
+ with_context : Some ( true ) ,
4058
+ sort_results : None ,
4059
+ } ,
4060
+ )
4061
+ . unwrap ( ) ;
4062
+
4063
+ let result2 = rpc_client
4064
+ . get_program_accounts_with_config (
4065
+ & program_id,
4066
+ RpcProgramAccountsConfig {
4067
+ filters : None ,
4068
+ account_config : RpcAccountInfoConfig {
4069
+ encoding : Some ( UiAccountEncoding :: Base64 ) ,
4070
+ data_slice : None ,
4071
+ commitment : None ,
4072
+ min_context_slot : None ,
4073
+ } ,
4074
+ with_context : Some ( true ) ,
4075
+ sort_results : None ,
4076
+ } ,
4077
+ )
4078
+ . unwrap ( ) ;
4079
+
4080
+ result1. extend ( result2) ;
4081
+ assert_eq ! ( expected_result, result1) ;
4082
+ }
4015
4083
}
4016
4084
}
0 commit comments