@layerzerolabs/common-utils-stellar-contracts 0.2.122 → 0.2.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/common-utils-stellar-contracts",
3
- "version": "0.2.122",
3
+ "version": "0.2.124",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "files": [
@@ -11,11 +11,11 @@
11
11
  "clippy.toml"
12
12
  ],
13
13
  "dependencies": {
14
- "@layerzerolabs/common-utils-macros-stellar-contracts": "0.2.122"
14
+ "@layerzerolabs/common-utils-macros-stellar-contracts": "0.2.124"
15
15
  },
16
16
  "devDependencies": {
17
- "@layerzerolabs/build-utils-rust": "0.2.122",
18
- "@layerzerolabs/vm-tooling-stellar": "0.2.122"
17
+ "@layerzerolabs/build-utils-rust": "0.2.124",
18
+ "@layerzerolabs/vm-tooling-stellar": "0.2.124"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public",
@@ -36,7 +36,9 @@
36
36
  "build": "pnpm resolve-dependencies && pnpm exec lz-tool --script \"cargo build\" stellar",
37
37
  "clean": "rm -rf ./dependencies ./target ./node_modules",
38
38
  "format": "pnpm exec lz-tool --script \"cargo fmt\" stellar",
39
- "lint": "pnpm resolve-dependencies && pnpm exec lz-tool --script \"cargo clippy -- -D warnings\" stellar",
39
+ "format:check": "pnpm exec lz-tool --script \"cargo fmt -- --check\" stellar",
40
+ "lint": "pnpm resolve-dependencies && pnpm exec lz-tool --script \"cargo fmt -- --check && cargo clippy --all-targets -- -D warnings\" stellar",
41
+ "lint:fix": "pnpm resolve-dependencies && pnpm exec lz-tool --script \"cargo clippy --all-targets --fix --allow-dirty --allow-staged && cargo fmt\" stellar",
40
42
  "resolve-dependencies": "pnpm exec build-utils-rust resolve",
41
43
  "test": "pnpm resolve-dependencies && pnpm exec lz-tool --script \"cargo nextest run --features testutils\" stellar"
42
44
  }
package/rustfmt.toml CHANGED
@@ -1,15 +1,12 @@
1
- format_macro_bodies = true
1
+ # Only stable rustfmt options are kept here: the Stellar docker toolchain runs
2
+ # rustfmt on the stable channel (rust 1.90.0), which silently drops unstable
3
+ # options (they only apply on nightly). Do not re-add unstable options unless the
4
+ # tooling is switched to a pinned nightly (see the Solana packages for that setup).
2
5
  max_width = 120
3
- format_macro_matchers = true
4
- format_strings = true
5
- imports_granularity = "Crate"
6
- match_arm_blocks = false
7
- reorder_impl_items = true
8
- group_imports = "StdExternalCrate"
9
6
  use_field_init_shorthand = true
10
7
  use_small_heuristics = "Max"
11
- wrap_comments = true
12
- format_code_in_doc_comments = true
13
8
 
