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

Reward block author in Dancelight #784

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,17 @@ impl pallet_timestamp::Config for Runtime {
type WeightInfo = weights::pallet_timestamp::SubstrateWeight<Runtime>;
}

pub struct RewardPoints;

impl pallet_authorship::EventHandler<AccountId, BlockNumberFor<Runtime>> for RewardPoints {
fn note_author(author: AccountId) {
ExternalValidatorsRewards::reward_by_ids(vec![(author, 20u32)])
}
}

impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type EventHandler = ();
type EventHandler = RewardPoints;
}

impl_opaque_keys! {
Expand Down
7 changes: 7 additions & 0 deletions solo-chains/runtime/dancelight/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ impl ExtBuilder {
pallet_sudo::GenesisConfig::<Runtime> { key: self.sudo }
.assimilate_storage(&mut t)
.unwrap();

snowbridge_pallet_system::GenesisConfig::<Runtime> {
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();

t
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import "@tanssi/api-augment";
import { describeSuite, customDevRpcRequest, expect, beforeAll } from "@moonwall/cli";
import { ApiPromise, Keyring } from "@polkadot/api";
import { jumpToSession } from "util/block";

describeSuite({
id: "DTR1601",
title: "Paras inherent tests",
foundationMethods: "dev",

testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;

beforeAll(async () => {
polkadotJs = context.polkadotJs();
});

it({
id: "E01",
title: "para candidates should trigger reward info",
test: async function () {
const keyring = new Keyring({ type: "sr25519" });
const aliceStash = keyring.addFromUri("//Alice//stash");
await context.createBlock();
// Send RPC call to enable para inherent candidate generation
await customDevRpcRequest("mock_enableParaInherentCandidate", []);
// Since collators are not assigned until session 2, we need to go till session 2 to actually see heads being injected
await jumpToSession(context, 3);
await context.createBlock();

// we are still in era 0
const validatorRewards = await context
.polkadotJs()
.query.externalValidatorsRewards.rewardPointsForEra(0);
const totalRewards = validatorRewards.total.toBigInt();

expect(totalRewards).to.be.greaterThan(0n);
tmpolaczyk marked this conversation as resolved.
Show resolved Hide resolved
// All of them come from alice as she is the only one validating candidates
expect(validatorRewards.individual.toHuman()[aliceStash.address]).to.be.eq(totalRewards.toString());
},
});

it({
id: "E02",
title: "Check rewards storage clears after historyDepth",
test: async function () {
const sessionsPerEra = await polkadotJs.consts.externalValidators.sessionsPerEra;
const historyDepth = await polkadotJs.consts.externalValidatorsRewards.historyDepth;

const currentIndex = await polkadotJs.query.session.currentIndex();

const targetSession =
currentIndex.toNumber() + sessionsPerEra.toNumber() * (historyDepth.toNumber() + 1);

await jumpToSession(context, targetSession);

const validatorRewards = await context
.polkadotJs()
.query.externalValidatorsRewards.rewardPointsForEra(0);
const totalRewards = validatorRewards.total.toBigInt();

// rewards should have expired
expect(totalRewards).to.be.equal(0n);
},
});
},
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@tanssi/api-augment";
import { describeSuite, customDevRpcRequest, expect, beforeAll } from "@moonwall/cli";

Check failure on line 2 in test/suites/dev-tanssi-relay/external-validators-rewards/test_external_validator_rewards.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'customDevRpcRequest' is defined but never used
import { ApiPromise, Keyring } from "@polkadot/api";
import { jumpToSession } from "util/block";

describeSuite({
id: "DTR1601",
id: "DTR1602",
title: "Paras inherent tests",
foundationMethods: "dev",

Expand All @@ -22,11 +22,6 @@
const keyring = new Keyring({ type: "sr25519" });
const aliceStash = keyring.addFromUri("//Alice//stash");
await context.createBlock();
// Send RPC call to enable para inherent candidate generation
await customDevRpcRequest("mock_enableParaInherentCandidate", []);
// Since collators are not assigned until session 2, we need to go till session 2 to actually see heads being injected
await jumpToSession(context, 3);
await context.createBlock();

// we are still in era 0
const validatorRewards = await context
Expand Down
Loading