Skip to content

Commit

Permalink
[client-ptb] Properly handle mutability around shared objects by value
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Mar 1, 2024
1 parent 5206ab6 commit 553beaa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crates/sui/src/client_ptb/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ impl<'a> PTBBuilder<'a> {
// Otherwise it's ambiguous what the value should be, and we need to turn to the signature
// to determine it.
let mut is_receiving = false;
let mut is_mutable = false;
// A value is mutable by default.
let mut is_mutable = true;

// traverse the types in the signature to see if the argument is an object argument or not,
// and also determine if it's a receiving argument or not.
Expand All @@ -461,7 +462,11 @@ impl<'a> PTBBuilder<'a> {
error!(loc, "Not enough type parameters supplied for Move call");
}
}
SignatureToken::Reference(_) => {
is_mutable = false;
}
SignatureToken::MutableReference(_) => {
// Not strictly needed, but for clarity
is_mutable = true;
}
SignatureToken::Bool
Expand All @@ -473,8 +478,9 @@ impl<'a> PTBBuilder<'a> {
| SignatureToken::Vector(_)
| SignatureToken::U16
| SignatureToken::U32
| SignatureToken::U256
| SignatureToken::Reference(_) => {}
| SignatureToken::U256 => {
is_mutable = false;
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ async fn test_ptb_publish_and_complex_arg_resolution() -> Result<(), anyhow::Err
.execute(context)
.await?;

let delete_object_ptb_string = format!(
r#"
--assign p @{package_id_str}
--assign s @{shared_id_str}
# Use the shared object by immutable reference first
--move-call "p::test_module::use_immut" s
--move-call "p::test_module::delete_shared_object" s
--gas-budget 100000000
"#
);

let args = shlex::split(&delete_object_ptb_string).unwrap();
sui::client_ptb::ptb::PTB { args: args.clone() }
.execute(context)
.await?;

Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ module test_functions::test_module {
public fun use_utf8_string(_: US) {
// do nothing
}

public fun delete_shared_object(shared: Shared) {
let Shared { id } = shared;
object::delete(id);
}
}

0 comments on commit 553beaa

Please sign in to comment.