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

Add orbiter notify_inactive_collator tests #2683

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions node/service/src/chain_spec/moonbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use hex_literal::hex;
use moonbase_runtime::{
currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig,
CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EligibilityValue, EthereumChainIdConfig,
EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig,
EthereumConfig, GenesisAccount, InflationInfo, MaintenanceModeConfig, MoonbeamOrbitersConfig,
OpenTechCommitteeCollectiveConfig, ParachainInfoConfig, ParachainStakingConfig,
PolkadotXcmConfig, Precompiles, Range, RuntimeGenesisConfig, SudoConfig, SystemConfig,
TransactionPaymentConfig, TreasuryCouncilCollectiveConfig, XcmTransactorConfig, HOURS,
Expand All @@ -38,7 +38,7 @@ use pallet_transaction_payment::Multiplier;
use sc_service::ChainType;
#[cfg(test)]
use sp_core::ecdsa;
use sp_runtime::{Perbill, Percent};
use sp_runtime::{traits::One, Perbill, Percent};

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;
Expand Down Expand Up @@ -331,6 +331,9 @@ pub fn testnet_genesis(
multiplier: Multiplier::from(8u128),
..Default::default()
},
moonbeam_orbiters: MoonbeamOrbitersConfig {
min_orbiter_deposit: One::one(),
},
xcm_transactor: XcmTransactorConfig {
relay_indices: moonbeam_relay_encoder::westend::WESTEND_RELAY_INDICES,
..Default::default()
Expand Down
1 change: 0 additions & 1 deletion pallets/moonbeam-orbiters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ pub mod pallet {
pub min_orbiter_deposit: BalanceOf<T>,
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ construct_runtime! {
XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Config<T>, Storage, Event<T>} = 33,
ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config<T>} = 34,
// Previously 36: pallet_assets::<Instance1>
MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event<T>} = 37,
MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event<T>, Config<T>} = 37,
EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin} = 38,
Randomness: pallet_randomness::{Pallet, Call, Storage, Event<T>, Inherent} = 39,
TreasuryCouncilCollective:
Expand Down
2 changes: 1 addition & 1 deletion test/suites/chopsticks/test-upgrade-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiPromise } from "@polkadot/api";
import { parseEther } from "ethers";

