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

fix(select): handle payment-part address matching #818

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Changes from all 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
37 changes: 33 additions & 4 deletions src/filters/select/eval/address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pallas::ledger::addresses::{Address, ByronAddress, ShelleyAddress, StakeAddress};
use pallas::ledger::addresses::{
Address, ByronAddress, ShelleyAddress, ShelleyDelegationPart, StakeAddress,
};
use serde::{Deserialize, Serialize};
use std::str::FromStr;

Expand Down Expand Up @@ -107,7 +109,11 @@ impl From<Address> for AddressPattern {
},
Address::Shelley(x) => Self {
payment_part: Some(x.payment().to_vec().into()),
delegation_part: Some(x.delegation().to_vec().into()),
delegation_part: match x.delegation() {
ShelleyDelegationPart::Key(x) => Some(x.to_vec().into()),
ShelleyDelegationPart::Script(x) => Some(x.to_vec().into()),
_ => None,
},
..Default::default()
},
}
Expand Down Expand Up @@ -137,9 +143,11 @@ mod tests {
use super::*;

#[test]
fn parse_pattern() {
fn parse_full_address_pattern() {
let pattern = AddressPattern::from_str("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x").unwrap();

dbg!(&pattern);

let expected = AddressPattern {
payment_part: FlexBytes::from_hex(
"9493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e",
Expand All @@ -159,6 +167,27 @@ mod tests {
assert_eq!(pattern, expected);
}

#[test]
fn parse_payment_part_pattern() {
let pattern =
AddressPattern::from_str("addr1w8ax5k9mutg07p2ngscu3chsauktmstq92z9de938j8nqacprc9mw")
.unwrap();

let expected = AddressPattern {
payment_part: FlexBytes::from_hex(
"fa6a58bbe2d0ff05534431c8e2f0ef2cbdc1602a8456e4b13c8f3077",
)
.unwrap()
.into(),

delegation_part: None,

..Default::default()
};

assert_eq!(pattern, expected);
}

#[test]
fn address_match() {
let pattern = |addr: &str| Pattern::from(AddressPattern::from_str(addr).unwrap());
Expand All @@ -171,6 +200,6 @@ mod tests {
let possitives = testing::find_positive_test_vectors(pattern(
"addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8",
));
assert_eq!(possitives, vec![2]);
assert_eq!(possitives, vec![1, 2, 3]);
}
}
Loading