Skip to content

Commit 523fd07

Browse files
committed
Make object withdraw public
1 parent e7b3047 commit 523fd07

File tree

15 files changed

+145
-26
lines changed

15 files changed

+145
-26
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use sui_json_rpc_types::{SuiExecutionStatus, SuiTransactionBlockEffectsAPI};
5+
use sui_macros::sim_test;
6+
use sui_protocol_config::ProtocolConfig;
7+
use sui_types::{
8+
gas_coin::GAS,
9+
transaction::{CallArg, ObjectArg},
10+
};
11+
use test_cluster::TestClusterBuilder;
12+
13+
#[sim_test]
14+
async fn test_object_balance_withdraw_disabled() {
15+
telemetry_subscribers::init_for_testing();
16+
17+
let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut cfg| {
18+
cfg.create_root_accumulator_object_for_testing();
19+
cfg.set_enable_accumulators_for_testing(false);
20+
cfg
21+
});
22+
23+
let test_cluster = TestClusterBuilder::new()
24+
.with_num_validators(1)
25+
.build()
26+
.await;
27+
28+
let tx = test_cluster
29+
.test_transaction_builder()
30+
.await
31+
.publish_examples("object_balance")
32+
.build();
33+
let resp = test_cluster.sign_and_execute_transaction(&tx).await;
34+
let package_id = resp.get_new_package_obj().unwrap().0;
35+
36+
let tx = test_cluster
37+
.test_transaction_builder()
38+
.await
39+
.move_call(package_id, "object_balance", "new", vec![])
40+
.build();
41+
let resp = test_cluster.sign_and_execute_transaction(&tx).await;
42+
let vault_obj = resp
43+
.effects
44+
.unwrap()
45+
.created()
46+
.first()
47+
.unwrap()
48+
.reference
49+
.to_object_ref();
50+
51+
let tx = test_cluster
52+
.test_transaction_builder()
53+
.await
54+
.move_call(
55+
package_id,
56+
"object_balance",
57+
"withdraw_funds",
58+
vec![
59+
CallArg::Object(ObjectArg::ImmOrOwnedObject(vault_obj)),
60+
CallArg::from(100u64),
61+
],
62+
)
63+
.with_type_args(vec![GAS::type_tag()])
64+
.build();
65+
let tx = test_cluster.sign_transaction(&tx).await;
66+
let resp = test_cluster
67+
.wallet
68+
.execute_transaction_may_fail(tx)
69+
.await
70+
.unwrap();
71+
let effects = resp.effects.unwrap();
72+
let SuiExecutionStatus::Failure { error } = effects.status() else {
73+
panic!("Transaction should fail");
74+
};
75+
assert!(error.contains("MoveAbort"));
76+
}

crates/sui-framework/docs/sui/balance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ accumulator.
489489
Create a <code>Withdrawal&lt;<a href="../sui/balance.md#sui_balance_Balance">Balance</a>&lt;T&gt;&gt;</code> from an object to withdraw funds from it.
490490

491491

492-
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/balance.md#sui_balance_withdraw_funds_from_object">withdraw_funds_from_object</a>&lt;T&gt;(obj: &<b>mut</b> <a href="../sui/object.md#sui_object_UID">sui::object::UID</a>, <a href="../sui/balance.md#sui_balance_value">value</a>: u64): <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">sui::funds_accumulator::Withdrawal</a>&lt;<a href="../sui/balance.md#sui_balance_Balance">sui::balance::Balance</a>&lt;T&gt;&gt;
492+
<pre><code><b>public</b> <b>fun</b> <a href="../sui/balance.md#sui_balance_withdraw_funds_from_object">withdraw_funds_from_object</a>&lt;T&gt;(obj: &<b>mut</b> <a href="../sui/object.md#sui_object_UID">sui::object::UID</a>, <a href="../sui/balance.md#sui_balance_value">value</a>: u64): <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">sui::funds_accumulator::Withdrawal</a>&lt;<a href="../sui/balance.md#sui_balance_Balance">sui::balance::Balance</a>&lt;T&gt;&gt;
493493
</code></pre>
494494

495495

@@ -498,7 +498,7 @@ Create a <code>Withdrawal&lt;<a href="../sui/balance.md#sui_balance_Balance">Bal
498498
<summary>Implementation</summary>
499499

500500

