Skip to content

Commit

Permalink
Fix failing tests and bump runtime versions (#265)
Browse files Browse the repository at this point in the history
* Fix failing mocks and tests

- Fix energy mocks and tests
- Fix domains mocks
- Fix creator staking mocks

* Update spec_version to 45

* Update transaction_version to 10

* Remove unnecessary migration

* Add missing migrations

* Remove redundant Github action

* Fix evm-addresses pallet build

* Add migration for pallet-xcm

- Fix benchmarking script
  • Loading branch information
F3Joule authored Dec 24, 2024
1 parent 6bc6799 commit ddccfe8
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 182 deletions.
148 changes: 0 additions & 148 deletions .github/workflows/create-runner.yml

This file was deleted.

4 changes: 2 additions & 2 deletions pallets/creator-staking/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ impl ExternalityBuilder {
(3, 10000),
(4, 4900),
(5, 3800),
(6, 10),
(6, REGISTER_DEPOSIT + EXISTENTIAL_DEPOSIT),
(7, 1000),
(8, 2000),
(9, 10000),
(10, 300),
(11, 400),
(20, 10),
(20, REGISTER_DEPOSIT + EXISTENTIAL_DEPOSIT),
(540, EXISTENTIAL_DEPOSIT),
(1337, 1_000_000_000_000),
],
Expand Down
6 changes: 5 additions & 1 deletion pallets/domains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ pub(crate) fn get_reserved_balance(who: &AccountId) -> BalanceOf<Test> {
<Test as pallet_domains::Config>::Currency::reserved_balance(who)
}

pub(crate) fn existential_deposit() -> Balance {
<Test as pallet_balances::Config>::ExistentialDeposit::get()
}

#[derive(Clone)]
pub struct ExtBuilder {
pub(crate) min_domain_length: u32,
Expand Down Expand Up @@ -420,7 +424,7 @@ impl ExtBuilder {

let domain_price = pallet_domains::Pallet::<Test>::calculate_price(&subdomain).unwrap();

let _ = account_with_balance(DOMAIN_OWNER, self.base_domain_deposit + domain_price);
let _ = account_with_balance(DOMAIN_OWNER, self.base_domain_deposit + domain_price + existential_deposit());
assert_ok!(_register_default_domain());
});
ext
Expand Down
14 changes: 7 additions & 7 deletions pallets/energy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl pallet_balances::Config for Test {
type AccountStore = System;
type WeightInfo = ();
type MaxLocks = ();
type MaxReserves = ();
type MaxReserves = ConstU32<2>;
type ReserveIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
Expand Down Expand Up @@ -370,7 +370,7 @@ pub(crate) fn account_with_balance(id: AccountId, balance: Balance) -> AccountId
}

pub(crate) fn set_native_balance(id: AccountId, balance: Balance) {
let _ = pallet_balances::Pallet::<Test>::make_free_balance_be(&id, balance);
let _ = Balances::make_free_balance_be(&id, balance);
}

pub(crate) fn set_energy_balance(id: AccountId, new_balance: Balance) {
Expand Down Expand Up @@ -438,12 +438,12 @@ impl ExtBuilder {
clear_withdraw_fee_args();
clear_corrected_and_deposit_fee_args();

let mut ext: TestExternalities = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap().into();

ext.execute_with(|| {
System::set_block_number(1);
});
let mut ext: TestExternalities = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.expect("Frame system builds valid default genesis config")
.into();

ext.execute_with(|| System::set_block_number(1));
ext
}
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/energy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,21 @@ fn generate_energy_should_work_when_energy_balance_equal_to_existential_deposit(
#[test]
fn generate_energy_should_work_when_caller_have_enough_balance() {
ExtBuilder::default()
.native_existential_deposit(0)
.native_existential_deposit(1)
.value_coefficient(10f64)
.build()
.execute_with(|| {
let caller = account_with_balance(1, 100);
let caller = account_with_balance(1, 101);
let receiver = account(10);

assert_balance!(caller, 100);
assert_total_issuance!(100);
assert_balance!(caller, 101);
assert_total_issuance!(101);
assert_energy_balance!(receiver, 0);
assert_total_energy!(0);

assert_ok!(Energy::generate_energy(RuntimeOrigin::signed(caller), receiver, 100,),);
assert_balance!(caller, 0);
assert_total_issuance!(0);
assert_balance!(caller, 1);
assert_total_issuance!(1);
assert_energy_balance!(receiver, 100);
assert_total_energy!(100);

Expand Down
3 changes: 1 addition & 2 deletions pallets/evm-addresses/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
libsecp256k1 = { version = "0.7.1", default-features = false, features = ["hmac", "static-context"], optional = true }
libsecp256k1 = { version = "0.7.1", default-features = false, features = ["hmac", "static-context"] }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

Expand All @@ -39,7 +39,6 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
]
std = [
"libsecp256k1",
"libsecp256k1/std",
"codec/std",
"scale-info/std",
Expand Down
23 changes: 8 additions & 15 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,14 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
// FIXME: remove if unnecessary
pallet_ownership::migration::v1::MigrateToV1<
Runtime,
Ownership,
OwnershipMigrationV1OldPallet,
>,
(
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
pallet_multisig::migrations::v1::MigrateToV1<Runtime>,
pallet_xcm::migration::v1::MigrateToV1<Runtime>,
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
),
>;

pub struct OwnershipMigrationV1OldPallet;
impl frame_support::traits::Get<&'static str> for OwnershipMigrationV1OldPallet {
fn get() -> &'static str {
"SpaceOwnership"
}
}

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
Expand Down Expand Up @@ -190,10 +183,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subsocial-parachain"),
impl_name: create_runtime_str!("subsocial-parachain"),
authoring_version: 1,
spec_version: 44,
spec_version: 45,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 9,
transaction_version: 10,
state_version: 0,
};

Expand Down
2 changes: 2 additions & 0 deletions runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ parameter_types! {
pub const RelayNetwork: NetworkId = NetworkId::Polkadot;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));

pub CheckAccount: AccountId = PolkadotXcm::check_account();
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down
1 change: 0 additions & 1 deletion scripts/run-benchmark-on.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ OUTPUT_FILE="$2"
--repeat=20 \
--pallet "$PALLET_NAME" \
--extrinsic '*' \
--execution=wasm \
--wasm-execution=Compiled \
--heap-pages=4096 \
--output="$OUTPUT_FILE" \
Expand Down

0 comments on commit ddccfe8

Please sign in to comment.