14
- # most of these are unstable, so we enable them
15
- unstable_features = true
9
+ # style_edition is a stable option honored by the docker toolchain. Pin it to
10
+ # 2021 to match every crate's `edition = "2021"` so formatting stays stable
11
+ # across rustfmt versions (setting it to 2024 would reformat the code).
12
+ style_edition = "2021"
@@ -19,11 +19,9 @@ use soroban_sdk::{testutils::Events, xdr, Address, Env, Event, TryFromVal, Val,
19
19
  /// }
20
20
  /// ```
21
21
  pub fn decode_event_topics_data(env: &Env, event: &xdr::ContractEvent) -> Option<(Vec<Val>, Val)> {
22
- // In the current Soroban SDK version this is always `V0`.
23
- // Using a single-variant match avoids "irrefutable let-else" warnings.
24
- let v0 = match &event.body {
25
- xdr::ContractEventBody::V0(v0) => v0,
26
- };
22
+ // In the current Soroban SDK version this enum has a single variant (`V0`),
23
+ // so this destructure is infallible.
24
+ let xdr::ContractEventBody::V0(v0) = &event.body;
27
25
 
28
26
  let mut topics = Vec::<Val>::new(env);
29
27
  for t in v0.topics.iter() {
@@ -120,7 +118,6 @@ pub fn assert_contains_event<E: Event>(env: &Env, contract: &Address, expected:
120
118
  /// &Event2 { ... },
121
119
  /// ]);
122
120
  /// ```
123
-
124
121
  pub fn assert_eq_events(env: &Env, contract: &Address, expected_events: &[&dyn Event]) {
125
122
  // Note: this module is only compiled for tests / testutils usage, where `std` is available.
126
123
  extern crate std;
@@ -143,7 +140,6 @@ pub fn assert_eq_events(env: &Env, contract: &Address, expected_events: &[&dyn E
143
140
  /// &Event2 { ... },
144
141
  /// ]);
145
142
  /// ```
146
-
147
143
  pub fn assert_contains_events(env: &Env, contract: &Address, expected_events: &[&dyn Event]) {
148
144
  // Note: this module is only compiled for tests / testutils usage, where `std` is available.
149
145
  extern crate std;
@@ -303,7 +303,7 @@ fn test_write_primitives_roundtrip() {
303
303
  .write_u16(0x3456)
304
304
  .write_u32(0x789ABCDE)
305
305
  .write_u64(0x0102030405060708)
306
- .write_u128(0x10111213141516171819_1a1b1c1d1e1f);
306
+ .write_u128(0x1011_1213_1415_1617_1819_1a1b_1c1d_1e1f);
307
307
 
308
308
  let bytes = writer.to_bytes();
309
309
  // 1 + 2 + 4 + 8 + 16 = 31
@@ -315,7 +315,7 @@ fn test_write_primitives_roundtrip() {
315
315
  assert_eq!(reader.read_u16(), 0x3456);
316
316
  assert_eq!(reader.read_u32(), 0x789ABCDE);
317
317
  assert_eq!(reader.read_u64(), 0x0102030405060708);
318
- assert_eq!(reader.read_u128(), 0x10111213141516171819_1a1b1c1d1e1f);
318
+ assert_eq!(reader.read_u128(), 0x1011_1213_1415_1617_1819_1a1b_1c1d_1e1f);
319
319
  }
320
320
 
321
321
  #[test]
@@ -86,8 +86,8 @@ fn test_to_array_boundary_values() {
86
86
  let data: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
87
87
  let bytes = Bytes::from_array(&env, &data);
88
88
  let arr: [u8; 10] = bytes.to_array();
89
- for i in 0..10 {
90
- assert_eq!(arr[i], i as u8);
89
+ for (i, value) in arr.iter().enumerate() {
90
+ assert_eq!(*value, i as u8);
91
91
  }
92
92
  }
93
93
 
@@ -154,7 +154,7 @@ fn test_to_array_preserves_all_values() {
154
154
  let bytes = Bytes::from_array(&env, &data);
155
155
  let arr: [u8; 256] = bytes.to_array();
156
156
 
157
- for i in 0..256 {
158
- assert_eq!(arr[i], i as u8, "Mismatch at index {}", i);
157
+ for (i, value) in arr.iter().enumerate() {
158
+ assert_eq!(*value, i as u8, "Mismatch at index {}", i);
159
159
  }
160
160
  }
@@ -712,8 +712,8 @@ fn recover_signer_invalid_r_zero_fails() {
712
712
  let mut sig_bytes = [0u8; 65];
713
713
  // r = 0 (bytes 0-31 already 0)
714
714
  // s = some non-zero value (bytes 32-63)
715
- for i in 32..64 {
716
- sig_bytes[i] = 1;
715
+ for value in sig_bytes.iter_mut().take(64).skip(32) {
716
+ *value = 1;
717
717
  }
718
718
  sig_bytes[64] = 27; // v
719
719
  let signature = BytesN::from_array(&env, &sig_bytes);
@@ -732,8 +732,8 @@ fn recover_signer_invalid_s_zero_fails() {
732
732
  // Signature with s=0 (invalid for secp256k1)
733
733
  let mut sig_bytes = [0u8; 65];
734
734
  // r = some non-zero value (bytes 0-31)
735
- for i in 0..32 {
736
- sig_bytes[i] = 1;
735
+ for value in sig_bytes.iter_mut().take(32) {
736
+ *value = 1;
737
737
  }
738
738
  // s = 0 (bytes 32-63 already 0)
739
739
  sig_bytes[64] = 27; // v
@@ -239,16 +239,14 @@ fn test_decode_event_topics_data_roundtrip() {
239
239
  assert_eq!(raw.len(), 1);
240
240
 
241
241
  let event = &raw[0];
242
- let v0 = match &event.body {
243
- xdr::ContractEventBody::V0(v0) => v0,
244
- };
242
+ let xdr::ContractEventBody::V0(v0) = &event.body;
245
243
 
246
244
  let (topics, data) = decode_event_topics_data(&env, event).expect("event should decode");
247
245
 
248
246
  // `Val` doesn't implement `PartialEq` in this SDK version, so compare by converting back to XDR.
249
247
  let topics_xdr: std::vec::Vec<xdr::ScVal> =
250
248
  topics.iter().map(|t| xdr::ScVal::try_from_val(&env, &t).expect("topic Val must convert to XDR")).collect();
251
- assert_eq!(topics_xdr.len(), v0.topics.len() as usize);
249
+ assert_eq!(topics_xdr.len(), v0.topics.len());
252
250
  for (i, t) in v0.topics.iter().enumerate() {
253
251
  assert_eq!(topics_xdr[i], *t);
254
252
  }
@@ -368,7 +368,7 @@ fn test_upgrade_success() {
368
368
 
369
369
  env.as_contract(&contract_id, || {
370
370
  // Initially, migrating flag should be false (default)
371
- assert_eq!(UpgradeableStorage::migrating(&env), false);
371
+ assert!(!UpgradeableStorage::migrating(&env));
372
372
  });
373
373
 
374
374
  // Call the actual upgrade function with valid WASM hash
@@ -377,7 +377,7 @@ fn test_upgrade_success() {
377
377
 
378
378
  env.as_contract(&contract_id, || {
379
379
  // Verify the flag is set by upgrade()
380
- assert_eq!(UpgradeableStorage::migrating(&env), true);
380
+ assert!(UpgradeableStorage::migrating(&env));
381
381
  });
382
382
  }
383
383
 
@@ -412,7 +412,7 @@ fn test_migrate_success() {
412
412
 
413
413
  env.as_contract(&contract_id, || {
414
414
  // Verify migration flag was cleared
415
- assert_eq!(UpgradeableStorage::migrating(&env), false);
415
+ assert!(!UpgradeableStorage::migrating(&env));
416
416
 
417
417
  // Verify migration data was stored (proving __migrate was called)
418
418
  let stored_value: Option<bool> = env.storage().instance().get(&Symbol::new(&env, "migrated"));
@@ -431,7 +431,7 @@ fn test_migrate_requires_auth() {
431
431
  // Set the migrating flag so we know failure is due to auth, not MigrationNotAllowed.
432
432
  env.as_contract(&contract_id, || {
433
433
  UpgradeableStorage::set_migrating(&env, &true);
434
- assert_eq!(UpgradeableStorage::migrating(&env), true);
434
+ assert!(UpgradeableStorage::migrating(&env));
435
435
  });
436
436
 
437
437
  let migration_data = Val::VOID.to_xdr(&env);
@@ -448,7 +448,7 @@ fn test_migrate_rejects_invalid_migration_data_and_does_not_clear_flag() {
448
448
  // Allow migrate (so we hit the decode path rather than MigrationNotAllowed).
449
449
  env.as_contract(&contract_id, || {
450
450
  UpgradeableStorage::set_migrating(&env, &true);
451
- assert_eq!(UpgradeableStorage::migrating(&env), true);
451
+ assert!(UpgradeableStorage::migrating(&env));
452
452
  });
453
453
 
454
454
  // Valid XDR, but not a u32 payload => should fail decoding in Upgradeable::migrate.
@@ -458,7 +458,7 @@ fn test_migrate_rejects_invalid_migration_data_and_does_not_clear_flag() {
458
458
 
459
459
  // Since migration failed before reaching the "clear flag" line, migrating should still be true.
460
460
  env.as_contract(&contract_id, || {
461
- assert_eq!(UpgradeableStorage::migrating(&env), true);
461
+ assert!(UpgradeableStorage::migrating(&env));
462
462
  });
463
463
  }
464
464
 
@@ -476,7 +476,7 @@ fn test_can_upgrade_and_migrate_multiple_times() {
476
476
  client.upgrade(&wasm_hash);
477
477
  client.migrate(&migration_data);
478
478
  env.as_contract(&contract_id, || {
479
- assert_eq!(UpgradeableStorage::migrating(&env), false);
479
+ assert!(!UpgradeableStorage::migrating(&env));
480
480
  let stored_value: Option<bool> = env.storage().instance().get(&Symbol::new(&env, "migrated"));
481
481
  assert_eq!(stored_value, Some(true));
482
482
  });
@@ -485,7 +485,7 @@ fn test_can_upgrade_and_migrate_multiple_times() {
485
485
  client.upgrade(&wasm_hash);
486
486
  client.migrate(&migration_data);
487
487
  env.as_contract(&contract_id, || {
488
- assert_eq!(UpgradeableStorage::migrating(&env), false);
488
+ assert!(!UpgradeableStorage::migrating(&env));
489
489
  let stored_value: Option<bool> = env.storage().instance().get(&Symbol::new(&env, "migrated"));
490
490
  assert_eq!(stored_value, Some(true));
491
491
  });