Skip to content

Commit

Permalink
Merge branch 'master' into jeremy-iforgor-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk authored Dec 20, 2024
2 parents 2bbe899 + b4fa19d commit 6599dde
Show file tree
Hide file tree
Showing 8 changed files with 967 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ parameter_types! {
}

// Holesky: https://github.com/eth-clients/holesky
// Fork versions: https://github.com/eth-clients/holesky/blob/main/metadata/config.yaml
#[cfg(not(any(
feature = "std",
feature = "fast-runtime",
Expand All @@ -117,19 +118,19 @@ parameter_types! {
epoch: 0,
},
altair: Fork {
version: hex_literal::hex!("01017000"), // 0x01017000
version: hex_literal::hex!("02017000"), // 0x02017000
epoch: 0,
},
bellatrix: Fork {
version: hex_literal::hex!("01017000"), // 0x01017000
version: hex_literal::hex!("03017000"), // 0x03017000
epoch: 0,
},
capella: Fork {
version: hex_literal::hex!("01017001"), // 0x01017001
version: hex_literal::hex!("04017000"), // 0x04017000
epoch: 256,
},
deneb: Fork {
version: hex_literal::hex!("01017002"), // 0x01017002
version: hex_literal::hex!("05017000"), // 0x05017000
epoch: 29696,
},
};
Expand Down
20 changes: 10 additions & 10 deletions test/suites/dev-tanssi-relay/inflation-rewards/test-rewards.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "@tanssi/api-augment";
import { describeSuite, expect, beforeAll, DevModeContext } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";
import { Header, ParaId, HeadData, Digest, DigestItem } from "@polkadot/types/interfaces";
import { Header, ParaId, HeadData, Digest, DigestItem, Slot } from "@polkadot/types/interfaces";
import { KeyringPair } from "@moonwall/util";
import { fetchIssuance, filterRewardFromContainer, jumpToSession } from "util/block";
import { DANCELIGHT_BOND } from "util/constants";
import { numberToHex, stringToHex } from "@polkadot/util";
import { stringToHex } from "@polkadot/util";
//5EYCAe5cHUC3LZehbwavqEb95LcNnpBzfQTsAxeUibSo1Gtb

// Helper function to make rewards work for a specific block and slot.
Expand All @@ -25,22 +25,23 @@ async function mockAndInsertHeadData(
const relayApi = context.polkadotJs();
const aura_engine_id = stringToHex("aura");

const digestItem: DigestItem = await relayApi.createType("DigestItem", {
PreRuntime: [aura_engine_id, numberToHex(slotNumber, 64)],
const slotNumberT: Slot = relayApi.createType("Slot", slotNumber);
const digestItem: DigestItem = relayApi.createType("DigestItem", {
PreRuntime: [aura_engine_id, slotNumberT.toHex(true)],
});
const digest: Digest = await relayApi.createType("Digest", {
const digest: Digest = relayApi.createType("Digest", {
logs: [digestItem],
});
const header: Header = await relayApi.createType("Header", {
const header: Header = relayApi.createType("Header", {
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
number: blockNumber,
stateRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
extrinsicsRoot: "0x0000000000000000000000000000000000000000000000000000000000000000",
digest,
});

const headData: HeadData = await relayApi.createType("HeadData", header.toHex());
const paraHeadKey = await relayApi.query.paras.heads.key(paraId);
const headData: HeadData = relayApi.createType("HeadData", header.toHex());
const paraHeadKey = relayApi.query.paras.heads.key(paraId);

await context.createBlock(
relayApi.tx.sudo
Expand Down Expand Up @@ -116,12 +117,11 @@ describeSuite({
// The first account of container 2000 will be rewarded.
const accountToReward: string = assignment.containerChains[2000][0];

const { block } = await context.createBlock();
const accountBalanceBefore = (
await polkadotJs.query.system.account(accountToReward)
).data.free.toBigInt();

await mockAndInsertHeadData(context, 2000, block.duration, 2, alice);
await mockAndInsertHeadData(context, 2000, 2, 2, alice);
await context.createBlock();

const currentChainRewards = (await polkadotJs.query.inflationRewards.chainsToReward()).unwrap();
Expand Down
110 changes: 110 additions & 0 deletions test/suites/dev-tanssi-relay/staking/test_staking_join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import "@tanssi/api-augment";
import { describeSuite, beforeAll, expect } from "@moonwall/cli";
import { KeyringPair } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { numberToHex } from "@polkadot/util";
import { jumpToBlock } from "../../../util/block";

describeSuite({
id: "DT0301",
title: "Fee test suite",
foundationMethods: "dev",
testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;
let alice: KeyringPair;
let bob: KeyringPair;
// TODO: don't hardcode the period here
const sessionPeriod = 10;

beforeAll(async () => {
alice = context.keyring.alice;
bob = context.keyring.bob;
polkadotJs = context.polkadotJs();

// Add alice and box keys to pallet session. In dancebox they are already there in genesis.
const newKey1 = await polkadotJs.rpc.author.rotateKeys();
const newKey2 = await polkadotJs.rpc.author.rotateKeys();

await context.createBlock([
await polkadotJs.tx.session.setKeys(newKey1, []).signAsync(alice),
await polkadotJs.tx.session.setKeys(newKey2, []).signAsync(bob),
]);
});

it({
id: "E01",
title: "Cannot execute stake join before 2 sessions",
test: async function () {
const initialSession = 0;
const tx = polkadotJs.tx.pooledStaking.requestDelegate(
alice.address,
"AutoCompounding",
10000000000000000n
);
await context.createBlock([await tx.signAsync(alice)]);
const events = await polkadotJs.query.system.events();
const ev1 = events.filter((a) => {
return a.event.method == "IncreasedStake";
});
expect(ev1.length).to.be.equal(1);
const ev2 = events.filter((a) => {
return a.event.method == "UpdatedCandidatePosition";
});
expect(ev2.length).to.be.equal(1);
const ev3 = events.filter((a) => {
return a.event.method == "RequestedDelegate";
});
expect(ev3.length).to.be.equal(1);

const stakingCandidates = await polkadotJs.query.pooledStaking.sortedEligibleCandidates();
expect(stakingCandidates.toJSON()).to.deep.equal([
{
candidate: alice.address,
stake: numberToHex(10000000000000000, 128),
},
]);

// Ensure that executePendingOperations can only be executed after 2 sessions, meaning that if the
// current session number is 0, we must wait until after the NewSession event for session 2.
// Jump to block 9
await jumpToBlock(context, 2 * sessionPeriod - 1);
const tx2 = polkadotJs.tx.pooledStaking.executePendingOperations([
{
delegator: alice.address,
operation: {
JoiningAutoCompounding: {
candidate: alice.address,
at: initialSession,
},
},
},
]);

await context.createBlock([await tx2.signAsync(bob)]);
// executePendingOperations failed
const events2 = await polkadotJs.query.system.events();
const ev4 = events2.filter((a) => {
return a.event.method == "ExtrinsicFailed";
});
expect(ev4.length).to.be.equal(1);

// We are now in block 19, jump to block 21
await context.createBlock();
await context.createBlock();

// Now the executePendingOperations should succeed
await context.createBlock([await tx2.signAsync(bob)]);

const events3 = await polkadotJs.query.system.events();
const ev5 = events3.filter((a) => {
return a.event.method == "StakedAutoCompounding";
});
expect(ev5.length).to.be.equal(1);
const ev6 = events3.filter((a) => {
return a.event.method == "ExecutedDelegate";
});
expect(ev6.length).to.be.equal(1);
},
});
},
});
Loading

0 comments on commit 6599dde

Please sign in to comment.