Skip to content

Commit

Permalink
[test] Ensure stable object id in test checkpoint data builder (#20839)
Browse files Browse the repository at this point in the history
## Description 

This will be useful when we need to query data from the DB and sort by
object ID.

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
lxfind authored Jan 10, 2025
1 parent 35d516b commit c5d47b7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/sui-types/src/test_checkpoint_data_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,12 @@ impl TestCheckpointDataBuilder {
}

/// Derive an object ID from an index. This is used to conveniently represent an object's ID.
/// We ensure that the bytes of object IDs have a stable order that is the same as object_idx.
pub fn derive_object_id(object_idx: u64) -> ObjectID {
ObjectID::derive_id(TransactionDigest::ZERO, object_idx)
// We achieve this by setting the first 8 bytes of the object ID to the object_idx.
let mut bytes = [0; ObjectID::LENGTH];
bytes[0..8].copy_from_slice(&object_idx.to_le_bytes());
ObjectID::from_bytes(bytes).unwrap()
}

/// Derive an address from an index.
Expand Down

0 comments on commit c5d47b7

Please sign in to comment.