Skip to content

Commit d21bca1

Browse files
committed
Fixed many tests - fails on app, cosmos, golem
1 parent 9cd4170 commit d21bca1

9 files changed

Lines changed: 20 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ tokio-stream = { version = "0.1.15", default-features = false }
6363
futures = { version = "0.3.30", default-features = false }
6464

6565
cosmrs = { version = "0.13.0", default-features = false, features = ["cosmwasm"] }
66-
cosmos-sdk-proto = { version = "0.18.0", default-features = false }
66+
cosmos-sdk-proto = { version = "0.18.0", default-features = false, features = ["cosmwasm"] }
6767
cw-orch-core = { version = "1"}
6868
abstract-cw-multi-test = { version = "1", default-features = false }
6969

packages/app/src/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ mod tests {
510510
// run finalize_block
511511
// query account + balances for update
512512
fn transaction_workflow<T: PersistentStorage + 'static>(storage: T) {
513+
// TODO: convert bech32 to 0x checksummed (make script)
513514
let sender = must_id("slay3r1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmvk3r3j");
514515
let recipient = must_id("slay3r1y5hl7x8hxl72dc9gu920eaz6l7vhl0luu6s70h");
515516
let denom: &str = "uslay";

packages/app/src/wasm/utils.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use sha2::{
44
};
55
use thiserror::Error;
66

7-
use layer_std::AccountId;
7+
use layer_std::{AccountId, VALID_ADDR_LENGTH};
88

99
use 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

packages/app/src/wasm/vm/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ mod tests {
464464
assert_eq!(res.messages.len(), 0);
465465
assert_eq!(res.events.len(), 0);
466466
assert_eq!(res.attributes.len(), 0);
467-
assert_eq!(gas_used, 57);
467+
assert_eq!(gas_used, 56);
468468

469469
// query the state was written - token_info and total supply
470470
let num = writer
@@ -662,7 +662,7 @@ mod tests {
662662
let cw20::AllAccountsResponse { accounts } = from_json(res).unwrap();
663663
assert_eq!(
664664
accounts,
665-
vec![two.to_string(), one.to_string(), three.to_string()]
665+
vec![one.to_string(), two.to_string(), three.to_string()]
666666
);
667667
}
668668

packages/cosmos/src/tx.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ mod test {
185185
Coin,
186186
};
187187

188-
use layer_std::{AccountId, BankMsg, PubKey, DEFAULT_BECH32_PREFIX};
188+
use layer_std::{AccountId, BankMsg, PubKey};
189+
190+
const DEFAULT_BECH32_PREFIX: &str = "slay3r";
189191

190192
#[test]
191193
fn happy_path_tx_parsing() {

packages/std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ripemd = { workspace = true }
1919
tracing = { workspace = true }
2020
bytes = { workspace = true }
2121
hex = { workspace = true }
22-
bech32 = { version = "0.9.1", default-features = false }
2322
chrono = { version = "0.4.19", default-features = false, features = ["std"] }
2423
derivative = "2.2.0"
2524

packages/std/src/account_id.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@ use std::fmt::{Debug, Display, Formatter};
22
use std::ops::Deref;
33

44
use ::cosmwasm_schema::serde;
5-
// use bech32::{self, Error as Bech32Error, FromBase32, ToBase32, Variant};
65
use alloy_primitives::{Address, AddressError};
76

87
use cosmwasm_std::{Addr, StdResult};
98
use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey};
109
use thiserror::Error;
1110

12-
// pub const ENV_BECH32_PREFIX: Option<&'static str> = std::option_env!("SLAY_BECH32");
13-
// pub const DEFAULT_BECH32_PREFIX: &str = "slay3r";
14-
1511
/// Valid lengths of decoded addresses
16-
pub const VALID_ADDR_LENGTH: [usize; 1] = [20usize];
17-
// pub const VALID_ADDR_LENGTH: [usize; 2] = [20usize, 32usize];
18-
19-
// fn bech32_prefix() -> &'static str {
20-
// ENV_BECH32_PREFIX.unwrap_or(DEFAULT_BECH32_PREFIX)
21-
// }
12+
pub const VALID_ADDR_LENGTH: usize = 20;
2213

2314
// Note: this is expanded cw_serde macro minus the Debug implementation, as we want to use Display there
2415
#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::cosmwasm_schema::schemars::JsonSchema)]
@@ -117,7 +108,7 @@ pub fn must_id(str: &str) -> AccountId {
117108
impl AccountId {
118109
/// This takes
119110
pub fn new(raw: &[u8]) -> Result<Self, AccountIdError> {
120-
if !VALID_ADDR_LENGTH.contains(&raw.len()) {
111+
if raw.len() != VALID_ADDR_LENGTH {
121112
Err(AccountIdError::InvalidLength(raw.len()))
122113
} else {
123114
Ok(AccountId(raw.to_vec()))
@@ -134,7 +125,7 @@ impl AccountId {
134125
pub fn unchecked(name: &str) -> Self {
135126
// pad to valid length
136127
let mut v = name.as_bytes().to_vec();
137-
v.resize(VALID_ADDR_LENGTH[0], 0u8);
128+
v.resize(VALID_ADDR_LENGTH, 0u8);
138129
AccountId(v)
139130
}
140131

packages/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod time;
99
mod tx;
1010
mod utils;
1111

12-
pub use account_id::{must_id, AccountId, AccountIdError};
12+
pub use account_id::{must_id, AccountId, AccountIdError, VALID_ADDR_LENGTH};
1313
use cosmwasm_std::Binary;
1414
pub use encode::{CoinEncode, HexEncode};
1515
pub use gas::{GasError, GasMeter, GasResult};

0 commit comments

Comments
 (0)