Skip to content

Commit b7ee335

Browse files
committed
Test fixes
1 parent b04aa4a commit b7ee335

File tree

12 files changed

+294
-45
lines changed

12 files changed

+294
-45
lines changed

crates/sui-core/src/authority.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) Mysten Labs, Inc.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
use crate::accumulators::AccumulatorSettlementTxBuilder;
56
use crate::accumulators::balance_read::AccountBalanceRead;
67
use crate::checkpoints::CheckpointBuilderError;
78
use crate::checkpoints::CheckpointBuilderResult;
@@ -1288,6 +1289,8 @@ impl AuthorityState {
12881289
return Err(SuiErrorKind::ValidatorHaltedAtEpochEnd.into());
12891290
}
12901291

1292+
transaction.validity_check(&epoch_store.tx_validity_check_context())?;
1293+
12911294
let checked_input_objects =
12921295
self.handle_transaction_deny_checks(transaction, epoch_store)?;
12931296

@@ -3909,6 +3912,66 @@ impl AuthorityState {
39093912
Ok(new_epoch_store)
39103913
}
39113914

3915+
pub async fn settle_transactions_for_testing(
3916+
&self,
3917+
ckpt_seq: CheckpointSequenceNumber,
3918+
effects: &[TransactionEffects],
3919+
) {
3920+
let builder = AccumulatorSettlementTxBuilder::new(
3921+
Some(self.get_transaction_cache_reader().as_ref()),
3922+
effects,
3923+
ckpt_seq,
3924+
0,
3925+
);
3926+
let epoch_store = self.epoch_store_for_testing();
3927+
let epoch = epoch_store.epoch();
3928+
let (settlements, barrier) = builder.build_tx(
3929+
epoch_store.protocol_config(),
3930+
epoch,
3931+
epoch_store
3932+
.epoch_start_config()
3933+
.accumulator_root_obj_initial_shared_version()
3934+
.unwrap(),
3935+
ckpt_seq,
3936+
ckpt_seq,
3937+
);
3938+
3939+
let mut settlements: Vec<_> = settlements
3940+
.into_iter()
3941+
.map(|tx| {
3942+
VerifiedExecutableTransaction::new_system(
3943+
VerifiedTransaction::new_system_transaction(tx),
3944+
epoch,
3945+
)
3946+
})
3947+
.collect();
3948+
let barrier = VerifiedExecutableTransaction::new_system(
3949+
VerifiedTransaction::new_system_transaction(barrier),
3950+
epoch,
3951+
);
3952+
3953+
settlements.push(barrier);
3954+
3955+
let assigned_versions = epoch_store
3956+
.assign_shared_object_versions_for_tests(
3957+
self.get_object_cache_reader().as_ref(),
3958+
&settlements,
3959+
)
3960+
.unwrap();
3961+
3962+
let version_map = assigned_versions.into_map();
3963+
3964+
for tx in settlements {
3965+
let env = ExecutionEnv::new()
3966+
.with_assigned_versions(version_map.get(&tx.key()).unwrap().clone());
3967+
let (effects, _) = self
3968+
.try_execute_immediately(&tx, env, &epoch_store)
3969+
.await
3970+
.unwrap();
3971+
assert!(effects.status().is_ok());
3972+
}
3973+
}
3974+
39123975
/// Advance the epoch store to the next epoch for testing only.
39133976
/// This only manually sets all the places where we have the epoch number.
39143977
/// It doesn't properly reconfigure the node, hence should be only used for testing.

