Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ICP-Rosetta): FI-1479: fix search transactions endpoint #1585

Merged
merged 30 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f5188da
add minter
NikolasHai Sep 12, 2024
24f8133
move lad testing
NikolasHai Sep 12, 2024
d346540
Merge branch 'master' of github.com:dfinity/ic
NikolasHai Sep 13, 2024
34dce8f
Merge branch 'master' into FI-1486-move-load-from-store-test
NikolasHai Sep 18, 2024
5240c8d
add offline option
NikolasHai Sep 19, 2024
dbed16e
add load from store test
NikolasHai Sep 19, 2024
3e44059
Merge branch 'master' of github.com:dfinity/ic
NikolasHai Sep 19, 2024
024c27a
Merge branch 'master' into FI-1486-move-load-from-store-test
NikolasHai Sep 19, 2024
29cf072
remove tests that load from storage
NikolasHai Sep 19, 2024
d4da591
fmt
NikolasHai Sep 19, 2024
e7a7832
fmt
NikolasHai Sep 19, 2024
3520e3a
add minter
NikolasHai Sep 12, 2024
5cfc822
fmt
NikolasHai Sep 19, 2024
9865ffc
fmt
NikolasHai Sep 19, 2024
a13019f
Merge branch 'master' into FI-1486-move-load-from-store-test
NikolasHai Sep 19, 2024
eab8801
fmt
NikolasHai Sep 19, 2024
465f6ad
fix search transaction endpoint
NikolasHai Sep 19, 2024
ee02218
add uniqueness check
NikolasHai Sep 19, 2024
c74171c
fix traversal check
NikolasHai Sep 19, 2024
22dca24
fix length test
NikolasHai Sep 19, 2024
e77f32d
Merge branch 'master' into FI-1479-fix-search-transactions-endpoint
NikolasHai Sep 23, 2024
29553e4
ran buildifier
NikolasHai Sep 23, 2024
850a848
merged with master
NikolasHai Sep 23, 2024
c334f24
fmt
NikolasHai Sep 23, 2024
e5176f6
Update rs/rosetta-api/tests/system_tests/system_tests.rs
NikolasHai Sep 24, 2024
3a4e5ba
Update rs/rosetta-api/src/request_handler.rs
NikolasHai Sep 24, 2024
663b089
Update rs/rosetta-api/tests/system_tests/test_cases/search_transactio…
NikolasHai Sep 24, 2024
26eac01
add check for num operations
NikolasHai Sep 24, 2024
78a3a76
Merge branch 'FI-1479-fix-search-transactions-endpoint' of github.com…
NikolasHai Sep 24, 2024
bb3429c
fmt
NikolasHai Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rs/rosetta-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ reqwest = { workspace = true }
rolling-file = { workspace = true }
rosetta-core = { path = "rosetta_core" }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_cbor = { workspace = true }
serde_json = { workspace = true }
strum = { workspace = true }
Expand All @@ -52,7 +53,6 @@ tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
rusqlite = { version = "~0.28.0", features = ["bundled"] }
NikolasHai marked this conversation as resolved.
Show resolved Hide resolved
serde_bytes = { workspace = true }

[dev-dependencies]
futures = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rs/rosetta-api/src/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ impl RosettaRequestHandler {
// Sort the transactions by block index in descending order
transactions.sort_by(|a, b| b.block_identifier.index.cmp(&a.block_identifier.index));

// Is rosetta blocks is empty that means the entire blockchain was traversed but no transactions were found that match the search criteria
// If rosetta blocks is empty that means the entire blockchain was traversed but no transactions were found that match the search criteria
let last_traversed_block_index = blocks.iter().map(|block| block.index).min().unwrap_or(0);
let num_fetched_transactions = transactions.len();

Expand Down
16 changes: 0 additions & 16 deletions rs/rosetta-api/tests/system_tests/system_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,3 @@ fn smoke_test() {
assert_eq!(res.network_identifiers.len(), 1);
});
}

