diff --git a/.github/workflows/_run-e2e-tests.yml b/.github/workflows/_run-e2e-tests.yml index d1ba2f08b7..1f15f82d35 100644 --- a/.github/workflows/_run-e2e-tests.yml +++ b/.github/workflows/_run-e2e-tests.yml @@ -65,22 +65,6 @@ jobs: artifact-aleph-node-image: ${{ inputs.artifact-aleph-node-image }} artifact-chain-bootstrapper-image: ${{ inputs.artifact-chain-bootstrapper-image }} - run-e2e-fee-calculation-test: - name: Run e2e fee calculation test - needs: [run-e2e-finalization-test] - runs-on: ubuntu-20.04 - steps: - - name: Checkout source code - uses: actions/checkout@v4 - - - name: Run e2e test - uses: ./.github/actions/run-e2e-test - with: - test-case: fee_calculation - artifact-aleph-e2e-client-image: ${{ inputs.artifact-aleph-e2e-client-image }} - artifact-aleph-node-image: ${{ inputs.artifact-aleph-node-image }} - artifact-chain-bootstrapper-image: ${{ inputs.artifact-chain-bootstrapper-image }} - run-e2e-channeling-fee-test: name: Run e2e channeling fee test needs: [run-e2e-finalization-test] diff --git a/e2e-tests/src/test/fee.rs b/e2e-tests/src/test/fee.rs deleted file mode 100644 index 2a7a79aae6..0000000000 --- a/e2e-tests/src/test/fee.rs +++ /dev/null @@ -1,155 +0,0 @@ -use aleph_client::{ - keypair_from_string, - pallets::{ - balances::{BalanceApi, BalanceUserApi, BalanceUserBatchExtApi}, - fee::TransactionPaymentApi, - }, - sp_runtime::FixedU128, - utility::BlocksApi, - waiting::{AlephWaiting, BlockStatus}, - AccountId, SignedConnection, TxStatus, -}; -use log::info; -use once_cell::sync::Lazy; -use primitives::Balance; - -use crate::{config::setup_test, transfer::setup_for_transfer}; - -/// In order to increase the block occupancy we need to transfer funds to a lot of accounts. This -/// array contains the accounts we will be transferring funds to. -static DESTINATIONS: Lazy> = Lazy::new(|| { - (0..1600) - .map(|i| keypair_from_string(&format!("//{i}")).account_id().clone()) - .collect() -}); - -/// The level of occupancy in a block. -enum BlockOccupancy { - Low, - High, -} - -/// Ensures that the fee multiplier is adjusted according to the block occupancy. -#[tokio::test] -pub async fn fee_calculation() -> anyhow::Result<()> { - let config = setup_test(); - let (connection, _) = setup_for_transfer(config).await; - - let minimal_multiplier = FixedU128::from(1); - - let (no_traffic_fee, no_traffic_multiplier) = current_fees(&connection).await; - info!("No traffic fee (multiplier): {no_traffic_fee} ({no_traffic_multiplier})."); - assert_eq!( - no_traffic_multiplier, minimal_multiplier, - "In the beginning the fee multiplier should be equal to the minimal value", - ); - - fill_blocks(BlockOccupancy::Low, 10, &connection).await; - - let (low_traffic_fee, low_traffic_multiplier) = current_fees(&connection).await; - info!("Low traffic fee (multiplier): {low_traffic_fee} ({low_traffic_multiplier})."); - assert_eq!( - low_traffic_multiplier, no_traffic_multiplier, - "Low traffic shouldn't affect the fee multiplier", - ); - // This might fail if the incremented nonce has longer encoding. Just restart the test. - assert_eq!( - no_traffic_fee, low_traffic_fee, - "Low traffic shouldn't affect the fee" - ); - - fill_blocks(BlockOccupancy::High, 10, &connection).await; - - let (high_traffic_fee, high_traffic_multiplier) = current_fees(&connection).await; - info!("High traffic fee (multiplier): {high_traffic_fee} ({high_traffic_multiplier})."); - assert!( - high_traffic_multiplier > low_traffic_multiplier, - "High traffic should lead to higher fee multiplier", - ); - assert!( - high_traffic_fee > low_traffic_fee, - "High traffic should lead to higher fee" - ); - - fill_blocks(BlockOccupancy::High, 10, &connection).await; - - let (highest_traffic_fee, highest_traffic_multiplier) = current_fees(&connection).await; - info!( - "Highest traffic fee (multiplier): {highest_traffic_fee} ({highest_traffic_multiplier})." - ); - assert!( - highest_traffic_multiplier > high_traffic_multiplier, - "Sustained high traffic should lead to higher fee multiplier", - ); - assert!( - highest_traffic_fee > high_traffic_fee, - "Sustained high traffic should lead to higher fee" - ); - - let now = connection.get_best_block().await.unwrap().unwrap(); - connection - .wait_for_block(|n| n >= now + 10, BlockStatus::Finalized) - .await; - - let (after_traffic_fee, after_traffic_multiplier) = current_fees(&connection).await; - info!("After traffic fee (multiplier): {after_traffic_fee} ({after_traffic_multiplier})."); - assert!( - after_traffic_multiplier < highest_traffic_multiplier, - "Lower traffic should lead to lower fee multiplier", - ); - assert!( - after_traffic_fee < highest_traffic_fee, - "Lower traffic should lead to lower fee multiplier", - ); - - Ok(()) -} - -/// Fill blocks with transfers to increase the block occupancy. -/// -/// The number of consecutive blocks to fill is specified by `blocks` parameter. The level of -/// occupancy in each block is specified by `block_occupancy` parameter. -/// -/// Every batch contains a number of transfers to accounts from `DESTINATIONS` array. The transfer -/// amount is equal to the existential deposit of the chain. -async fn fill_blocks(block_occupancy: BlockOccupancy, blocks: u32, connection: &SignedConnection) { - let limit = match block_occupancy { - // 1100 transfers == 49% weight < 49.5% == 50% of 99% that is maximum real block occupancy for transfer transactions - BlockOccupancy::Low => 1100, - // above 49.5% block weight - BlockOccupancy::High => 1600, - }; - - let existential_deposit = connection - .existential_deposit() - .await - .expect("Failed to get existential deposit"); - - for _ in 0..blocks { - connection - .batch_transfer_keep_alive( - &DESTINATIONS[..limit], - existential_deposit, - TxStatus::InBlock, - ) - .await - .unwrap_or_else(|err| panic!("Error while submitting batch: {err:?}")); - } -} - -/// Submit a single extrinsic and return its fee and the actual fee multiplier. -/// -/// The extrinsic is a transfer to the `//1` account with amount of 1 unit, without tip. -async fn current_fees(connection: &SignedConnection) -> (Balance, FixedU128) { - let actual_multiplier = connection.get_next_fee_multiplier(None).await; - - let to = keypair_from_string("//1").account_id().clone(); - - let tx_info = connection - .transfer_keep_alive(to, 1, TxStatus::Finalized) - .await - .unwrap(); - let fee = connection.get_tx_fee(tx_info).await.unwrap(); - - (fee, actual_multiplier) -} diff --git a/e2e-tests/src/test/mod.rs b/e2e-tests/src/test/mod.rs index df69ebab21..d72276ffd7 100644 --- a/e2e-tests/src/test/mod.rs +++ b/e2e-tests/src/test/mod.rs @@ -8,7 +8,6 @@ pub use button_game::{ pub use electing_validators::authorities_are_staking; pub use era_payout::era_payouts_calculated_correctly; pub use era_validators::era_validators; -pub use fee::fee_calculation; pub use finality_version::{ finality_version_change, schedule_doomed_version_change_and_verify_finalization_stopped, schedule_version_change, @@ -32,7 +31,6 @@ mod electing_validators; mod emergency_finalizer; mod era_payout; mod era_validators; -mod fee; mod finality_version; mod finalization; mod helpers;