crates/sui-core/src/execution_scheduler/execution_scheduler_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ impl ExecutionScheduler {
316316
for (cert, env) in &certs {
317317
let tx_withdraws = cert
318318
.transaction_data()
319-
.process_funds_withdrawals_for_signing()
320-
.expect("Balance withdraws should have already been checked");
319+
.process_funds_withdrawals_for_execution();
321320
assert!(!tx_withdraws.is_empty());
322321
let accumulator_version = env
323322
.assigned_versions

crates/sui-core/src/unit_tests/coin_deny_list_tests.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,43 @@ async fn test_regulated_coin_v2_types() {
215215
// using the funds withdrawal argument in programmable transactions.
216216
#[tokio::test]
217217
async fn test_regulated_coin_v2_funds_withdraw_deny() {
218+
telemetry_subscribers::init_for_testing();
218219
let env = new_authority_and_publish("coin_deny_list_v2").await;
219220

220221
let metadata = env.extract_v2_metadata().await;
221222
let regulated_coin_type = metadata.regulated_coin_type();
222223
let deny_list_object_init_version = env.get_latest_object_ref(&SUI_DENY_LIST_OBJECT_ID).await.1;
223-
let env_gas_ref = env.get_latest_object_ref(&env.gas_object_id).await;
224+
let mut env_gas_ref = env.get_latest_object_ref(&env.gas_object_id).await;
224225
let deny_cap_ref = env.get_latest_object_ref(&metadata.deny_cap_id).await;
225226

226227
// Create a new account that will be denied for the regulated coin.
227228
let (denied_address, denied_keypair) = get_account_key_pair();
228229

230+
env.authority
231+
.settle_transactions_for_testing(0, std::slice::from_ref(&env.publish_effects))
232+
.await;
233+
234+
{
235+
// Fund the denied address
236+
let tx = TestTransactionBuilder::new(
237+
env.sender,
238+
env_gas_ref,
239+
env.authority.reference_gas_price_for_testing().unwrap(),
240+
)
241+
.transfer_funds_to_address_balance(100_000_000, regulated_coin_type.clone(), denied_address)
242+
.build_and_sign(&env.keypair);
243+
let effects = send_and_confirm_transaction_(&env.authority, None, tx, true)
244+
.await
245+
.unwrap()
246+
.1;
247+
assert!(effects.status().is_ok(), "Funding should succeed");
248+
env_gas_ref = effects.gas_object().0;
249+
250+
env.authority
251+
.settle_transactions_for_testing(1, std::slice::from_ref(&effects))
252+
.await;
253+
}
254+
229255
// Add the denied address to the regulated coin deny list.
230256
let add_tx = TestTransactionBuilder::new(
231257
env.sender,
@@ -392,6 +418,7 @@ async fn new_authority_and_publish(path: &str) -> TestEnv {
392418

393419
let mut protocol_config =
394420
ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
421+
protocol_config.enable_accumulators_for_testing();
395422
protocol_config
396423
.set_per_object_congestion_control_mode_for_testing(PerObjectCongestionControlMode::None);
397424

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
module coin_deny_list_v2::regulated_coin {
5-
use sui::coin;
4+
module coin_deny_list_v2::regulated_coin;
65

7-
public struct REGULATED_COIN has drop {}
6+
use sui::coin;
87

9-
fun init(otw: REGULATED_COIN, ctx: &mut TxContext) {
10-
let (treasury_cap, deny_cap, metadata) = coin::create_regulated_currency_v2(
11-
otw,
12-
9,
13-
b"RC",
14-
b"REGULATED_COIN",
15-
b"A new regulated coin",
16-
option::none(),
17-
true,
18-
ctx
19-
);
20-
transfer::public_transfer(deny_cap, tx_context::sender(ctx));
21-
transfer::public_freeze_object(treasury_cap);
22-
transfer::public_freeze_object(metadata);
23-
}
8+
public struct REGULATED_COIN has drop {}
9+
10+
fun init(otw: REGULATED_COIN, ctx: &mut TxContext) {
11+
let (mut treasury_cap, deny_cap, metadata) = coin::create_regulated_currency_v2(
12+
otw,
13+
9,
14+
b"RC",
15+
b"REGULATED_COIN",
16+
b"A new regulated coin",
17+
option::none(),
18+
true,
19+
ctx,
20+
);
21+
transfer::public_transfer(deny_cap, tx_context::sender(ctx));
22+
23+
let coin = treasury_cap.mint(100_000_000, ctx);
24+
coin.send_funds(tx_context::sender(ctx));
25+
transfer::public_freeze_object(treasury_cap);
26+
transfer::public_freeze_object(metadata);
2427
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use sui_types::{
2525
supported_protocol_versions::SupportedProtocolVersions,
2626
transaction::{
2727
Argument, Command, FundsWithdrawalArg, GasData, Transaction, TransactionData,
28-
TransactionDataV1, TransactionExpiration, TransactionKind,
28+
TransactionDataAPI, TransactionDataV1, TransactionExpiration, TransactionKind,
2929
},
3030
};
3131
use test_cluster::TestClusterBuilder;
@@ -744,6 +744,26 @@ async fn test_address_balance_gas() {
744744

745745
let chain_id = test_cluster.get_chain_identifier();
746746

747+
// check that a transaction with a zero gas budget is rejected
748+
{
749+
let mut tx = create_storage_test_transaction_address_balance(
750+
sender,
751+
gas_package_id,
752+
rgp,
753+
chain_id,
754+
None,
755+
0,
756+
);
757+
tx.gas_data_mut().budget = 0;
758+
let signed_tx = test_cluster.sign_transaction(&tx).await;
759+
let err = test_cluster
760+
.wallet
761+
.execute_transaction_may_fail(signed_tx)
762+
.await
763+
.unwrap_err();
764+
assert!(err.to_string().contains("Gas budget: 0 is lower than min:"));
765+
}
766+
747767
let tx = create_storage_test_transaction_address_balance(
748768
sender,
749769
gas_package_id,
@@ -2275,7 +2295,7 @@ async fn test_multiple_deposits_merged_in_effects() {
22752295
let rgp = test_cluster.get_reference_gas_price().await;
22762296
let context = &mut test_cluster.wallet;
22772297

2278-
let (sender, gas) = get_sender_and_gas(context).await;
2298+
let (sender, gas) = get_sender_and_one_gas(context).await;
22792299
let recipient = sender;
22802300

22812301
let initial_deposit = make_send_to_account_tx(10000, recipient, sender, gas, rgp);

crates/sui-test-transaction-builder/src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use sui_types::SUI_RANDOMNESS_STATE_OBJECT_ID;
1414
use sui_types::base_types::{FullObjectRef, ObjectID, ObjectRef, SequenceNumber, SuiAddress};
1515
use sui_types::crypto::{AccountKeyPair, Signature, Signer, get_key_pair};
1616
use sui_types::digests::TransactionDigest;
17+
use sui_types::gas_coin::GAS;
1718
use sui_types::multisig::{BitmapUnit, MultiSig, MultiSigPublicKey};
1819
use sui_types::multisig_legacy::{MultiSigLegacy, MultiSigPublicKeyLegacy};
1920
use sui_types::object::Owner;
@@ -294,6 +295,31 @@ impl TestTransactionBuilder {
294295
self
295296
}
296297

298+
pub fn transfer_sui_to_address_balance(mut self, amount: u64, recipient: SuiAddress) -> Self {
299+
self.test_data =
300+
TestTransactionData::TransferFundsToAddressBalance(TransferFundsToAddressBalanceData {
301+
amount,
302+
type_arg: GAS::type_tag(),
303+
recipient,
304+
});
305+
self
306+
}
307+
308+
pub fn transfer_funds_to_address_balance(
309+
mut self,
310+
amount: u64,
311+
type_arg: TypeTag,
312+
recipient: SuiAddress,
313+
) -> Self {
314+
self.test_data =
315+
TestTransactionData::TransferFundsToAddressBalance(TransferFundsToAddressBalanceData {
316+
amount,
317+
type_arg,
318+
recipient,
319+
});
320+
self
321+
}
322+
297323
pub fn split_coin(mut self, coin: ObjectRef, amounts: Vec<u64>) -> Self {
298324
self.test_data = TestTransactionData::SplitCoin(SplitCoinData { coin, amounts });
299325
self
@@ -368,6 +394,19 @@ impl TestTransactionBuilder {
368394
.unwrap_or(self.gas_price * TEST_ONLY_GAS_UNIT_FOR_TRANSFER),
369395
self.gas_price,
370396
),
397+
TestTransactionData::TransferFundsToAddressBalance(data) => {
398+
TransactionData::new_transfer_funds_to_address_balance(
399+
data.recipient,
400+
self.sender,
401+
data.amount,
402+
data.type_arg,
403+
self.gas_object,
404+
self.gas_budget
405+
.unwrap_or(self.gas_price * TEST_ONLY_GAS_UNIT_FOR_TRANSFER),
406+
self.gas_price,
407+
)
408+
.unwrap()
409+
}
371410
TestTransactionData::SplitCoin(data) => TransactionData::new_split_coin(
372411
self.sender,
373412
data.coin,
@@ -474,6 +513,7 @@ enum TestTransactionData {
474513
Move(MoveData),
475514
Transfer(TransferData),
476515
TransferSui(TransferSuiData),
516+
TransferFundsToAddressBalance(TransferFundsToAddressBalanceData),
477517
SplitCoin(SplitCoinData),
478518
Publish(PublishData),
479519
Programmable(ProgrammableTransaction),
@@ -507,6 +547,12 @@ struct TransferSuiData {
507547
recipient: SuiAddress,
508548
}
509549

550+
struct TransferFundsToAddressBalanceData {
551+
amount: u64,
552+
type_arg: TypeTag,
553+
recipient: SuiAddress,
554+
}
555+
510556
struct SplitCoinData {
511557
coin: ObjectRef,
512558
amounts: Vec<u64>,

crates/sui-types/src/balance.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub const BALANCE_STRUCT_NAME: &IdentStr = ident_str!("Balance");
1919
pub const BALANCE_CREATE_REWARDS_FUNCTION_NAME: &IdentStr = ident_str!("create_staking_rewards");
2020
pub const BALANCE_DESTROY_REBATES_FUNCTION_NAME: &IdentStr = ident_str!("destroy_storage_rebates");
2121

22+
pub const BALANCE_REDEEM_FUNDS_FUNCTION_NAME: &IdentStr = ident_str!("redeem_funds");
23+
pub const BALANCE_SEND_FUNDS_FUNCTION_NAME: &IdentStr = ident_str!("send_funds");
2224
#[serde_as]
2325
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)]
2426
pub struct Supply {

crates/sui-types/src/gas.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{base_types::ObjectID, gas_model::gas_v2::PerObjectStorage};
1111
pub mod checked {
1212

1313
use crate::gas::GasUsageReport;
14-
use crate::gas_model::gas_predicates::gas_price_too_high;
14+
use crate::gas_model::gas_predicates::check_for_gas_price_too_high;
1515
use crate::{
1616
ObjectID,
1717
effects::{TransactionEffects, TransactionEffectsAPI},
@@ -83,7 +83,8 @@ pub mod checked {
8383
}
8484
.into());
8585
}
86-
if gas_price_too_high(config.gas_model_version()) && gas_price >= config.max_gas_price()
86+
if check_for_gas_price_too_high(config.gas_model_version())
87+
&& gas_price >= config.max_gas_price()
8788
{
8889
return Err(UserInputError::GasPriceTooHigh {
8990
max_gas_price: config.max_gas_price(),

crates/sui-types/src/gas_model/gas_predicates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn dont_charge_budget_on_storage_oog(gas_model_version: u64) -> bool {
2222
}
2323

2424
/// If true, enable the check for gas price too high
25-
pub fn gas_price_too_high(gas_model_version: u64) -> bool {
25+
pub fn check_for_gas_price_too_high(gas_model_version: u64) -> bool {
2626
gas_model_version >= 4
2727
}
2828

0 commit comments

Comments
 (0)