Skip to content

Commit

Permalink
tweak: Remove CustomGenesis and make default genesis not error on r…
Browse files Browse the repository at this point in the history
…ound change
  • Loading branch information
dhedey committed Aug 20, 2024
1 parent 559b174 commit c4d6037
Show file tree
Hide file tree
Showing 32 changed files with 398 additions and 502 deletions.
2 changes: 1 addition & 1 deletion radix-clis/src/resim/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl SimulatorEnvironment {

fn bootstrap(&mut self) {
ProtocolBuilder::for_network(&self.network_definition)
.bootstrap_then_until(ProtocolVersion::LATEST)
.from_bootstrap_to_latest()
.commit_each_protocol_update(&mut self.db);
}
}
Expand Down
1 change: 1 addition & 0 deletions radix-clis/src/utils/common_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ mod test {
build_and_decode(arg, type_kind, type_validation).map(|(_, arg)| arg)
}

#[allow(dead_code)] // As it's used for displaying the error messages
#[derive(Debug, Clone)]
pub enum BuildAndDecodeArgError {
BuildCallArgumentError(BuildCallArgumentError),
Expand Down
15 changes: 11 additions & 4 deletions radix-engine-monkey-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use radix_engine::blueprints::consensus_manager::EpochChangeEvent;
use radix_engine::blueprints::pool::v1::constants::*;
use radix_engine::errors::{NativeRuntimeError, RuntimeError, VmError};
use radix_engine::transaction::{TransactionOutcome, TransactionResult};
use radix_engine::updates::BabylonSettings;
use radix_engine::vm::OverridePackageCode;
use radix_engine_interface::blueprints::package::PackageDefinition;
use radix_engine_interface::blueprints::pool::{
Expand All @@ -37,7 +38,7 @@ use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use rayon::iter::IntoParallelIterator;
use rayon::iter::ParallelIterator;
use scrypto_test::prelude::{CustomGenesis, LedgerSimulator, LedgerSimulatorBuilder};
use scrypto_test::prelude::{LedgerSimulator, LedgerSimulatorBuilder};

pub struct SystemTestFuzzer {
rng: ChaCha8Rng,
Expand Down Expand Up @@ -326,14 +327,20 @@ impl<T: TxnFuzzer> FuzzTest<T> {
fn new(seed: u64) -> Self {
let mut fuzzer = SystemTestFuzzer::new(seed);
let initial_epoch = Epoch::of(5);
let genesis = CustomGenesis::default_with_xrd_amount(
let pub_key = Secp256k1PrivateKey::from_u64(1u64).unwrap().public_key();
let genesis = BabylonSettings::single_validator_and_staker(
pub_key,
Decimal::one(),
Decimal::from(24_000_000_000u64),
ComponentAddress::preallocated_account_from_public_key(&pub_key),
initial_epoch,
CustomGenesis::default_consensus_manager_config(),
ConsensusManagerConfig::test_default(),
);

let (mut ledger, validator_set) = LedgerSimulatorBuilder::new()
.with_custom_genesis(genesis)
.with_custom_protocol(|builder| {
builder.with_babylon(genesis).from_bootstrap_to_latest()
})
.with_custom_extension(OverridePackageCode::new(
CUSTOM_PACKAGE_CODE_ID,
ResourceTestInvoke,
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/application/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn run_all(mode: CostingTaskMode) {
let execute = move |run: &dyn Fn(DefaultLedgerSimulator) -> TransactionReceipt,
file: &'static str| {
let ledger = LedgerSimulatorBuilder::new()
.with_custom_protocol(|builder| builder.bootstrap_then_until(protocol_version))
.with_custom_protocol(|builder| builder.from_bootstrap_to(protocol_version))
.without_kernel_trace()
.build();
let receipt = run(ledger);
Expand Down
4 changes: 0 additions & 4 deletions radix-engine-tests/tests/application/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ fn test_assume_all_signature_proofs_flag_method_authorization() {
fn test_preview_no_auth() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))
.build();
let network = NetworkDefinition::simulator();

Expand Down
3 changes: 1 addition & 2 deletions radix-engine-tests/tests/application/stake_reconciliation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use radix_common::prelude::*;
use radix_engine::updates::*;
use radix_substate_store_interface::db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper};
use scrypto_test::prelude::*;
use core::fmt::Write;
Expand All @@ -19,7 +18,7 @@ fn test_stake_reconciliation() {
// Arrange
let pub_key = Secp256k1PrivateKey::from_u64(1u64).unwrap().public_key();
let mut ledger = LedgerSimulatorBuilder::new()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();
let (account_pk, _, account) = ledger.new_account(false);

Expand Down
6 changes: 1 addition & 5 deletions radix-engine-tests/tests/blueprints/access_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use radix_engine::transaction::TransactionReceipt;
use radix_engine_interface::blueprints::access_controller::*;
use radix_engine_interface::prelude::*;
use radix_transactions::prelude::*;
use scrypto_test::prelude::{CustomGenesis, DefaultLedgerSimulator, LedgerSimulatorBuilder};
use scrypto_test::prelude::{DefaultLedgerSimulator, LedgerSimulatorBuilder};

#[test]
pub fn creating_an_access_controller_succeeds() {
Expand Down Expand Up @@ -1652,10 +1652,6 @@ impl AccessControllerLedgerSimulator {
pub fn new(timed_recovery_delay_in_minutes: Option<u32>) -> Self {
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))
.build();

// Creating a new account - this is where the badges will be held
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/blueprints/account_locker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn account_locker_cant_be_instantiated_before_protocol_update() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::Anemone)
.with_custom_protocol(|builder| builder.from_bootstrap_to(ProtocolVersion::Anemone))
.build();
let (_, _, account) = ledger.new_account(false);

Expand Down
8 changes: 0 additions & 8 deletions radix-engine-tests/tests/blueprints/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ use scrypto_test::prelude::*;
fn sdk_clock_reads_timestamp_set_by_validator_next_round() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))
.build();
let package_address = ledger.publish_package_simple(PackageLoader::get("clock"));

Expand Down Expand Up @@ -71,10 +67,6 @@ fn no_auth_required_to_get_current_time_rounded_to_minutes() {
fn sdk_clock_compares_against_timestamp_set_by_validator_next_round() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))
.build();
let package_address = ledger.publish_package_simple(PackageLoader::get("clock"));

Expand Down
12 changes: 3 additions & 9 deletions radix-engine-tests/tests/blueprints/time.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use radix_common::time::UtcDateTime;
use radix_common::types::{Epoch, Round};
use radix_common::types::Round;
use radix_engine_interface::blueprints::consensus_manager::TimePrecision;
use scrypto_test::prelude::*;

#[test]
fn advancing_round_changes_app_facing_minute_resolution_clock() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))

.build();

let epoch_seconds_rounded_to_minutes = UtcDateTime::new(2022, 1, 1, 0, 0, 0)
Expand Down Expand Up @@ -39,10 +36,7 @@ fn advancing_round_changes_app_facing_minute_resolution_clock() {
fn advancing_round_changes_internal_milli_timestamp() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))

.build();
let epoch_milli = 123456789;

Expand Down
28 changes: 17 additions & 11 deletions radix-engine-tests/tests/blueprints/transaction_tracker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use radix_common::prelude::*;
use radix_engine::errors::RejectionReason;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::updates::BabylonSettings;
use radix_engine_interface::blueprints::consensus_manager::EpochChangeCondition;
use radix_transactions::errors::TransactionValidationError;
use scrypto_test::prelude::*;
Expand All @@ -11,18 +12,23 @@ use radix_transactions::validation::*;
fn test_transaction_replay_protection() {
let init_epoch = Epoch::of(1);
let rounds_per_epoch = 5;
let genesis = CustomGenesis::default(
init_epoch,
CustomGenesis::default_consensus_manager_config().with_epoch_change_condition(
EpochChangeCondition {
min_round_count: rounds_per_epoch,
max_round_count: rounds_per_epoch,
target_duration_millis: 1000,
},
),
);
let genesis = BabylonSettings::test_default()
.with_consensus_manager_config(
ConsensusManagerConfig::test_default()
.with_epoch_change_condition(
EpochChangeCondition {
min_round_count: rounds_per_epoch,
max_round_count: rounds_per_epoch,
target_duration_millis: 1000,
},
)
);
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(genesis)
.with_custom_protocol(|builder| {
builder
.with_babylon(genesis)
.from_bootstrap_to_latest()
})
.build();

// 1. Run a notarized transaction
Expand Down
17 changes: 8 additions & 9 deletions radix-engine-tests/tests/blueprints/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use radix_common::prelude::*;
use radix_engine::blueprints::consensus_manager::ValidatorError;
use radix_engine::errors::{ApplicationError, RuntimeError};
use radix_engine::transaction::TransactionReceipt;
use radix_engine::updates::BabylonSettings;
use radix_engine_interface::blueprints::consensus_manager::{
ValidatorAcceptsDelegatedStakeInput, VALIDATOR_ACCEPTS_DELEGATED_STAKE_IDENT,
VALIDATOR_GET_REDEMPTION_VALUE_IDENT,
Expand All @@ -18,16 +19,20 @@ where
let initial_epoch = Epoch::of(5);
let pub_key = Secp256k1PrivateKey::from_u64(1u64).unwrap().public_key();
let validator_account_address = ComponentAddress::preallocated_account_from_public_key(&pub_key);
let genesis = CustomGenesis::single_validator_and_staker(
let genesis = BabylonSettings::single_validator_and_staker(
pub_key,
Decimal::one(),
Decimal::ZERO,
validator_account_address,
initial_epoch,
CustomGenesis::default_consensus_manager_config(),
ConsensusManagerConfig::test_default(),
);
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(genesis)
.with_custom_protocol(|builder| {
builder
.with_babylon(genesis)
.from_bootstrap_to_latest()
})
.build();

// Act
Expand Down Expand Up @@ -82,13 +87,7 @@ fn cannot_signal_protocol_update_if_wrong_length() {
#[test]
fn check_if_validator_accepts_delegated_stake() {
// Arrange
let initial_epoch = Epoch::of(5);
let genesis = CustomGenesis::default(
initial_epoch,
CustomGenesis::default_consensus_manager_config(),
);
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(genesis)
.build();
let (pub_key, _, account) = ledger.new_account(false);

Expand Down
4 changes: 2 additions & 2 deletions radix-engine-tests/tests/db/substate_database_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ fn run_scenarios(
let ledger_with_overlay = Rc::new(RefCell::new(
LedgerSimulatorBuilder::new()
.with_custom_database(overlay)
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.without_kernel_trace()
.build(),
));
Expand Down Expand Up @@ -517,7 +517,7 @@ fn run_scenarios(
);
})
.execute_protocol_updates_and_scenarios(
ProtocolBuilder::for_network(&network_definition).bootstrap_then_until(ProtocolVersion::LATEST),
ProtocolBuilder::for_network(&network_definition).from_bootstrap_to_latest(),
ScenarioTrigger::AtStartOfEveryProtocolVersion,
ScenarioFilter::AllScenariosFirstValidAtProtocolVersion,
&mut ProtocolUpdateHooks {
Expand Down
8 changes: 4 additions & 4 deletions radix-engine-tests/tests/flash/access_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn access_controller_instantiated_before_protocol_update_has_v1_state() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();

let access_controller = ledger
Expand Down Expand Up @@ -228,7 +228,7 @@ fn before_protocol_update_calling_any_method_on_an_access_controller_with_v1_sta
for (method_name, args) in invocations {
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();
let (_, _, account) = ledger.new_account(false);

Expand Down Expand Up @@ -498,7 +498,7 @@ fn after_protocol_update_calling_any_method_on_an_access_controller_with_v1_stat
for (method_name, args) in invocations {
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();
let (_, _, account) = ledger.new_account(false);

Expand Down Expand Up @@ -586,7 +586,7 @@ fn after_protocol_update_calling_any_method_on_an_access_controller_with_v1_stat
}

ProtocolBuilder::for_simulator()
.from_until(ProtocolVersion::Babylon, ProtocolVersion::Bottlenose)
.from_to(ProtocolVersion::Babylon, ProtocolVersion::Bottlenose)
.commit_each_protocol_update(ledger.substate_db_mut());

// Act
Expand Down
5 changes: 2 additions & 3 deletions radix-engine-tests/tests/flash/account.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use radix_engine::{blueprints::account::*, updates::*};
use radix_engine::blueprints::account::*;
use scrypto_test::prelude::*;

#[test]
fn before_protocol_update_try_deposit_or_refund_fails_if_claimed_authorized_depositor_is_not_one() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();
let (user_public_key, _, user_account) = ledger.new_account(false);

Expand Down Expand Up @@ -53,7 +53,6 @@ fn after_protocol_update_try_deposit_or_refund_refunds_resources_if_claimed_auth
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.without_kernel_trace()
.with_protocol_version(ProtocolVersion::LATEST)
.build();
let (user_public_key, _, user_account) = ledger.new_account(false);

Expand Down
9 changes: 2 additions & 7 deletions radix-engine-tests/tests/flash/crypto_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use radix_engine::updates::*;
use radix_engine_tests::common::PackageLoader;
use radix_engine_tests::common::*;
use scrypto_test::prelude::*;
use scrypto_test::prelude::{CustomGenesis, LedgerSimulatorBuilder};

#[test]
fn publishing_crypto_utils_without_state_flash_should_fail() {
Expand All @@ -21,11 +20,7 @@ fn publishing_crypto_utils_with_state_flash_should_succeed() {
fn run_flash_test(flash_substates: bool, expect_success: bool) {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_genesis(CustomGenesis::default(
Epoch::of(1),
CustomGenesis::default_consensus_manager_config(),
))
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.build();

if flash_substates {
Expand Down Expand Up @@ -72,7 +67,7 @@ fn run_flash_test_test_environment(enable_bls: bool, expect_success: bool) {
.with_anemone(AnemoneSettings::all_disabled().set(|s| {
s.vm_boot_to_enable_bls128_and_keccak256 = UpdateSetting::new(enable_bls)
}))
.bootstrap_then_until(ProtocolVersion::Anemone)
.from_bootstrap_to(ProtocolVersion::Anemone)
})
.build();

Expand Down
6 changes: 3 additions & 3 deletions radix-engine-tests/tests/flash/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use scrypto_test::prelude::*;
fn database_is_consistent_before_and_after_protocol_update() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.without_kernel_trace()
.build();

Expand Down Expand Up @@ -81,7 +81,7 @@ fn database_is_consistent_before_and_after_protocol_update() {
fn single_sided_contributions_to_two_resource_pool_are_only_allowed_after_protocol_update() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.without_kernel_trace()
.build();

Expand Down Expand Up @@ -236,7 +236,7 @@ fn single_sided_contributions_to_two_resource_pool_are_only_allowed_after_protoc
fn single_sided_contributions_to_multi_resource_pool_are_only_allowed_after_protocol_update() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_protocol_version(ProtocolVersion::Babylon)
.with_custom_protocol(|builder| builder.only_babylon())
.without_kernel_trace()
.build();

Expand Down
Loading

0 comments on commit c4d6037

Please sign in to comment.