501-
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/balance.md#sui_balance_withdraw_funds_from_object">withdraw_funds_from_object</a>&lt;T&gt;(
501+
<pre><code><b>public</b> <b>fun</b> <a href="../sui/balance.md#sui_balance_withdraw_funds_from_object">withdraw_funds_from_object</a>&lt;T&gt;(
502502
obj: &<b>mut</b> UID,
503503
<a href="../sui/balance.md#sui_balance_value">value</a>: u64,
504504
): Withdrawal&lt;<a href="../sui/balance.md#sui_balance_Balance">Balance</a>&lt;T&gt;&gt; {

crates/sui-framework/docs/sui/funds_accumulator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Aborts with <code><a href="../sui/funds_accumulator.md#sui_funds_accumulator_EOv
227227

228228

229229

230-
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/funds_accumulator.md#sui_funds_accumulator_redeem">redeem</a>&lt;T: store&gt;(withdrawal: <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">sui::funds_accumulator::Withdrawal</a>&lt;T&gt;): T
230+
<pre><code><b>public</b> <b>fun</b> <a href="../sui/funds_accumulator.md#sui_funds_accumulator_redeem">redeem</a>&lt;T: store&gt;(withdrawal: <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">sui::funds_accumulator::Withdrawal</a>&lt;T&gt;): T
231231
</code></pre>
232232

233233

@@ -236,7 +236,7 @@ Aborts with <code><a href="../sui/funds_accumulator.md#sui_funds_accumulator_EOv
236236
<summary>Implementation</summary>
237237

238238

239-
<pre><code><b>public</b>(<a href="../sui/package.md#sui_package">package</a>) <b>fun</b> <a href="../sui/funds_accumulator.md#sui_funds_accumulator_redeem">redeem</a>&lt;/* internal */ T: store&gt;(withdrawal: <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">Withdrawal</a>&lt;T&gt;): T {
239+
<pre><code><b>public</b> <b>fun</b> <a href="../sui/funds_accumulator.md#sui_funds_accumulator_redeem">redeem</a>&lt;/* internal */ T: store&gt;(withdrawal: <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">Withdrawal</a>&lt;T&gt;): T {
240240
<b>let</b> <a href="../sui/funds_accumulator.md#sui_funds_accumulator_Withdrawal">Withdrawal</a> { owner, limit: value } = withdrawal;
241241
<a href="../sui/funds_accumulator.md#sui_funds_accumulator_withdraw_impl">withdraw_impl</a>(owner, value)
242242
}

crates/sui-framework/packages/sui-framework/sources/balance.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public fun redeem_funds<T>(withdrawal: sui::funds_accumulator::Withdrawal<Balanc
110110
}
111111

112112
/// Create a `Withdrawal<Balance<T>>` from an object to withdraw funds from it.
113-
public(package) fun withdraw_funds_from_object<T>(
113+
public fun withdraw_funds_from_object<T>(
114114
obj: &mut UID,
115115
value: u64,
116116
): Withdrawal<Balance<T>> {

crates/sui-framework/packages/sui-framework/sources/funds_accumulator.move

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public fun withdrawal_join<T: store>(withdrawal: &mut Withdrawal<T>, other: With
7171
// TODO When this becomes `public` we need
7272
// - custom verifier rules for `T`
7373
// - private generic rules for `T`
74-
public(package) fun redeem</* internal */ T: store>(withdrawal: Withdrawal<T>): T {
74+
public fun redeem</* internal */ T: store>(withdrawal: Withdrawal<T>): T {
7575
let Withdrawal { owner, limit: value } = withdrawal;
7676
withdraw_impl(owner, value)
7777
}
0 Bytes
Binary file not shown.

crates/sui-framework/published_api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ withdrawal_join
18171817
public fun
18181818
0x2::funds_accumulator
18191819
redeem
1820-
public(package) fun
1820+
public fun
18211821
0x2::funds_accumulator
18221822
withdraw_from_object
18231823
public(package) fun
@@ -1880,7 +1880,7 @@ redeem_funds
18801880
public fun
18811881
0x2::balance
18821882
withdraw_funds_from_object
1883-
public(package) fun
1883+
public fun
18841884
0x2::balance
18851885
create_supply_internal
18861886
public(package) fun

crates/sui-open-rpc/spec/openrpc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@
12941294
"name": "Result",
12951295
"value": {
12961296
"minSupportedProtocolVersion": "1",
1297-
"maxSupportedProtocolVersion": "102",
1297+
"maxSupportedProtocolVersion": "103",
12981298
"protocolVersion": "6",
12991299
"featureFlags": {
13001300
"abstract_size_in_object_runtime": false,

crates/sui-protocol-config/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tracing::{info, warn};
2323

2424
/// The minimum and maximum protocol versions supported by this build.
2525
const MIN_PROTOCOL_VERSION: u64 = 1;
26-
const MAX_PROTOCOL_VERSION: u64 = 102;
26+
const MAX_PROTOCOL_VERSION: u64 = 103;
2727

2828
// Record history of protocol version allocations here:
2929
//
@@ -275,6 +275,7 @@ const MAX_PROTOCOL_VERSION: u64 = 102;
275275
// Version 100: Framework update
276276
// Version 101: Framework update
277277
// Set max updates per settlement txn to 100.
278+
// Version 103: Framework update
278279

279280
#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
280281
pub struct ProtocolVersion(u64);
@@ -4265,6 +4266,7 @@ impl ProtocolConfig {
42654266
);
42664267
cfg.feature_flags.deprecate_global_storage_ops = true;
42674268
}
4269+
103 => {}
42684270
// Use this template when making changes:
42694271
//
42704272
// // modify an existing constant.

crates/sui-swarm-config/tests/snapshots/snapshot_tests__genesis_config_snapshot_matches.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ssfn_config_info: ~
66
validator_config_info: ~
77
parameters:
88
chain_start_timestamp_ms: 0
9-
protocol_version: 102
9+
protocol_version: 103
1010
allow_insertion_of_extra_objects: true
1111
epoch_duration_ms: 86400000
1212
stake_subsidy_start_epoch: 0

0 commit comments

Comments
 (0)