@@ -4,7 +4,7 @@ use sha2::{
44} ;
55use thiserror:: Error ;
66
7- use layer_std:: AccountId ;
7+ use layer_std:: { AccountId , VALID_ADDR_LENGTH } ;
88
99use crate :: PulsarError ;
1010
@@ -23,7 +23,7 @@ pub fn build_instantiate_address(
2323 prehash. extend ( code_id. to_be_bytes ( ) ) ;
2424 prehash. extend ( counter. to_be_bytes ( ) ) ;
2525 let raw = Sha256 :: digest ( prehash) ;
26- Ok ( AccountId :: new ( & raw ) ?)
26+ Ok ( AccountId :: new ( & raw [ .. VALID_ADDR_LENGTH ] ) ?)
2727}
2828
2929/// We should match the reference wasmd/Go implementation for compatibility with cosmos-sdk:
@@ -58,7 +58,7 @@ pub fn build_instantiate_2_address(
5858 key. extend_from_slice ( & ( msg. len ( ) as u64 ) . to_be_bytes ( ) ) ;
5959 key. extend_from_slice ( msg) ;
6060 let address_data = hash ( "module" , & key) ;
61- Ok ( AccountId :: new ( & address_data) ?)
61+ Ok ( AccountId :: new ( & address_data[ .. VALID_ADDR_LENGTH ] ) ?)
6262}
6363
6464/// This must be compatible with the wasmd calls, and thus map to address.Module in Cosmos SDK.
@@ -108,41 +108,31 @@ mod tests {
108108 let msg2: & [ u8 ] = b"{}" ;
109109 let msg3: & [ u8 ] = b"{\" some\" :123,\" structure\" :{\" nested\" :[\" ok\" ,true]}}" ;
110110
111+ // TODO: reduce all expected to 40 chars, not 64 chars
112+
111113 // No msg
112- let expected = AccountId :: new ( & hex ! (
113- "5e865d3e45ad3e961f77fd77d46543417ced44d924dc3e079b5415ff6775f847"
114- ) )
115- . unwrap ( ) ;
114+ let expected = AccountId :: new ( & hex ! ( "5e865d3e45ad3e961f77fd77d46543417ced44d9" ) ) . unwrap ( ) ;
116115 assert_eq ! (
117116 build_instantiate_2_address( & checksum1, & creator1, & salt1, msg1) . unwrap( ) ,
118117 expected
119118 ) ;
120119
121120 // With msg
122- let expected = AccountId :: new ( & hex ! (
123- "0995499608947a5281e2c7ebd71bdb26a1ad981946dad57f6c4d3ee35de77835"
124- ) )
125- . unwrap ( ) ;
121+ let expected = AccountId :: new ( & hex ! ( "0995499608947a5281e2c7ebd71bdb26a1ad9819" ) ) . unwrap ( ) ;
126122 assert_eq ! (
127123 build_instantiate_2_address( & checksum1, & creator1, & salt1, msg2) . unwrap( ) ,
128124 expected
129125 ) ;
130126
131127 // Long msg
132- let expected = AccountId :: new ( & hex ! (
133- "83326e554723b15bac664ceabc8a5887e27003abe9fbd992af8c7bcea4745167"
134- ) )
135- . unwrap ( ) ;
128+ let expected = AccountId :: new ( & hex ! ( "83326e554723b15bac664ceabc8a5887e27003ab" ) ) . unwrap ( ) ;
136129 assert_eq ! (
137130 build_instantiate_2_address( & checksum1, & creator1, & salt1, msg3) . unwrap( ) ,
138131 expected
139132 ) ;
140133
141134 // Long salt
142- let expected = AccountId :: new ( & hex ! (
143- "9384c6248c0bb171e306fd7da0993ec1e20eba006452a3a9e078883eb3594564"
144- ) )
145- . unwrap ( ) ;
135+ let expected = AccountId :: new ( & hex ! ( "9384c6248c0bb171e306fd7da0993ec1e20eba00" ) ) . unwrap ( ) ;
146136 assert_eq ! (
147137 build_instantiate_2_address( & checksum1, & creator1, & salt2, b"" ) . unwrap( ) ,
148138 expected
0 commit comments