Skip to content

Commit

Permalink
Fix SpacetimeType for Address (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim authored Aug 22, 2023
1 parent 0badd5d commit 8fd6958
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions crates/lib/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Address {
}
}

impl_serialize!([] Address, (self, ser) =>self.0.to_be_bytes().serialize(ser));
impl_serialize!([] Address, (self, ser) => self.0.to_be_bytes().serialize(ser));
impl_deserialize!([] Address, de => <[u8; 16]>::deserialize(de).map(|v| Self(u128::from_be_bytes(v))));

#[cfg(feature = "serde")]
Expand All @@ -82,7 +82,7 @@ impl<'de> serde::Deserialize<'de> for Address {
}
}

impl_st!([] Address, _ts => sats::AlgebraicType::U128);
impl_st!([] Address, _ts => sats::AlgebraicType::bytes());

#[cfg(test)]
mod tests {
Expand All @@ -108,26 +108,4 @@ mod tests {
assert_eq!(addr, de);
}
}

// At some point, using `Address` in a spacetimedb table was not working
// (buffer length errors were thrown when deserializing). This test exists
// to guard against a regression.
#[test]
fn test_addr_column_rountrip() {
use spacetimedb_bindings_macro::{Deserialize, Serialize};

#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
struct MyTable {
name: String,
addr: Address,
}

let val = MyTable {
name: "example.com".into(),
addr: Address(rand::random()),
};
let ser = sats::bsatn::to_vec(&val).unwrap();
let de = sats::bsatn::from_slice(&ser).unwrap();
assert_eq!(val, de);
}
}

0 comments on commit 8fd6958

Please sign in to comment.