Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 136 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["app/*", "contracts/*", "packages/*"]
members = ["app/*", "contracts/*", "packages/*", "tools/address-converter"]
exclude = ["tools/proto-compiler"]
resolver = "2"

Expand Down Expand Up @@ -72,6 +72,8 @@ cosmos-sdk-proto = { version = "0.18.0", default-features = false, features = ["
cw-orch-core = { version = "1"}
abstract-cw-multi-test = { version = "1", default-features = false }

alloy-primitives = { version = "0.8.2", default-features = false }

[profile.release]
# temporary to speed up testing
# lto = true
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile.slay3rd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ COPY packages/std/Cargo.toml /myapp/packages/std/Cargo.toml
COPY dummy.rs /myapp/packages/std/src/lib.rs
COPY packages/storage/Cargo.toml /myapp/packages/storage/Cargo.toml
COPY dummy.rs /myapp/packages/storage/src/lib.rs
COPY tools/proto-compiler/Cargo.toml /myapp/tools/proto-compiler/Cargo.toml
COPY dummy.rs /myapp/tools/proto-compiler/src/lib.rs
COPY tools/address-converter/Cargo.toml /myapp/tools/address-converter/Cargo.toml
COPY dummy.rs /myapp/tools/address-converter/src/lib.rs
RUN cargo build --release --bin slay3rd

# clean up these fake local deps so we compile for real later
Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,11 @@ mod tests {
// run finalize_block
// query account + balances for update
fn transaction_workflow<T: PersistentStorage + 'static>(storage: T) {
let sender = must_id("slay3r1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmvk3r3j");
let recipient = must_id("slay3r1y5hl7x8hxl72dc9gu920eaz6l7vhl0luu6s70h");
// TODO: convert bech32 to 0x checksummed (make script)
let sender = must_id("0x0d82b1E7c96dbfA42462fE612932e6bfF111D51B");
let recipient = must_id("0x252fFf18f737fcA6E0A8E154FCf45aFf997fBFFc");
// let sender = must_id("slay3r1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmvk3r3j");
// let recipient = must_id("slay3r1y5hl7x8hxl72dc9gu920eaz6l7vhl0luu6s70h");
let denom: &str = "uslay";

let expected_gas = 16_000u64;
Expand Down Expand Up @@ -577,7 +580,7 @@ mod tests {
recipient: recipient.clone(),
amount: coins(2_000_000, denom),
})],
signer: must_id("slay3r1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmvk3r3j"),
signer: must_id("0x0d82b1E7c96dbfA42462fE612932e6bfF111D51B"),
signing_info: SigningInfo {
message_hash: Binary::from(
hex!("6d368a4b8436e0b19a2d06069e0b70086ba7c40e91a9d04d31946c10346d79a9")
Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/testing/hackatom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ fn error_handling_from_api_call() {
match err {
PulsarError::Wasm(WasmError::Contract(msg)) => {
assert!(
msg.starts_with("Generic error: addr_validate errored: Bech32:"),
msg.starts_with(
"Generic error: addr_validate errored: Address: invalid string length"
),
"Unexpected error message: {}",
msg
);
Expand Down
28 changes: 9 additions & 19 deletions packages/app/src/wasm/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sha2::{
};
use thiserror::Error;

use layer_std::AccountId;
use layer_std::{AccountId, VALID_ADDR_LENGTH};

use crate::PulsarError;

Expand All @@ -23,7 +23,7 @@ pub fn build_instantiate_address(
prehash.extend(code_id.to_be_bytes());
prehash.extend(counter.to_be_bytes());
let raw = Sha256::digest(prehash);
Ok(AccountId::new(&raw)?)
Ok(AccountId::new(&raw[..VALID_ADDR_LENGTH])?)
}

/// We should match the reference wasmd/Go implementation for compatibility with cosmos-sdk:
Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn build_instantiate_2_address(
key.extend_from_slice(&(msg.len() as u64).to_be_bytes());
key.extend_from_slice(msg);
let address_data = hash("module", &key);
Ok(AccountId::new(&address_data)?)
Ok(AccountId::new(&address_data[..VALID_ADDR_LENGTH])?)
}

/// This must be compatible with the wasmd calls, and thus map to address.Module in Cosmos SDK.
Expand Down Expand Up @@ -108,41 +108,31 @@ mod tests {
let msg2: &[u8] = b"{}";
let msg3: &[u8] = b"{\"some\":123,\"structure\":{\"nested\":[\"ok\",true]}}";

// TODO: reduce all expected to 40 chars, not 64 chars

// No msg
let expected = AccountId::new(&hex!(
"5e865d3e45ad3e961f77fd77d46543417ced44d924dc3e079b5415ff6775f847"
))
.unwrap();
let expected = AccountId::new(&hex!("5e865d3e45ad3e961f77fd77d46543417ced44d9")).unwrap();
assert_eq!(
build_instantiate_2_address(&checksum1, &creator1, &salt1, msg1).unwrap(),
expected
);

// With msg
let expected = AccountId::new(&hex!(
"0995499608947a5281e2c7ebd71bdb26a1ad981946dad57f6c4d3ee35de77835"
))
.unwrap();
let expected = AccountId::new(&hex!("0995499608947a5281e2c7ebd71bdb26a1ad9819")).unwrap();
assert_eq!(
build_instantiate_2_address(&checksum1, &creator1, &salt1, msg2).unwrap(),
expected
);

// Long msg
let expected = AccountId::new(&hex!(
"83326e554723b15bac664ceabc8a5887e27003abe9fbd992af8c7bcea4745167"
))
.unwrap();
let expected = AccountId::new(&hex!("83326e554723b15bac664ceabc8a5887e27003ab")).unwrap();
assert_eq!(
build_instantiate_2_address(&checksum1, &creator1, &salt1, msg3).unwrap(),
expected
);

// Long salt
let expected = AccountId::new(&hex!(
"9384c6248c0bb171e306fd7da0993ec1e20eba006452a3a9e078883eb3594564"
))
.unwrap();
let expected = AccountId::new(&hex!("9384c6248c0bb171e306fd7da0993ec1e20eba00")).unwrap();
assert_eq!(
build_instantiate_2_address(&checksum1, &creator1, &salt2, b"").unwrap(),
expected
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/wasm/vm/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ mod tests {
assert_eq!(res.messages.len(), 0);
assert_eq!(res.events.len(), 0);
assert_eq!(res.attributes.len(), 0);
assert_eq!(gas_used, 57);
assert_eq!(gas_used, 56);

// query the state was written - token_info and total supply
let num = writer
Expand Down Expand Up @@ -677,7 +677,7 @@ mod tests {
let cw20::AllAccountsResponse { accounts } = from_json(res).unwrap();
assert_eq!(
accounts,
vec![two.to_string(), one.to_string(), three.to_string()]
vec![one.to_string(), two.to_string(), three.to_string()]
);
}

Expand Down
Loading