Skip to content

Commit

Permalink
Avoid the usage of CanonicalAddr.0
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Oct 18, 2022
1 parent 013fda5 commit e6033ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/std/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ mod tests {

#[test]
fn canonical_addr_implements_hash() {
let alice1 = CanonicalAddr(Binary::from([0, 187, 61, 11, 250, 0]));
let alice1 = CanonicalAddr::from([0, 187, 61, 11, 250, 0]);
let mut hasher = DefaultHasher::new();
alice1.hash(&mut hasher);
let alice1_hash = hasher.finish();

let alice2 = CanonicalAddr(Binary::from([0, 187, 61, 11, 250, 0]));
let alice2 = CanonicalAddr::from([0, 187, 61, 11, 250, 0]);
let mut hasher = DefaultHasher::new();
alice2.hash(&mut hasher);
let alice2_hash = hasher.finish();

let bob = CanonicalAddr(Binary::from([16, 21, 33, 0, 255, 9]));
let bob = CanonicalAddr::from([16, 21, 33, 0, 255, 9]);
let mut hasher = DefaultHasher::new();
bob.hash(&mut hasher);
let bob_hash = hasher.finish();
Expand All @@ -521,9 +521,9 @@ mod tests {
/// This requires Hash and Eq to be implemented
#[test]
fn canonical_addr_can_be_used_in_hash_set() {
let alice1 = CanonicalAddr(Binary::from([0, 187, 61, 11, 250, 0]));
let alice2 = CanonicalAddr(Binary::from([0, 187, 61, 11, 250, 0]));
let bob = CanonicalAddr(Binary::from([16, 21, 33, 0, 255, 9]));
let alice1 = CanonicalAddr::from([0, 187, 61, 11, 250, 0]);
let alice2 = CanonicalAddr::from([0, 187, 61, 11, 250, 0]);
let bob = CanonicalAddr::from([16, 21, 33, 0, 255, 9]);

let mut set = HashSet::new();
set.insert(alice1.clone());
Expand Down
3 changes: 1 addition & 2 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::vec::Vec;

use crate::addresses::{Addr, CanonicalAddr};
use crate::binary::Binary;
use crate::errors::{RecoverPubkeyError, StdError, StdResult, SystemError, VerificationError};
use crate::import_helpers::{from_high_half, from_low_half};
use crate::memory::{alloc, build_region, consume_region, Region};
Expand Down Expand Up @@ -224,7 +223,7 @@ impl Api for ExternalApi {
}

let out = unsafe { consume_region(canon) };
Ok(CanonicalAddr(Binary(out)))
Ok(CanonicalAddr::from(out))
}

fn addr_humanize(&self, canonical: &CanonicalAddr) -> StdResult<Addr> {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ mod tests {
#[should_panic(expected = "length not correct")]
fn addr_humanize_input_length() {
let api = MockApi::default();
let input = CanonicalAddr(Binary(vec![61; 11]));
let input = CanonicalAddr::from(vec![61; 11]);
api.addr_humanize(&input).unwrap();
}

Expand Down

0 comments on commit e6033ae

Please sign in to comment.