Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

randomness #9: smoke tests from randomnet #12282

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions aptos-move/move-examples/on_chain_dice/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "OnChainDice"
version = "0.0.0"

[addresses]
module_owner = "_"

[dependencies]
AptosFramework = { local = "../../framework/aptos-framework" }
21 changes: 21 additions & 0 deletions aptos-move/move-examples/on_chain_dice/sources/dice.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module module_owner::dice {
use std::signer::address_of;
use std::vector;
use aptos_framework::randomness;

struct DiceRollHistory has key {
rolls: vector<u64>,
}

entry fun roll(account: signer) acquires DiceRollHistory {
danielxiangzl marked this conversation as resolved.
Show resolved Hide resolved
let addr = address_of(&account);
let roll_history = if (exists<DiceRollHistory>(addr)) {
move_from<DiceRollHistory>(addr)
} else {
DiceRollHistory { rolls: vector[] }
};
let new_roll = randomness::u64_range(0, 6);
vector::push_back(&mut roll_history.rolls, new_roll);
move_to(&account, roll_history);
}
}
24 changes: 20 additions & 4 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct GenesisConfiguration {
pub voting_power_increase_limit: u64,
pub employee_vesting_start: u64,
pub employee_vesting_period_duration: u64,
pub initial_features_override: Option<Features>,
}

pub static GENESIS_KEYPAIR: Lazy<(Ed25519PrivateKey, Ed25519PublicKey)> = Lazy::new(|| {
Expand Down Expand Up @@ -139,7 +140,13 @@ pub fn encode_aptos_mainnet_genesis_transaction(
&execution_config,
&gas_schedule,
);
initialize_features(&mut session);
initialize_features(
&mut session,
genesis_config
.initial_features_override
.clone()
.map(Features::into_flag_vec),
);
initialize_aptos_coin(&mut session);
initialize_on_chain_governance(&mut session, genesis_config);
create_accounts(&mut session, accounts);
Expand Down Expand Up @@ -248,7 +255,13 @@ pub fn encode_genesis_change_set(
execution_config,
gas_schedule,
);
initialize_features(&mut session);
initialize_features(
&mut session,
genesis_config
.initial_features_override
.clone()
.map(Features::into_flag_vec),
);
if genesis_config.is_test {
initialize_core_resources_and_aptos_coin(&mut session, core_resources_key);
} else {
Expand Down Expand Up @@ -421,8 +434,9 @@ fn initialize(
);
}

fn initialize_features(session: &mut SessionExt) {
let features: Vec<u64> = FeatureFlag::default_features()
fn initialize_features(session: &mut SessionExt, features_override: Option<Vec<FeatureFlag>>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not individual override but the whole vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifying a patch seems more complicated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah just the name is a bit confusing

let features: Vec<u64> = features_override
.unwrap_or_else(FeatureFlag::default_features)
.into_iter()
.map(|feature| feature as u64)
.collect();
Expand Down Expand Up @@ -879,6 +893,7 @@ pub fn generate_test_genesis(
voting_power_increase_limit: 50,
employee_vesting_start: 1663456089,
employee_vesting_period_duration: 5 * 60, // 5 minutes
initial_features_override: None,
},
&OnChainConsensusConfig::default_for_genesis(),
&OnChainExecutionConfig::default_for_genesis(),
Expand Down Expand Up @@ -926,6 +941,7 @@ fn mainnet_genesis_config() -> GenesisConfiguration {
voting_power_increase_limit: 30,
employee_vesting_start: 1663456089,
employee_vesting_period_duration: 5 * 60, // 5 minutes
initial_features_override: None,
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/aptos-genesis/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use aptos_keygen::KeyGen;
use aptos_logger::prelude::*;
use aptos_types::{
chain_id::ChainId,
on_chain_config::{GasScheduleV2, OnChainConsensusConfig, OnChainExecutionConfig},
on_chain_config::{Features, GasScheduleV2, OnChainConsensusConfig, OnChainExecutionConfig},
transaction::Transaction,
waypoint::Waypoint,
};
Expand Down Expand Up @@ -431,6 +431,7 @@ pub struct GenesisConfiguration {
pub consensus_config: OnChainConsensusConfig,
pub execution_config: OnChainExecutionConfig,
pub gas_schedule: GasScheduleV2,
pub initial_features_override: Option<Features>,
}

pub type InitConfigFn = Arc<dyn Fn(usize, &mut NodeConfig, &mut NodeConfig) + Send + Sync>;
Expand Down Expand Up @@ -648,6 +649,7 @@ impl Builder {
consensus_config: OnChainConsensusConfig::default_for_genesis(),
execution_config: OnChainExecutionConfig::default_for_genesis(),
gas_schedule: default_gas_schedule(),
initial_features_override: None,
};
if let Some(init_genesis_config) = &self.init_genesis_config {
(init_genesis_config)(&mut genesis_config);
Expand Down
5 changes: 4 additions & 1 deletion crates/aptos-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use aptos_storage_interface::DbReaderWriter;
use aptos_temppath::TempPath;
use aptos_types::{
chain_id::ChainId,
on_chain_config::{GasScheduleV2, OnChainConsensusConfig, OnChainExecutionConfig},
on_chain_config::{Features, GasScheduleV2, OnChainConsensusConfig, OnChainExecutionConfig},
transaction::Transaction,
waypoint::Waypoint,
};
Expand Down Expand Up @@ -70,6 +70,7 @@ pub struct GenesisInfo {
pub consensus_config: OnChainConsensusConfig,
pub execution_config: OnChainExecutionConfig,
pub gas_schedule: GasScheduleV2,
pub initial_features_override: Option<Features>,
}

impl GenesisInfo {
Expand Down Expand Up @@ -106,6 +107,7 @@ impl GenesisInfo {
consensus_config: genesis_config.consensus_config.clone(),
execution_config: genesis_config.execution_config.clone(),
gas_schedule: genesis_config.gas_schedule.clone(),
initial_features_override: genesis_config.initial_features_override.clone(),
})
}

Expand Down Expand Up @@ -138,6 +140,7 @@ impl GenesisInfo {
voting_power_increase_limit: self.voting_power_increase_limit,
employee_vesting_start: 1663456089,
employee_vesting_period_duration: 5 * 60, // 5 minutes
initial_features_override: self.initial_features_override.clone(),
},
&self.consensus_config,
&self.execution_config,
Expand Down
8 changes: 7 additions & 1 deletion crates/aptos-genesis/src/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use aptos_db::AptosDB;
use aptos_framework::ReleaseBundle;
use aptos_storage_interface::DbReaderWriter;
use aptos_temppath::TempPath;
use aptos_types::{chain_id::ChainId, transaction::Transaction, waypoint::Waypoint};
use aptos_types::{
chain_id::ChainId, on_chain_config::Features, transaction::Transaction, waypoint::Waypoint,
};
use aptos_vm::AptosVM;
use aptos_vm_genesis::{AccountBalance, EmployeePool, ValidatorWithCommissionRate};

Expand Down Expand Up @@ -54,6 +56,8 @@ pub struct MainnetGenesisInfo {
employee_vesting_start: u64,
/// Duration of each vesting period (in seconds).
employee_vesting_period_duration: u64,

initial_features_override: Option<Features>,
}

impl MainnetGenesisInfo {
Expand Down Expand Up @@ -93,6 +97,7 @@ impl MainnetGenesisInfo {
voting_power_increase_limit: genesis_config.voting_power_increase_limit,
employee_vesting_start,
employee_vesting_period_duration,
initial_features_override: genesis_config.initial_features_override.clone(),
})
}

Expand Down Expand Up @@ -126,6 +131,7 @@ impl MainnetGenesisInfo {
voting_power_increase_limit: self.voting_power_increase_limit,
employee_vesting_start: self.employee_vesting_start,
employee_vesting_period_duration: self.employee_vesting_period_duration,
initial_features_override: self.initial_features_override.clone(),
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/aptos/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub fn fetch_mainnet_genesis_info(git_options: GitOptions) -> CliTypedResult<Mai
consensus_config: OnChainConsensusConfig::default_for_genesis(),
execution_config: OnChainExecutionConfig::default_for_genesis(),
gas_schedule: default_gas_schedule(),
initial_features_override: None,
},
)?)
}
Expand Down Expand Up @@ -297,6 +298,7 @@ pub fn fetch_genesis_info(git_options: GitOptions) -> CliTypedResult<GenesisInfo
consensus_config: layout.on_chain_consensus_config,
execution_config: layout.on_chain_execution_config,
gas_schedule: default_gas_schedule(),
initial_features_override: None,
},
)?)
}
Expand Down
13 changes: 12 additions & 1 deletion crates/aptos/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use std::{
time::Duration,
};
use tempfile::TempDir;
use thiserror::__private::AsDisplay;
use tokio::time::{sleep, Instant};

