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

Restore order for value_transfers and messages #1525

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
21 changes: 17 additions & 4 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,25 @@ mod fast {
let value_transfers_charlie = &recipient
.messages_containing(Some(&charlie.encode(&recipient.config().chain)))
.await;
let all_vts = &recipient.messages_containing(None).await;

println!("ALL VTS");
dbg!(all_vts);
let all_vts = &recipient.value_transfers().await;
let all_messages = &recipient.messages_containing(None).await;

assert_eq!(value_transfers_bob.0.len(), 3);
assert_eq!(value_transfers_charlie.0.len(), 2);

// Also asserting the order now (sorry juanky)
// ALL MESSAGES (First one should be the oldest one)
assert!(all_messages
.0
.windows(2)
.all(|pair| { pair[0].blockheight() <= pair[1].blockheight() }));

// ALL VTS (First one should be the most recent one)
assert!(all_vts
.0
.windows(2)
.all(|pair| { pair[0].blockheight() >= pair[1].blockheight() }));
}

pub mod tex {
Expand Down Expand Up @@ -419,7 +432,7 @@ mod fast {
let val_tranfers = dbg!(sender.value_transfers().await);
// This fails, as we don't scan sends to tex correctly yet
assert_eq!(
val_tranfers.0[2].recipient_address().unwrap(),
val_tranfers.0[0].recipient_address().unwrap(),
tex_addr_from_first.encode()
);
}
Expand Down
3 changes: 1 addition & 2 deletions zingolib/src/lightclient/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ impl LightClient {
pub async fn messages_containing(&self, filter: Option<&str>) -> ValueTransfers {
let mut value_transfers = self.value_transfers().await.0;
value_transfers.reverse();

match filter {
Some(s) => {
value_transfers.retain(|vt| {
Expand Down Expand Up @@ -303,7 +302,7 @@ impl LightClient {
let mut value_transfers: Vec<ValueTransfer> = Vec::new();
let transaction_summaries = self.transaction_summaries().await;

for tx in transaction_summaries.iter() {
AloeareV marked this conversation as resolved.
Show resolved Hide resolved
for tx in transaction_summaries.iter().rev() {
match tx.kind() {
TransactionKind::Sent(SendType::Send) => {
// create 1 sent value transfer for each non-self recipient address
Expand Down
16 changes: 9 additions & 7 deletions zingolib/src/testutils/chain_generics/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ where
false,
)
.await;

assert_eq!(sender.value_transfers().await.0.len(), 3);
assert_eq!(
sender.value_transfers().await.0[0].kind(),
ValueTransferKind::Received
);
assert_eq!(
sender.value_transfers().await.0[1].kind(),
ValueTransferKind::Sent(SentValueTransfer::Send)
);
assert_eq!(
sender.value_transfers().await.0[2].kind(),
sender.value_transfers().await.0[1].kind(),
ValueTransferKind::Sent(SentValueTransfer::SendToSelf(
SelfSendValueTransfer::MemoToSelf
))
);
assert_eq!(
sender.value_transfers().await.0[2].kind(),
ValueTransferKind::Received
);
assert_eq!(recipient.value_transfers().await.0.len(), 1);
assert_eq!(
recipient.value_transfers().await.0[0].kind(),
Expand All @@ -85,9 +86,10 @@ where
false,
)
.await;

assert_eq!(sender.value_transfers().await.0.len(), 4);
assert_eq!(
sender.value_transfers().await.0[3].kind(),
sender.value_transfers().await.0[0].kind(),
ValueTransferKind::Sent(SentValueTransfer::SendToSelf(SelfSendValueTransfer::Basic))
);

Expand All @@ -96,7 +98,7 @@ where
.unwrap();
assert_eq!(sender.value_transfers().await.0.len(), 5);
assert_eq!(
sender.value_transfers().await.0[4].kind(),
sender.value_transfers().await.0[0].kind(),
ValueTransferKind::Sent(SentValueTransfer::SendToSelf(SelfSendValueTransfer::Shield))
);
}
Expand Down
Loading