Skip to content

Commit

Permalink
adding tests/feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed May 28, 2024
1 parent ce876c0 commit 9f49c9c
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 66 deletions.
71 changes: 60 additions & 11 deletions aptos-move/aptos-aggregator/src/delayed_field_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl DelayedFieldData {
mod test {
use super::*;
use crate::FakeAggregatorView;
use claims::{assert_err, assert_ok, assert_ok_eq};
use claims::{assert_err, assert_none, assert_ok_eq};

#[test]
fn test_aggregator_not_in_storage() {
Expand Down Expand Up @@ -355,28 +355,53 @@ mod test {
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(0))
);
assert_ok!(data.try_add_delta(id, max_value, SignedU128::Positive(100), &resolver));
assert_ok_eq!(
data.try_add_or_check_delta(id, max_value, SignedU128::Positive(100), &resolver, false),
true
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(0))
);

assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Positive(100), &resolver),
true
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(100))
);
assert!(data
.try_add_delta(id, max_value, SignedU128::Negative(50), &resolver)
.unwrap());

assert_ok_eq!(
data.try_add_or_check_delta(id, max_value, SignedU128::Positive(120), &resolver, false),
false
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(100))
);

assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Negative(50), &resolver),
true
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(50))
);
assert!(!data
.try_add_delta(id, max_value, SignedU128::Negative(70), &resolver)
.unwrap());
assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Negative(70), &resolver),
false
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::<DelayedFieldID>::Create(DelayedFieldValue::Aggregator(50))
);
assert!(!data
.try_add_delta(id, max_value, SignedU128::Positive(170), &resolver)
.unwrap());
assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Positive(170), &resolver),
false
);
assert_eq!(
get_agg(&data, &id),
&DelayedChange::Create(DelayedFieldValue::Aggregator(50))
Expand Down Expand Up @@ -406,6 +431,20 @@ mod test {

resolver.set_from_aggregator_id(id, 100);

assert_ok_eq!(
data.try_add_or_check_delta(id, max_value, SignedU128::Positive(400), &resolver, false),
true
);
// checks only add to captured reads, not to writes
assert_none!(data.delayed_fields.get(&id));

assert_ok_eq!(
data.try_add_or_check_delta(id, max_value, SignedU128::Positive(550), &resolver, false),
false
);
// checks only add to captured reads, not to writes
assert_none!(data.delayed_fields.get(&id));

assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Positive(400), &resolver),
true
Expand All @@ -414,6 +453,16 @@ mod test {
get_agg(&data, &id),
&aggregator_delta_change(400, max_value)
);

assert_ok_eq!(
data.try_add_or_check_delta(id, max_value, SignedU128::Negative(100), &resolver, false),
true
);
assert_eq!(
get_agg(&data, &id),
&aggregator_delta_change(400, max_value)
);

assert_ok_eq!(
data.try_add_delta(id, max_value, SignedU128::Negative(470), &resolver),
true
Expand Down
27 changes: 15 additions & 12 deletions aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! This module defines the gas parameters for Aptos Framework & Stdlib.

use crate::{
gas_feature_versions::{RELEASE_V1_14, RELEASE_V1_8, RELEASE_V1_9_SKIPPED},
gas_schedule::NativeGasParameters,
ver::gas_feature_versions::{RELEASE_V1_12, RELEASE_V1_13},
};
Expand Down Expand Up @@ -297,18 +298,20 @@ crate::gas_schedule::macros::define_gas_parameters!(
[aggregator_destroy_base: InternalGas, "aggregator.destroy.base", 1838],
[aggregator_factory_new_aggregator_base: InternalGas, "aggregator_factory.new_aggregator.base", 1838],

[aggregator_v2_create_aggregator_base: InternalGas, {12.. => "aggregator_v2.create_aggregator.base"}, 1838],
[aggregator_v2_try_add_base: InternalGas, {12.. => "aggregator_v2.try_add.base"}, 1102],
[aggregator_v2_try_sub_base: InternalGas, {12.. => "aggregator_v2.try_sub.base"}, 1102],
[aggregator_v2_read_base: InternalGas, {12.. => "aggregator_v2.read.base"}, 2205],
[aggregator_v2_snapshot_base: InternalGas, {12.. => "aggregator_v2.snapshot.base"}, 1102],

[aggregator_v2_create_snapshot_base: InternalGas, {11.. => "aggregator_v2.create_snapshot.base"}, 1102],
[aggregator_v2_create_snapshot_per_byte: InternalGasPerByte, { 12.. =>"aggregator_v2.create_snapshot.per_byte" }, 3],
[aggregator_v2_copy_snapshot_base: InternalGas, {11.. => "aggregator_v2.copy_snapshot.base"}, 1102],
[aggregator_v2_read_snapshot_base: InternalGas, {11.. => "aggregator_v2.read_snapshot.base"}, 2205],
[aggregator_v2_string_concat_base: InternalGas, {11.. => "aggregator_v2.string_concat.base"}, 1102],
[aggregator_v2_string_concat_per_byte: InternalGasPerByte, { 12.. =>"aggregator_v2.string_concat.per_byte" }, 3],
[aggregator_v2_create_aggregator_base: InternalGas, {RELEASE_V1_9_SKIPPED.. => "aggregator_v2.create_aggregator.base"}, 1838],
[aggregator_v2_try_add_base: InternalGas, {RELEASE_V1_9_SKIPPED.. => "aggregator_v2.try_add.base"}, 1102],
[aggregator_v2_try_sub_base: InternalGas, {RELEASE_V1_9_SKIPPED.. => "aggregator_v2.try_sub.base"}, 1102],
[aggregator_v2_is_at_least_base: InternalGas, {RELEASE_V1_14.. => "aggregator_v2.is_at_least.base"}, 500],

[aggregator_v2_read_base: InternalGas, {RELEASE_V1_9_SKIPPED.. => "aggregator_v2.read.base"}, 2205],
[aggregator_v2_snapshot_base: InternalGas, {RELEASE_V1_9_SKIPPED.. => "aggregator_v2.snapshot.base"}, 1102],

[aggregator_v2_create_snapshot_base: InternalGas, {RELEASE_V1_8.. => "aggregator_v2.create_snapshot.base"}, 1102],
[aggregator_v2_create_snapshot_per_byte: InternalGasPerByte, { RELEASE_V1_9_SKIPPED.. =>"aggregator_v2.create_snapshot.per_byte" }, 3],
[aggregator_v2_copy_snapshot_base: InternalGas, {RELEASE_V1_8.. => "aggregator_v2.copy_snapshot.base"}, 1102],
[aggregator_v2_read_snapshot_base: InternalGas, {RELEASE_V1_8.. => "aggregator_v2.read_snapshot.base"}, 2205],
[aggregator_v2_string_concat_base: InternalGas, {RELEASE_V1_8.. => "aggregator_v2.string_concat.base"}, 1102],
[aggregator_v2_string_concat_per_byte: InternalGasPerByte, { RELEASE_V1_9_SKIPPED.. =>"aggregator_v2.string_concat.per_byte" }, 3],

Check warning on line 314 in aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs#L301-L314

Added lines #L301 - L314 were not covered by tests

[object_exists_at_base: InternalGas, { 7.. => "object.exists_at.base" }, 919],
// Based on SHA3-256's cost
Expand Down
10 changes: 9 additions & 1 deletion aptos-move/aptos-gas-schedule/src/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/// - Changing how gas is calculated in any way
///
/// Change log:
/// - V19
/// - gas for aggregator_v2::is_at_least native function
/// - V18
/// - Separate limits for governance scripts
/// - Function info & dispatchable token gas params
Expand All @@ -25,6 +27,7 @@
/// - V12
/// - Added BN254 operations.
/// - IO gas change: 1. read bytes charged at 4KB intervals; 2. ignore free_write_bytes_quota
/// - aggregator v2 gas charges
/// - V11
/// - Ristretto255 natives (point cloning & double-scalar multiplication) and Bulletproofs natives
/// - Hard limit on the number of write ops per transaction
Expand Down Expand Up @@ -59,11 +62,16 @@
/// global operations.
/// - V1
/// - TBA
pub const LATEST_GAS_FEATURE_VERSION: u64 = 18;
pub const LATEST_GAS_FEATURE_VERSION: u64 = 19;

#[allow(dead_code)]
pub mod gas_feature_versions {
pub const RELEASE_V1_8: u64 = 11;
pub const RELEASE_V1_9_SKIPPED: u64 = 12;
pub const RELEASE_V1_9: u64 = 13;
pub const RELEASE_V1_10: u64 = 15;
pub const RELEASE_V1_11: u64 = 16;
pub const RELEASE_V1_12: u64 = 17;
pub const RELEASE_V1_13: u64 = 18;
pub const RELEASE_V1_14: u64 = 19;
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum FeatureFlag {
DispatchableFungibleAsset,
NewAccountsDefaultToFaAptStore,
OperationsDefaultToFaAptStore,
AggregatorV2IsAtLeastApi,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -300,6 +301,9 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::OperationsDefaultToFaAptStore => {
AptosFeatureFlag::OPERATIONS_DEFAULT_TO_FA_APT_STORE
},
FeatureFlag::AggregatorV2IsAtLeastApi => {
AptosFeatureFlag::AGGREGATOR_V2_IS_AT_LEAST_API
},
}
}
}
Expand Down Expand Up @@ -413,6 +417,9 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::OPERATIONS_DEFAULT_TO_FA_APT_STORE => {
FeatureFlag::OperationsDefaultToFaAptStore
},
AptosFeatureFlag::AGGREGATOR_V2_IS_AT_LEAST_API => {
FeatureFlag::AggregatorV2IsAtLeastApi
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc a8f570394fd4cd6dccbec4f0f8a866f365ac76eac32cb0e8a1665f3d09f06c80 # shrinks to test_env = TestEnvConfig { executor_mode: BothComparison, aggregator_execution_mode: DisabledOnly, block_split: Whole }
13 changes: 13 additions & 0 deletions aptos-move/e2e-move-tests/src/aggregator_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,19 @@ impl AggV2TestHarness {
self.create_entry_agg_func_with_args("0x1::aggregator_v2_test::add_sub", agg_loc, &[a, b])
}

pub fn add_if_at_least(
&mut self,
agg_loc: &AggregatorLocation,
min_value: u128,
delta: u128,
) -> SignedTransaction {
self.create_entry_agg_func_with_args(
"0x1::aggregator_v2_test::add_if_at_least",
agg_loc,
&[min_value, delta],
)
}

pub fn add_delete(&mut self, agg_loc: &AggregatorLocation, value: u128) -> SignedTransaction {
self.create_entry_agg_func_with_args("0x1::aggregator_v2_test::add_delete", agg_loc, &[
value,
Expand Down
Loading

0 comments on commit 9f49c9c

Please sign in to comment.