Skip to content

Commit ee336a1

Browse files
committed
update bcs schema
1 parent e1a7464 commit ee336a1

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

crates/iota-sdk-types/src/object.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ pub struct MoveStruct {
291291
/// Number that increases each time a tx takes this object as a mutable
292292
/// input This is a lamport timestamp, not a sequentially increasing
293293
/// version
294-
#[cfg_attr(feature = "bcs-schema", bcs_schema(as_type = "u64"))]
295294
version: Version,
296295
/// BCS bytes of a Move struct value.
297296
///

crates/iota-sdk-types/tests/bcs_schema_fuzzing.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ impl TestHarness {
410410
"checkpoint-transaction",
411411
Self::generate_checkpoint_transaction,
412412
);
413+
overrides.insert("move-struct", Self::gen_move_struct);
413414

414415
Self {
415416
grammar,
@@ -508,6 +509,25 @@ impl TestHarness {
508509
out
509510
}
510511

512+
/// Generate a valid `move-struct` in BCS wire form.
513+
///
514+
/// Layout: compressed-struct-tag + u64 version + length-prefixed bytes.
515+
/// `MoveStruct::new` rejects `contents` shorter than `ObjectId::LENGTH`
516+
/// (32 bytes), since the leading bytes are the object's id; the grammar's
517+
/// generic `bytes` rule cannot express that lower bound, so generate it
518+
/// here directly.
519+
fn gen_move_struct(&mut self) -> Vec<u8> {
520+
let mut out = self.generate("compressed-struct-tag");
521+
out.extend(self.rng.next_u64().to_le_bytes());
522+
const MIN_LEN: usize = 32; // ObjectId::LENGTH
523+
let len = MIN_LEN + (self.rng.next_u32() as usize) % 33; // 32..=64
524+
out.extend(encode_uleb128(len as u64));
525+
let mut buf = vec![0u8; len];
526+
self.rng.fill_bytes(&mut buf);
527+
out.extend(buf);
528+
out
529+
}
530+
511531
/// Generate a valid `validator-aggregated-signature` in BCS wire form.
512532
///
513533
/// Layout: u64 epoch + 48OCTET bls-sig + BCS-bytes(roaring bitmap).

0 commit comments

Comments
 (0)