Skip to content

Commit 7f4d962

Browse files
committed
Make object withdraw public
1 parent da6793e commit 7f4d962

File tree

13 files changed

+140
-23
lines changed

13 files changed

+140
-23
lines changed

crates/sui-e2e-tests/tests/address_balance_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ async fn test_soft_bundle_different_gas_payers() {
22872287
async fn test_multiple_deposits_merged_in_effects() {
22882288
let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut cfg| {
22892289
cfg.create_root_accumulator_object_for_testing();
2290-
cfg.enable_accumulators_for_testing();
2290+
cfg.set_enable_accumulators_for_testing(true);
22912291
cfg
22922292
});
22932293

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-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,56 +240,56 @@ validators:
240240
next_epoch_worker_address: ~
241241
extra_fields:
242242
id:
243-
id: "0x6b750b1995b859c04a07cad4f6dc0316c22ce19b65ff070b6ad09d3d98a8b0ec"
243+
id: "0x60f0fa9e616607fd37cd5a838761683d09267467116806512808dfca3d6393f1"
244244
size: 0
245245
voting_power: 10000
246-
operation_cap_id: "0xcd5be0cdc411ebe485e7a4caa8a25ee698b19efef84d643b67fc5e22ce296c98"
246+
operation_cap_id: "0x8740beecc31986061a943b065aa964756fadf2b15e06d3ab0fecfd05bd16cbcf"
247247
gas_price: 1000
248248
staking_pool:
249-
id: "0xc6cab9e7103ce830380661fd326ab395dc9603229f0ae1658dc1bd5675e99354"
249+
id: "0x922ca1a3aee20b04bdb48146a8c4e0603c688c6ab6ad9f654f818e95142f5330"
250250
activation_epoch: 0
251251
deactivation_epoch: ~
252252
sui_balance: 20000000000000000
253253
rewards_pool:
254254
value: 0
255255
pool_token_balance: 20000000000000000
256256
exchange_rates:
257-
id: "0xd9c45b06c207a4fedb70f0d7a70b61e61e77257af2c73ce575c2c0a17ea398ba"
257+
id: "0x070d22422efb725fe02df34ac4d9ad76b713ac15cc9ea7479292ea5ab9fcb7fa"
258258
size: 1
259259
pending_stake: 0
260260
pending_total_sui_withdraw: 0
261261
pending_pool_token_withdraw: 0
262262
extra_fields:
263263
id:
264-
id: "0xaf34bd6b7aba0a272f9e3d031757dd588ae7d1d9a6088601df6cc7c4dcc15780"
264+
id: "0xadec63ef2e3a7448a29065e11edae5e122beb704a4e4efd679eebd5c36f41899"
265265
size: 0
266266
commission_rate: 200
267267
next_epoch_stake: 20000000000000000
268268
next_epoch_gas_price: 1000
269269
next_epoch_commission_rate: 200
270270
extra_fields:
271271
id:
272-
id: "0xd7ebe9f5212663e6dfe304bb91839f34c4381063e51d863f4e5fb5e9c8470d51"
272+
id: "0xd11fa723631e40431fb6a11653f13d14cd32950da5080d93bef068d27cac8eff"
273273
size: 0
274274
pending_active_validators:
275275
contents:
276-
id: "0x7f73b990548de4efabca42e4d1163d4f45de5ed60717a211d5a0301e068611ef"
276+
id: "0xee4f787eb9c6930114322ff13eedd21b6f0fff25116cda573cccc8ef2dc5c6ea"
277277
size: 0
278278
pending_removals: []
279279
staking_pool_mappings:
280-
id: "0x5ce8ef201bb32bd45373266e90c990eb8cb6b76d0f1d476e767604a215c1260c"
280+
id: "0x4b099d22ad663735c145902bef3241a626c7cc9c418fed59bc9f274339186df9"
281281
size: 1
282282
inactive_validators:
283-
id: "0x65f4e217e52db9a18fe0d999c06d62be4742e38834ccacf2f12f805242be5b65"
283+
id: "0x16999c05f5b289c339035bb5ddc4b1e09641359434a84a7774cf5c515557cf3a"
284284
size: 0
285285
validator_candidates:
286-
id: "0x03057eb4bcc1c680f6cfbbee4fbe3d6d66227a3a248c32d3643e286329e7878d"
286+
id: "0x80490d536c169c3382d2ca01a2b61859ffc597d806a41e71e57931bb792b8dfe"
287287
size: 0
288288
at_risk_validators:
289289
contents: []
290290
extra_fields:
291291
id:
292-
id: "0xa542d6b2f5614ccd0ead7dd58fbddad650443fff888206906404a40c22420b56"
292+
id: "0xd8fa5918aa4891ed21850029e0146127dd116edc08f6c7ac06f5c61d23d2c517"
293293
size: 0
294294
storage_fund:
295295
total_object_storage_rebates:
@@ -306,7 +306,7 @@ parameters:
306306
validator_low_stake_grace_period: 7
307307
extra_fields:
308308
id:
309-
id: "0x9f73ed4896df6cd9f6bd4b17e6357a8acde6e47cf23699ee3ea3efc2ca31d377"
309+
id: "0xbf7284890e9f96a4f95507f20a7a2ce1d8367dcf5176d7aa14409ca767afb078"
310310
size: 0
311311
reference_gas_price: 1000
312312
validator_report_records:
@@ -320,7 +320,7 @@ stake_subsidy:
320320
stake_subsidy_decrease_rate: 1000
321321
extra_fields:
322322
id:
323-
id: "0x2f2903f704f8806a197ddc830da67845412e63d2d87725cc1ea54b7999e10c55"
323+
id: "0x986ce94bad81a80fbaf5387d094054287089875a28f2ac1382c8d65615f55ab5"
324324
size: 0
325325
safe_mode: false
326326
safe_mode_storage_rewards:
@@ -332,5 +332,5 @@ safe_mode_non_refundable_storage_fee: 0
332332
epoch_start_timestamp_ms: 10
333333
extra_fields:
334334
id:
335-
id: "0xc69df2a866c6b091f2571c82ee83e7e719c74694f9e93798cc813423185a5cf7"
335+
id: "0xf9889dfca12569d0eb937e47ba7fb2c690d0c7895fe6d7a7816d0aeda69d91cf"
336336
size: 0

crates/sui-types/src/balance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub const BALANCE_DESTROY_REBATES_FUNCTION_NAME: &IdentStr = ident_str!("destroy
2828

2929
pub const BALANCE_REDEEM_FUNDS_FUNCTION_NAME: &IdentStr = ident_str!("redeem_funds");
3030
pub const BALANCE_SEND_FUNDS_FUNCTION_NAME: &IdentStr = ident_str!("send_funds");
31+
3132
#[serde_as]
3233
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)]
3334
pub struct Supply {

0 commit comments

Comments
 (0)