Skip to content

Commit

Permalink
Add support to change arbitrary object owner
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Jan 3, 2025
1 parent 194ab05 commit b5731a6
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions crates/sui-types/src/test_checkpoint_data_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,18 @@ impl TestCheckpointDataBuilder {
/// Transfer an existing object to a new owner.
/// `object_idx` is a convenient representation of the object's ID.
/// `recipient_idx` is a convenient representation of the recipient's address.
pub fn transfer_object(mut self, object_idx: u64, recipient_idx: u8) -> Self {
pub fn transfer_object(self, object_idx: u64, recipient_idx: u8) -> Self {
self.change_object_owner(object_idx, Owner::AddressOwner(dbg_addr(recipient_idx)))
}

/// Change the owner of an existing object.
/// `object_idx` is a convenient representation of the object's ID.
/// `owner` is the new owner of the object.
pub fn change_object_owner(mut self, object_idx: u64, owner: Owner) -> Self {
let tx_builder = self.checkpoint_builder.next_transaction.as_mut().unwrap();
let object_id = derive_object_id(object_idx);
let mut object = self
.live_objects
.get(&object_id)
.cloned()
.expect("Transferring an object that doesn't exist");
object.owner = Owner::AddressOwner(dbg_addr(recipient_idx));
let mut object = self.live_objects.get(&object_id).unwrap().clone();
object.owner = owner;
tx_builder.mutated_objects.insert(object_id, object);
self
}
Expand Down Expand Up @@ -295,18 +298,6 @@ impl TestCheckpointDataBuilder {
self
}

/// Freeze an existing object in the transaction.
/// `object_idx` is a convenient representation of the object's ID.
pub fn freeze_object(mut self, object_idx: u64) -> Self {
let tx_builder = self.checkpoint_builder.next_transaction.as_mut().unwrap();
let object_id = derive_object_id(object_idx);
assert!(self.live_objects.contains_key(&object_id));
let mut object = self.live_objects.get(&object_id).unwrap().clone();
object.owner = Owner::Immutable;
tx_builder.mutated_objects.insert(object_id, object);
self
}

/// Add events to the transaction.
/// `events` is a vector of events to be added to the transaction.
pub fn with_events(mut self, events: Vec<Event>) -> Self {
Expand Down Expand Up @@ -688,7 +679,7 @@ mod tests {
.create_owned_object(0)
.finish_transaction()
.start_transaction(0)
.freeze_object(0)
.change_object_owner(0, Owner::Immutable)
.finish_transaction()
.build_checkpoint();

Expand Down

0 comments on commit b5731a6

Please sign in to comment.