Skip to content

Commit

Permalink
Not-working test
Browse files Browse the repository at this point in the history
  • Loading branch information
max-dfinity committed Feb 5, 2025
1 parent c1130d3 commit 2151022
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 21 deletions.
11 changes: 9 additions & 2 deletions rs/rosetta-api/icp/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ic_rosetta_api::models::ConstructionDeriveRequestMetadata;
use ic_rosetta_api::models::ConstructionMetadataRequestOptions;
use ic_rosetta_api::models::ConstructionPayloadsRequestMetadata;
use ic_rosetta_api::models::OperationIdentifier;
use ic_rosetta_api::request_types::ChangeAutoStakeMaturityMetadata;
use ic_rosetta_api::request_types::DisburseMetadata;
use ic_rosetta_api::request_types::KeyMetadata;
use ic_rosetta_api::request_types::NeuronIdentifierMetadata;
Expand All @@ -20,6 +19,7 @@ use ic_rosetta_api::request_types::RequestType;
use ic_rosetta_api::request_types::SetDissolveTimestampMetadata;
use ic_rosetta_api::request_types::SpawnMetadata;
use ic_rosetta_api::request_types::StakeMaturityMetadata;
use ic_rosetta_api::request_types::{ChangeAutoStakeMaturityMetadata, ListNeuronsMetadata};
use icp_ledger::AccountIdentifier;
use icrc_ledger_types::icrc1::account::Account;
use icrc_ledger_types::icrc1::account::Subaccount;
Expand Down Expand Up @@ -541,6 +541,7 @@ impl RosettaClient {

pub fn build_list_neurons_operations(
signer_principal: Principal,
page_number: Option<u64>,
) -> anyhow::Result<Vec<Operation>> {
Ok(vec![Operation {
operation_identifier: OperationIdentifier {
Expand All @@ -555,7 +556,11 @@ impl RosettaClient {
)),
amount: None,
coin_change: None,
metadata: None,
metadata: Some(
ListNeuronsMetadata { page_number }
.try_into()
.map_err(|e| anyhow::anyhow!("Failed to convert metadata: {:?}", e))?,
),
}])
}

Expand Down Expand Up @@ -1322,12 +1327,14 @@ impl RosettaClient {
&self,
network_identifier: NetworkIdentifier,
signer_keypair: &T,
page_number: Option<u64>,
) -> anyhow::Result<ConstructionSubmitResponse>
where
T: RosettaSupportedKeyPair,
{
let list_neurons_operations = RosettaClient::build_list_neurons_operations(
signer_keypair.generate_principal_id()?.0,
page_number,
)?;
self.make_submit_and_wait_for_transaction(
signer_keypair,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use proptest::test_runner::Config as TestRunnerConfig;
use proptest::test_runner::TestRunner;
use rosetta_core::objects::ObjectMap;
use rosetta_core::request_types::CallRequest;
use std::time::Duration;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
Expand Down Expand Up @@ -1305,7 +1306,11 @@ fn test_list_neurons() {
let list_neurons_response = ListNeuronsResponse::try_from(
TransactionOperationResults::try_from(
env.rosetta_client
.list_neurons(env.network_identifier.clone(), &(*TEST_IDENTITY).clone())
.list_neurons(
env.network_identifier.clone(),
&(*TEST_IDENTITY).clone(),
None,
)
.await
.unwrap()
.metadata,
Expand All @@ -1321,22 +1326,27 @@ fn test_list_neurons() {
.0;
assert_eq!(list_neurons_response.full_neurons.len(), 0);

// Stake the minimum amount 100 million e8s
let staked_amount = 100_000_000u64;
let neuron_index = 0;
let from_subaccount = [0; 32];
for neuron_index in 0..501 {
// Stake the minimum amount 100 million e8s
let staked_amount = 100_000_000u64;
let from_subaccount = [0; 32];

env.rosetta_client
.create_neuron(
env.network_identifier.clone(),
&(*TEST_IDENTITY).clone(),
RosettaCreateNeuronArgs::builder(staked_amount.into())
.with_from_subaccount(from_subaccount)
.with_neuron_index(neuron_index)
.build(),
)
.await
.unwrap();
env.rosetta_client
.create_neuron(
env.network_identifier.clone(),
&(*TEST_IDENTITY).clone(),
RosettaCreateNeuronArgs::builder(staked_amount.into())
.with_from_subaccount(from_subaccount)
.with_neuron_index(neuron_index)
.build(),
)
.await
.unwrap();
// Otherwise we hit neuron creation limit
env.pocket_ic
.advance_time(Duration::from_secs(60 * 5))
.await;
}

// See if the neuron was created successfully
let agent = get_test_agent(env.pocket_ic.url().unwrap().port().unwrap()).await;
Expand All @@ -1345,7 +1355,11 @@ fn test_list_neurons() {
let neurons_rosetta = ListNeuronsResponse::try_from(
TransactionOperationResults::try_from(
env.rosetta_client
.list_neurons(env.network_identifier.clone(), &(*TEST_IDENTITY).clone())
.list_neurons(
env.network_identifier.clone(),
&(*TEST_IDENTITY).clone(),
None,
)
.await
.unwrap()
.metadata,
Expand All @@ -1360,12 +1374,38 @@ fn test_list_neurons() {
.unwrap()
.0
.full_neurons;
assert_eq!(neurons_governance.len(), 1);
assert_eq!(neurons_rosetta.len(), 1);
assert_eq!(neurons_governance.len(), 500);
assert_eq!(neurons_rosetta.len(), 500);
assert_eq!(
neurons_governance.first().unwrap().id,
neurons_rosetta.first().unwrap().id
);

// Query the second page of results
let neurons_rosetta = ListNeuronsResponse::try_from(
TransactionOperationResults::try_from(
env.rosetta_client
.list_neurons(
env.network_identifier.clone(),
&(*TEST_IDENTITY).clone(),
Some(1),
)
.await
.unwrap()
.metadata,
)
.unwrap()
.operations
.first()
.unwrap()
.clone()
.metadata,
)
.unwrap()
.0
.full_neurons;
// Second page should only have 1 entry
assert_eq!(neurons_rosetta.len(), 1);
});
}

Expand Down

0 comments on commit 2151022

Please sign in to comment.