Skip to content

Commit 1e54559

Browse files
authored
fix: use testutils if the target isn't Wasm (#164)
There was an update to the soroban-sdk macros that made it necessary to always use testutils if not targetting wasm.
1 parent d7bc451 commit 1e54559

File tree

9 files changed

+343
-286
lines changed

9 files changed

+343
-286
lines changed

Cargo.lock

Lines changed: 318 additions & 250 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ loam-soroban-sdk = { path = "./crates/loam-soroban-sdk" }
1414
loam-sdk-macro = { path = "./crates/loam-sdk-macro" }
1515
loam-subcontract-ft = { path = "./crates/loam-subcontract-ft" }
1616

17-
soroban-sdk = { version = "21.2.0" }
18-
stellar-strkey = "0.0.8"
17+
soroban-sdk = "21.2.0"
18+
stellar-xdr = "21.2.0"
19+
stellar-strkey = "0.0.11"
1920

2021
cargo_metadata = "0.18.1"
2122
thiserror = "1.0.38"

crates/loam-cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ toml = { version = "0.8.12", features = ["parse", "preserve_order"] }
6262
rand = "0.8.5"
6363
wasm-gen = { version = "0.1.4" }
6464
notify = "6.1.1"
65-
stellar-strkey = "0.0.8"
66-
stellar-xdr = "21.0.0"
65+
stellar-strkey = { workspace = true }
66+
stellar-xdr = { workspace = true }
6767
rust-embed = { version = "8.2.0", features = ["debug-embed"] }
6868
regex = "1.10.5"
6969
toml_edit = "0.22.16"

crates/loam-cli/tests/fixtures/soroban-init-boilerplate/Cargo.toml

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

crates/loam-cli/tests/fixtures/soroban-init-boilerplate/contracts/token/Cargo.toml

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

crates/loam-sdk-macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ proc-macro = true
1313
[dependencies]
1414
loam-build = { path = "../loam-build", version = "0.7.3" }
1515

16-
soroban-sdk = { workspace = true, features = ["testutils"] }
16+
stellar-xdr = { workspace = true, features = ["curr"] }
1717
stellar-strkey = { workspace = true }
1818

1919
sha2 = { workspace = true }

crates/loam-sdk-macro/src/util.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::Path};
22

33
use proc_macro2::TokenStream;
44
use quote::{quote, ToTokens};
5-
use soroban_sdk::xdr;
5+
use stellar_xdr::curr as xdr;
66
use syn::{File, ItemTrait, TraitItemFn};
77

88
/// Read a crate starting from a single file then parse into a file
@@ -128,35 +128,18 @@ pub fn parse_asset(str: &str) -> Result<xdr::Asset, xdr::Error> {
128128
let split: Vec<&str> = str.splitn(2, ':').collect();
129129
assert!(split.len() == 2, "invalid asset \"{str}\"");
130130
let code = split[0];
131-
let issuer = split[1];
131+
let issuer: xdr::AccountId = split[1].parse()?;
132132
let re = regex::Regex::new("^[[:alnum:]]{1,12}$").expect("regex failed");
133133
assert!(re.is_match(code), "invalid asset \"{str}\"");
134-
if code.len() <= 4 {
135-
let mut asset_code: [u8; 4] = [0; 4];
136-
for (i, b) in code.as_bytes().iter().enumerate() {
137-
asset_code[i] = *b;
134+
let asset_code: xdr::AssetCode = code.parse()?;
135+
Ok(match asset_code {
136+
xdr::AssetCode::CreditAlphanum4(asset_code) => {
137+
xdr::Asset::CreditAlphanum4(xdr::AlphaNum4 { asset_code, issuer })
138138
}
139-
Ok(xdr::Asset::CreditAlphanum4(xdr::AlphaNum4 {
140-
asset_code: xdr::AssetCode4(asset_code),
141-
issuer: parse_account_id(issuer)?,
142-
}))
143-
} else {
144-
let mut asset_code: [u8; 12] = [0; 12];
145-
for (i, b) in code.as_bytes().iter().enumerate() {
146-
asset_code[i] = *b;
139+
xdr::AssetCode::CreditAlphanum12(asset_code) => {
140+
xdr::Asset::CreditAlphanum12(xdr::AlphaNum12 { asset_code, issuer })
147141
}
148-
Ok(xdr::Asset::CreditAlphanum12(xdr::AlphaNum12 {
149-
asset_code: xdr::AssetCode12(asset_code),
150-
issuer: parse_account_id(issuer)?,
151-
}))
152-
}
153-
}
154-
155-
pub fn parse_account_id(str: &str) -> Result<xdr::AccountId, stellar_strkey::DecodeError> {
156-
let pk_bytes = stellar_strkey::ed25519::PublicKey::from_string(str)?.0;
157-
Ok(xdr::AccountId(xdr::PublicKey::PublicKeyTypeEd25519(
158-
pk_bytes.into(),
159-
)))
142+
})
160143
}
161144

162145
// Generate the code to read the STELLAR_NETWORK environment variable

crates/loam-sdk/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ crate-type = ["rlib"]
1616
loam-sdk-macro = { path = "../loam-sdk-macro", version = "0.8.4" }
1717
loam-soroban-sdk = { path = "../loam-soroban-sdk", version = "0.6.15", optional = true }
1818

19+
[target.'cfg(not(target_family="wasm"))'.dependencies]
20+
soroban-sdk = { workspace = true, features = ["testutils"], optional = true }
1921

2022
[features]
2123
default = ["loam-soroban-sdk"]

crates/loam-soroban-sdk/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ crate-type = ["rlib"]
1414

1515
[dependencies]
1616
loam-sdk-macro = { path = "../loam-sdk-macro", version = "0.8.4" }
17-
soroban-sdk = { workspace = true }
17+
soroban-sdk = { workspace = true, default-features = false }
18+
19+
[target.'cfg(not(target_family="wasm"))'.dependencies]
20+
soroban-sdk = { workspace = true, features = ["testutils"] }
1821

1922

2023
[features]

0 commit comments

Comments
 (0)