describeSuite({
id: "R01",
id: "C01",
title: "Chopsticks Upgrade",
foundationMethods: "chopsticks",
testCases: ({ it, context, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/sample/sample_basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BN } from "@polkadot/util";
import { ApiPromise } from "@polkadot/api";

describeSuite({
id: "D014001",
id: "D014201",
title: "Dev test suite",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { blake2AsHex } from "@polkadot/util-crypto";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";

describeSuite({
id: "D010902",
id: "D010901",
title: "Democracy - Preimage",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { beforeEach, describeSuite, expect, instantFastTrack } from "@moonwall/c
import { ALITH_ADDRESS, GLMR, KeyringPair, VOTE_AMOUNT, generateKeyringPair } from "@moonwall/util";

describeSuite({
id: "D010904",
id: "D010902",
title: "Democracy - Referendum",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { alith } from "@moonwall/util";
import "@polkadot/api-augment";

describeSuite({
id: "D4008",
id: "D010903",
title: "Referenda - FastGeneralAdmin",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { alith } from "@moonwall/util";
import "@polkadot/api-augment";

describeSuite({
id: "D010905",
id: "D010904",
title: "Referenda - GeneralAdmin",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { expectOk } from "../../../../helpers";
import { ApiPromise } from "@polkadot/api";

describeSuite({
id: "D5001",
id: "D012301",
title: "Lazy Migrations Pallet - Clear Suicided Storage",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-multisigs/test-multisigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
// TODO: Make the test cases atomic

describeSuite({
id: "D012301",
id: "D012401",
title: "Multisigs - perform multisigs operations",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@moonbeam-network/api-augment";
import { customDevRpcRequest, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "D012401",
id: "D012501",
title: "Node - RPC",
foundationMethods: "dev",
testCases: ({ context, it }) => {
Expand Down
155 changes: 155 additions & 0 deletions test/suites/dev/moonbase/test-orbiters/test-orbiters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { describeSuite, expect } from "@moonwall/cli";
import "@moonbeam-network/api-augment";
import { alith, baltathar, charleth, dorothy, ethan, faith, goliath } from "@moonwall/util";
import { jumpRounds } from "../../../../helpers";

describeSuite({
id: "D012601",
title: "Orbiters",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
it({
id: "T01",
title: "Marking orbiters offline is a noop",
test: async function () {
const minCandidateStk = context.polkadotJs().consts.parachainStaking.minCandidateStk;
await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parachainStaking.setBlocksPerRound(10))
.signAsync(alith),
],
{ allowFailures: false }
);

await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parachainStaking.enableMarkingOffline(true))
.signAsync(alith),
],
{ allowFailures: false }
);

// ceil(2 / 3 * 8) = 6 collators are needed to be able to mark
// collators offline. Alith is arleady a collator so 5 extra
// are added.
const collators = [baltathar, charleth, dorothy, ethan, faith];

const joinCandidateTxs = collators.map((c, i) =>
context
.polkadotJs()
.tx.parachainStaking.joinCandidates(minCandidateStk, 1 + i)
.signAsync(c)
);
await context.createBlock(joinCandidateTxs, { allowFailures: false });

const orbiterPool = collators[1];
const orbiter = goliath;

await context.createBlock(
[
context
.polkadotJs()
.tx.sudo.sudo(
context.polkadotJs().tx.moonbeamOrbiters.addCollator(orbiterPool.address)
)
.signAsync(alith),
],
{ allowFailures: false }
);

await context.createBlock(
context.polkadotJs().tx.moonbeamOrbiters.orbiterRegister().signAsync(orbiter),
{ allowFailures: false }
);

await context.createBlock(
context
.polkadotJs()
.tx.moonbeamOrbiters.collatorAddOrbiter(orbiter.address)
.signAsync(orbiterPool),
{ allowFailures: false }
);

// Advance some rounds so orbiter is set to active and it goes
// some rounds without producing blocks
await jumpRounds(context, 6);

const afterOrbiterActiveRound = await context.polkadotJs().query.parachainStaking.round();
const afterOrbiterActiveOrbiter = await context
.polkadotJs()
.query.moonbeamOrbiters.orbiterPerRound(
afterOrbiterActiveRound.current,
orbiterPool.address
);
expect(afterOrbiterActiveOrbiter.toString()).toEqual(orbiter.address);

const notifyInactiveOrbiter = await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiter.address)
.signAsync(alith),
{ allowFailures: true }
);

expect(notifyInactiveOrbiter.result!.successful).toEqual(false);
expect(notifyInactiveOrbiter.result!.error!.name).toEqual("CannotBeNotifiedAsInactive");

// Call to mark an orbiterPool that has not produced blocks offline
// should succeed but it should be an noop (pool will still be active) if there are is an
// active orbiter in the pool
await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiterPool.address)
.signAsync(alith),
{ allowFailures: false }
);

const afterNoopNotifyInfo = await context
.polkadotJs()
.query.parachainStaking.candidateInfo(orbiterPool.address);
expect(afterNoopNotifyInfo.unwrap().status.isActive).toBe(true);

await context.createBlock(
context
.polkadotJs()
.tx.moonbeamOrbiters.collatorRemoveOrbiter(orbiter.address)
.signAsync(orbiterPool),
{ allowFailures: false }
);

// Advance rounds so that the orbiter gets rotated out of the pool
// and the OrbiterPerRoundEntry is cleared
await jumpRounds(context, 6);

// Marking the orbiter pool without active orbiters should
// make the orbiter pool idle
await context.createBlock(
context
.polkadotJs()
.tx.parachainStaking.notifyInactiveCollator(orbiterPool.address)
.signAsync(alith),
{ allowFailures: false }
);

const afterRemoveOrbiterRound = await context.polkadotJs().query.parachainStaking.round();
const afterRemoveOrbiterOrbiter = await context
.polkadotJs()
.query.moonbeamOrbiters.orbiterPerRound(
afterRemoveOrbiterRound.current,
orbiterPool.address
);
expect(afterRemoveOrbiterOrbiter.isNone).toBe(true);

const afterOrbiterRemoveInfo = await context
.polkadotJs()
.query.parachainStaking.candidateInfo(orbiterPool.address);
expect(afterOrbiterRemoveInfo.unwrap().status.isIdle).toBe(true);
},
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describeSuite, expect } from "@moonwall/cli";
import { ALITH_ADDRESS, GLMR, generateKeyringPair } from "@moonwall/util";

describeSuite({
id: "D012501",
id: "D012701",
title: "Polkadot API",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@moonbeam-network/api-augment";
import { customDevRpcRequest, describeSuite, expect } from "@moonwall/cli";

describeSuite({
id: "D012502",
id: "D012702",
title: "Web3Api Information",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-pov/test-evm-over-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Abi, encodeFunctionData } from "viem";
import { expectEVMResult, HeavyContract, deployHeavyContracts } from "../../../../helpers";

describeSuite({
id: "D012601",
id: "D012801",
title: "PoV controlled by gasLimit",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-pov/test-evm-over-pov2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";

describeSuite({
id: "D012602",
id: "D012802",
title: "PoV Limit (3.5Mb in Dev)",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiPromise } from "@polkadot/api";
import { u128 } from "@polkadot/types";

describeSuite({
id: "D012603",
id: "D012803",
title: "Remove LocalAssets storage - PoV Size validation",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Abi, encodeFunctionData } from "viem";
import { ALITH_ADDRESS, PRECOMPILE_BATCH_ADDRESS, createEthersTransaction } from "@moonwall/util";

describeSuite({
id: "D012604",
id: "D012804",
title: "PoV precompile test - gasLimit",
foundationMethods: "dev",
testCases: ({ context, log, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";

describeSuite({
id: "D012605",
id: "D012805",
title: "PoV precompile test - PoV Limit (3.5Mb in Dev)",
foundationMethods: "dev",
testCases: ({ context, log, it }) => {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { GAS_LIMIT_POV_RATIO } from "@moonwall/util";

describeSuite({
id: "D012606",
id: "D012806",
title: "XCM to EVM - PoV tests",
foundationMethods: "dev",
testCases: ({ context, log, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Abi, encodeFunctionData } from "viem";
import { extractRevertReason } from "../../../../helpers";

describeSuite({
id: "D012701",
id: "D012901",
title: "Precompiles - Assets-ERC20 (LocalAssets Removal)",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Abi, encodeFunctionData } from "viem";
import { mockAssetBalance } from "../../../../helpers";

describeSuite({
id: "D012702",
id: "D012902",
title: "Precompiles - Low Level Transactions",
foundationMethods: "dev",
testCases: ({ context, log, it }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Abi, decodeAbiParameters, encodeFunctionData } from "viem";
import { mockAssetBalance } from "../../../../helpers";

describeSuite({
id: "D012703",
id: "D012903",
title: "Precompiles - Assets-ERC20 Wasm",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mockAssetBalance } from "../../../../helpers";
import { Abi, encodeFunctionData } from "viem";

describeSuite({
id: "D012704",
id: "D012904",
title: "",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mockAssetBalance } from "../../../../helpers";
import { Abi, encodeFunctionData } from "viem";

describeSuite({
id: "D012705",
id: "D012905",
title: "Precompiles - Assets-ERC20 Wasm",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
Expand Down
Loading
Loading