Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Migrate to use BagOfBytes: NonFungibleLocalId::Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Feb 7, 2024
1 parent 1e07ae6 commit dff7f4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions profile/src/v100/address/non_fungible_local_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use radix_engine_common::data::scrypto::model::NonFungibleLocalId as NativeNonFu
pub enum NonFungibleLocalId {
Integer { value: u64 },
Str { value: String },
Bytes { value: Vec<u8> },
Bytes { value: BagOfBytes },
Ruid { value: Vec<u8> },
}

Expand All @@ -32,7 +32,7 @@ impl From<NativeNonFungibleLocalId> for NonFungibleLocalId {
value: value.value(),
},
NativeNonFungibleLocalId::Bytes(value) => Self::Bytes {
value: value.value().to_vec(),
value: value.value().to_vec().into(),
},
NativeNonFungibleLocalId::RUID(value) => Self::Ruid {
value: value.value().to_vec(),
Expand All @@ -48,7 +48,7 @@ impl TryFrom<NonFungibleLocalId> for NativeNonFungibleLocalId {
match value {
NonFungibleLocalId::Str { value } => Self::string(value)
.map_err(|_| Self::Error::InvalidNonFungibleLocalIDString),
NonFungibleLocalId::Bytes { value } => Self::bytes(value)
NonFungibleLocalId::Bytes { value } => Self::bytes(value.to_vec())
.map_err(|_| Self::Error::InvalidNonFungibleLocalIDBytes),
NonFungibleLocalId::Ruid { value } => value
.try_into()
Expand Down Expand Up @@ -112,7 +112,10 @@ mod tests {
#[test]
fn invalid_local_id_bytes() {
assert_eq!(
NonFungibleLocalId::Bytes { value: Vec::new() }.try_into(),
NonFungibleLocalId::Bytes {
value: BagOfBytes::new()
}
.try_into(),
Err::<NativeNonFungibleLocalId, _>(
CommonError::InvalidNonFungibleLocalIDBytes
)
Expand Down Expand Up @@ -141,7 +144,7 @@ mod tests {
fn from_native_bytes() {
let bytes = [0xab; 64];
let non_native = NonFungibleLocalId::Bytes {
value: bytes.clone().to_vec(),
value: bytes.clone().to_vec().into(),
};
let native = NativeNonFungibleLocalId::Bytes(
BytesNonFungibleLocalId::new(bytes.clone().to_vec()).unwrap(),
Expand Down
10 changes: 10 additions & 0 deletions profile/src/wallet_kit_common/types/bag_of_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use radix_engine_common::crypto::{Hash, IsHash};
Clone,
PartialEq,
Eq,
Default,
PartialOrd,
Ord,
Hash,
Expand Down Expand Up @@ -121,6 +122,9 @@ pub fn bag_of_bytes_append_cafe(to: &BagOfBytes) -> BagOfBytes {
}

impl BagOfBytes {
pub fn new() -> Self {
Vec::new().into()
}
pub fn to_hex(&self) -> String {
hex_encode(self.bytes())
}
Expand Down Expand Up @@ -304,6 +308,12 @@ mod tests {
assert_eq!(BagOfBytes::placeholder().len(), 32);
}

#[test]
fn default_is_empty() {
assert_eq!(BagOfBytes::default(), BagOfBytes::new());
assert_eq!(BagOfBytes::default().is_empty(), true);
}

#[test]
fn is_empty() {
assert_eq!(BagOfBytes::placeholder().is_empty(), false);
Expand Down

0 comments on commit dff7f4e

Please sign in to comment.