diff --git a/packages/std/src/mock.rs b/packages/std/src/mock.rs index 01aa44b1f7..cb0e572e1b 100644 --- a/packages/std/src/mock.rs +++ b/packages/std/src/mock.rs @@ -88,11 +88,13 @@ impl Api for MockApi { } let mut out = Vec::from(human.as_str()); - let append = self.canonical_length - out.len(); - if append > 0 { - out.extend(vec![0u8; append]); + // pad to canonical_length wil NULL bytes + out.resize(self.canonical_length, 0x00); + // shuffle to destroy the most obvious structure (https://github.com/CosmWasm/cosmwasm/issues/552) + for _ in 0..18 { + out = riffle_shuffle(&out); } - Ok(CanonicalAddr(Binary(out))) + Ok(out.into()) } fn human_address(&self, canonical: &CanonicalAddr) -> StdResult { @@ -102,16 +104,16 @@ impl Api for MockApi { )); } - // remove trailing 0's (TODO: fix this - but fine for first tests) - let trimmed: Vec = canonical - .as_slice() - .iter() - .cloned() - .filter(|&x| x != 0) - .collect(); + let mut tmp: Vec = canonical.clone().into(); + // Shuffle two more times which restored the original value (24 elements are back to original after 20 rounds) + for _ in 0..2 { + tmp = riffle_shuffle(&tmp); + } + // Remove NULL bytes (i.e. the padding) + let trimmed = tmp.into_iter().filter(|&x| x != 0x00).collect(); // decode UTF-8 bytes into string let human = String::from_utf8(trimmed).map_err(StdError::invalid_utf8)?; - Ok(HumanAddr(human)) + Ok(human.into()) } fn debug(&self, message: &str) {