#[test]
fn test_cc() {
println!(
"Acc: {:?}",
icp_ledger::AccountIdentifier::new(
ic_types::PrincipalId(
candid::Principal::from_text(
"iowfl-yzooa-br3dt-77erl-nlm7f-kplhq-php75-hw3an-aeqn2-swh4t-3qe",
)
.unwrap(),
),
None,
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use proptest::test_runner::TestRunner;
use rosetta_core::identifiers::TransactionIdentifier;
use rosetta_core::objects::BlockTransaction;
use rosetta_core::request_types::SearchTransactionsRequest;
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use std::time::SystemTime;
Expand Down Expand Up @@ -313,8 +314,10 @@ fn test_search_transactions_by_account() {
// Make sure every fetched transaction is unique
assert_eq!(
result.len(),
result.into_iter().collect::<HashSet<_>>().len()
result.clone().into_iter().collect::<HashSet<_>>().len()
);

assert!(!result.is_empty());
NikolasHai marked this conversation as resolved.
Show resolved Hide resolved
}

search_transactions_request.account_identifier = Some(
Expand Down Expand Up @@ -366,20 +369,34 @@ fn test_search_transactions_by_operation_type() {
.await;

if !args_with_caller.is_empty() {
let operations = vec![
"TRANSFER".to_string(),
"MINT".to_string(),
"BURN".to_string(),
"APPROVE".to_string(),
];

let mut search_transactions_request =
SearchTransactionsRequest::builder(env.network_identifier.clone())
.build();

for operation in operations.into_iter() {
let icp_blocks = query_encoded_blocks(
&get_test_agent(env.pocket_ic.url().unwrap().port().unwrap()).await,
0,
u64::MAX,
)
.await
.blocks
.into_iter()
.map(|block| icp_ledger::Block::decode(block).unwrap())
.collect::<Vec<icp_ledger::Block>>();
let operation_counts =
icp_blocks.iter().fold(HashMap::new(), |mut ops, s| {
let ops_type = match s.transaction.operation {
icp_ledger::Operation::Transfer { .. } => "Transfer",
icp_ledger::Operation::Mint { .. } => "Mint",
icp_ledger::Operation::Burn { .. } => "Burn",
icp_ledger::Operation::Approve { .. } => "Approve",
}
.to_string();
*ops.entry(ops_type).or_insert(0) += 1;
ops
});
for operation in operation_counts.keys().clone() {
// We make sure that the service returns the correct number of transactions for each account
NikolasHai marked this conversation as resolved.
Show resolved Hide resolved
search_transactions_request.type_ = Some(operation);
search_transactions_request.type_ = Some(operation.clone());

let result = traverse_all_transactions(
&env.rosetta_client,
Expand All @@ -389,17 +406,27 @@ fn test_search_transactions_by_operation_type() {
assert!(result.clone().into_iter().all(|block_transaction| {
block_transaction.transaction.operations.into_iter().any(
|operation| {
operation.type_
== search_transactions_request.type_.clone().unwrap()
// ICP Rosetta returns Transfers as Transactions and not as Transfer
if operation.type_ == "TRANSACTION" {
search_transactions_request.type_
== Some("Transfer".to_string())
} else {
search_transactions_request
.type_
.clone()
.map(|t| t.to_uppercase())
== Some(operation.type_)
}
},
)
}));

// Make sure every fetched transaction is unique
assert_eq!(
result.len(),
result.into_iter().collect::<HashSet<_>>().len()
result.clone().into_iter().collect::<HashSet<_>>().len()
);
assert_eq!(result.len(), *operation_counts.get(operation).unwrap());
NikolasHai marked this conversation as resolved.
Show resolved Hide resolved
}

search_transactions_request.type_ = Some("INVALID_OPERATION".to_string());
Expand All @@ -408,7 +435,7 @@ fn test_search_transactions_by_operation_type() {
search_transactions_request.clone(),
)
.await;
// If the account does not exist the service should return an empty list
// If the operation type does not exist the service should return an empty list
assert_eq!(result.len(), 0);
}
});
Expand Down
Loading