Skip to content

Commit

Permalink
Setup example upgrade for integration test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Jan 21, 2025
1 parent 4559624 commit f23f195
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ jobs:
with:
workspaces: integration_tests/
cache-on-failure: true
- name: Tests the Tethys upgrade
run: tests/run-upgrade-test.sh v1.4.0
- name: Tests the EXAMPLE upgrade
run: tests/run-upgrade-test.sh v1.5.1
8 changes: 8 additions & 0 deletions app/upgrades/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Example Upgrade

The *Example* upgrade contains the following changes.

## Summary of Changes

* First bullet point here
* Second bullet point here
33 changes: 33 additions & 0 deletions app/upgrades/example/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package example

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

var PlanName = "example"

func GetExampleUpgradeHandler(
mm *module.Manager, configurator *module.Configurator, crisisKeeper *crisiskeeper.Keeper, distrKeeper *distrkeeper.Keeper,
) func(
ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap,
) (module.VersionMap, error) {
if mm == nil {
panic("Nil argument to GetExampleUpgradeHandler")
}
return func(ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Module Consensus Version Map", "vmap", vmap)

ctx.Logger().Info("Example Upgrade: Running any configured module migrations")
out, outErr := mm.RunMigrations(ctx, *configurator, vmap)

ctx.Logger().Info("Asserting invariants after upgrade")
crisisKeeper.AssertInvariants(ctx)

ctx.Logger().Info("Example Upgrade Successful")
return out, outErr
}
}
6 changes: 6 additions & 0 deletions app/upgrades/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"

"github.com/AltheaFoundation/althea-L1/app/upgrades/example"
"github.com/AltheaFoundation/althea-L1/app/upgrades/tethys"
)

Expand All @@ -25,4 +26,9 @@ func RegisterUpgradeHandlers(
tethys.PlanName,
tethys.GetTethysUpgradeHandler(mm, configurator, crisisKeeper, distrKeeper),
)
// EXAMPLE upgrade
upgradeKeeper.SetUpgradeHandler(
example.PlanName,
example.GetExampleUpgradeHandler(mm, configurator, crisisKeeper, distrKeeper),
)
}
47 changes: 5 additions & 42 deletions integration_tests/test_runner/src/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use super::erc20_conversion::erc20_conversion_test;
use super::microtx_fees::microtx_fees_test;
use super::native_token::native_token_test;

pub const UPGRADE_NAME: &str = "tethys";
pub const UPGRADE_NAME: &str = "example";
const UPGRADE_BLOCK_DELTA: u64 = 20;

/// Perform a series of integration tests to seed the system with data, then submit and pass a chain
/// upgrade proposal
Expand Down Expand Up @@ -102,7 +103,7 @@ pub async fn run_upgrade(
} else {
panic!("Chain is not moving!");
};
let upgrade_height = (curr_height + 40) as i64;
let upgrade_height = (curr_height + UPGRADE_BLOCK_DELTA) as i64;
let upgrade_prop_params = UpgradeProposalParams {
upgrade_height,
plan_name,
Expand Down Expand Up @@ -161,49 +162,11 @@ pub async fn run_all_recoverable_tests(
#[allow(clippy::too_many_arguments)]
pub async fn run_upgrade_specific_tests(
_web30: &Web3,
althea_contact: &Contact,
_althea_contact: &Contact,
_ibc_contact: &Contact,
_keys: Vec<ValidatorKeys>,
_ibc_keys: Vec<CosmosPrivateKey>,
_erc20_addresses: Vec<EthAddress>,
post_upgrade: bool,
_post_upgrade: bool,
) {
let mut distr_grpc = DistributionQueryClient::connect(althea_contact.get_url())
.await
.expect("Unable to connect distribution query client");

let params = distr_grpc
.params(QueryParamsRequest {})
.await
.expect("Unable to get params")
.into_inner()
.params
.expect("No params returned");

info!("Got Params: {:?}", params);

// The params values are returned as difficult to handle strings:
// 50% would be "500000000000000000", which we divide by 10^18 to account for precision to get 0.5
let precision = 10f64.powi(18);
let base_pr: f64 = params.base_proposer_reward.parse::<f64>().unwrap() / precision;
let bonus_pr: f64 = params.bonus_proposer_reward.parse::<f64>().unwrap() / precision;
let epsilon = f64::EPSILON;
match post_upgrade {
false => {
// The base reward should not yet be ~0.5 and the bonus reward should not yet be ~0.04
info!(
"Expecting base reward {} != 0.5 or bonus reward {} != 0.04",
base_pr, bonus_pr
);
assert!(((base_pr - 0.5).abs() > epsilon) || ((bonus_pr - 0.04).abs() > epsilon));
}
true => {
// The base reward should now be ~0.5 and the bonus reward should now be ~0.04
info!(
"Expecting base reward {} ~= 0.5 and bonus reward {} ~= 0.04",
base_pr, bonus_pr
);
assert!(((base_pr - 0.5).abs() <= epsilon) && ((bonus_pr - 0.04).abs() <= epsilon));
}
}
}

0 comments on commit f23f195

Please sign in to comment.