#[cfg(test)]
Expand Down Expand Up @@ -470,6 +471,16 @@ impl CliTestFramework {
.await
}

pub fn add_file_in_package(&self, rel_path: &str, content: String) {
let source_path = self.move_dir().join(rel_path);
write_to_file(
source_path.as_path(),
&source_path.as_display().to_string(),
content.as_bytes(),
)
.unwrap();
}

pub async fn update_validator_network_addresses(
&self,
operator_index: usize,
Expand Down Expand Up @@ -1026,7 +1037,7 @@ impl CliTestFramework {
.await
}

fn aptos_framework_dir() -> PathBuf {
pub fn aptos_framework_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("..")
Expand Down
5 changes: 5 additions & 0 deletions testsuite/smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ aptos-config = { workspace = true }
aptos-consensus = { workspace = true }
aptos-crypto = { workspace = true }
aptos-db = { workspace = true }
aptos-debugger = { workspace = true }
aptos-dkg = { workspace = true }
aptos-faucet-core = { workspace = true }
aptos-forge = { workspace = true }
aptos-framework = { workspace = true }
Expand Down Expand Up @@ -50,11 +52,14 @@ diesel = { workspace = true, features = [
"numeric",
"serde_json",
] }
digest = { workspace = true }
hex = { workspace = true }
hyper = { workspace = true }
move-core-types = { workspace = true }
num-traits = { workspace = true }
proptest = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions testsuite/smoke-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ mod keyless;
#[cfg(test)]
mod network;
#[cfg(test)]
mod randomness;
#[cfg(test)]
mod rest_api;
#[cfg(test)]
mod rosetta;
Expand Down
Loading
Loading