Skip to content

Commit

Permalink
Minor fix and test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitu33 committed May 12, 2023
1 parent c317805 commit 2d1a0fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion massa-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ transition = { git = "https://github.com/massalabs/transition.git" }

[dev-dependencies]
serial_test = "1.0"
serde_json = "1.0"

# for more information on what are the following features used for, see the cargo.toml at workspace level
[features]
Expand Down
43 changes: 10 additions & 33 deletions massa-models/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl Deserializer<Address> for AddressDeserializer {
Ok((rest, Address::User(addr)))
}
SC_PREFIX => {
let (rest, addr) = self.deserialize(&buffer[1..])?;
let (rest, addr) = self.deserialize(rest)?;
Ok((rest, Address::SC(addr)))
}
_ => Err(nom::Err::Error(E::from_error_kind(buffer, ErrorKind::Eof))),
Expand Down Expand Up @@ -623,7 +623,7 @@ impl Deserializer<UserAddress> for AddressDeserializer {
Ok((rest, UserAddressVariant!["0"](addr)))
}
<UserAddress!["1"]>::VERSION => {
let (rest, addr) = self.deserialize(&buffer[1..])?;
let (rest, addr) = self.deserialize(rest)?;
Ok((rest, UserAddressVariant!["1"](addr)))
}
_ => Err(nom::Err::Error(E::from_error_kind(buffer, ErrorKind::Eof))),
Expand Down Expand Up @@ -705,7 +705,6 @@ pub struct ExecutionAddressCycleInfo {
#[cfg(test)]
mod test {
use super::*;
use serde_json;

#[test]
fn test_address() {
Expand All @@ -721,38 +720,16 @@ mod test {
println!("sc_addr_0: {}", sc_addr_0);
println!("sc_addr_1: {}", sc_addr_1);

let str = "AU12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF";
let addr = Address::from_str(str);
println!("str: {}", str);
assert!(addr.is_ok());
println!("addr: {}", addr.clone().ok().unwrap());
// let v1 = "AU12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF";
let v2 = "AU4cJWyjpBetGwaRqFDXyrHiQuGB3QKrwjzGiGSzQPGeAARB9AY4";
let addr = Address::from_str(v2).unwrap();

let mut buffer: Vec<u8> = vec![];
let _ = AddressSerializer::new().serialize(&addr, &mut buffer);
let (_rest, addr2): (&[u8], Address) = AddressDeserializer::new()
.deserialize::<massa_serialization::DeserializeError>(&buffer)
.unwrap();

let addr_to_ser = addr.clone().ok().unwrap();

let _ = AddressSerializer::new().serialize(&addr_to_ser, &mut buffer);

println!("buffer: {:?}", &buffer);

let addr2: Result<(&[u8], Address), _> =
AddressDeserializer::new()
.deserialize::<massa_serialization::DeserializeError>(&buffer);

assert!(addr2.is_ok());
println!("addr2: {}", addr2.ok().unwrap().1);

let j = serde_json::to_string(&addr.clone().ok().unwrap());

assert!(j.is_ok());

println!("j: {}", j.ok().unwrap());
assert_eq!(addr, addr2);
}
}

// TODO: wanted tests
//
// * Addr ser + deser
// * Addr version in all callers
// * Addr version switch
// * Which places should handle multiple versions at once (all of them?)

0 comments on commit 2d1a0fe

Please sign in to comment.