Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Nov 9, 2022
1 parent a872bbe commit eb7c89f
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions rpc-client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4292,4 +4292,83 @@ mod tests {
assert_eq!(expected_minimum_delegation, actual_minimum_delegation);
}
}

#[test]
fn test_get_program_accounts_with_config() {
let program_id = Pubkey::new_unique();
let pubkey = Pubkey::new_unique();
let account = Account {
lamports: 1_000_000,
data: vec![],
owner: program_id,
executable: false,
rent_epoch: 0,
};
let keyed_account = RpcKeyedAccount {
pubkey: pubkey.to_string(),
account: UiAccount::encode(&pubkey, &account, UiAccountEncoding::Base64, None, None),
};
let expected_result = vec![(pubkey, account)];
// Test: without context
{
let mocks: Mocks = [(
RpcRequest::GetProgramAccounts,
serde_json::to_value(OptionalContext::NoContext(vec![keyed_account.clone()]))
.unwrap(),
)]
.into_iter()
.collect();
let rpc_client = RpcClient::new_mock_with_mocks("mock_client".to_string(), mocks);
let result = rpc_client
.get_program_accounts_with_config(
&program_id,
RpcProgramAccountsConfig {
filters: None,
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: None,
},
)
.unwrap();
assert_eq!(expected_result, result);
}

// Test: with context
{
let mocks: Mocks = [(
RpcRequest::GetProgramAccounts,
serde_json::to_value(OptionalContext::Context(Response {
context: RpcResponseContext {
slot: 1,
api_version: None,
},
value: vec![keyed_account],
}))
.unwrap(),
)]
.into_iter()
.collect();
let rpc_client = RpcClient::new_mock_with_mocks("mock_client".to_string(), mocks);
let result = rpc_client
.get_program_accounts_with_config(
&program_id,
RpcProgramAccountsConfig {
filters: None,
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
data_slice: None,
commitment: None,
min_context_slot: None,
},
with_context: Some(true),
},
)
.unwrap();
assert_eq!(expected_result, result);
}
}
}

0 comments on commit eb7c89f

Please sign in to comment.