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 pallet staking tests for starlight (typescript) #782

Merged
merged 29 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2d40c92
Add pallet_pooled_staking to Dancelight
tmpolaczyk Dec 3, 2024
6fca81d
zepter
tmpolaczyk Dec 3, 2024
28286cd
toml-maid
tmpolaczyk Dec 3, 2024
0af422a
Fix benchmark compilation
tmpolaczyk Dec 3, 2024
b2cb4b5
Fix tests
tmpolaczyk Dec 3, 2024
6889dac
Fix benchmark compilation
tmpolaczyk Dec 3, 2024
8dce6fe
Add weights
tmpolaczyk Dec 3, 2024
f78a685
typescript-api
tmpolaczyk Dec 3, 2024
312682e
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 9, 2024
ff19a38
Delay instead of G
tmpolaczyk Dec 9, 2024
d39650c
Add staking integration tests
tmpolaczyk Dec 9, 2024
0abf05d
Merge branch 'master' into tomasz-starlight-staking
tmpolaczyk Dec 9, 2024
0981e2e
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 10, 2024
07a6b9f
One test works
tmpolaczyk Dec 11, 2024
bfcfd26
Give up on second test
tmpolaczyk Dec 11, 2024
eb0e0ff
Add special accounts that need existential deposit to genesis
tmpolaczyk Dec 11, 2024
c3586a8
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 11, 2024
ba95891
Merge remote-tracking branch 'origin/tomasz-starlight-staking' into t…
tmpolaczyk Dec 11, 2024
eb1ff06
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 13, 2024
daaf59d
Undo runtime debug changes
tmpolaczyk Dec 13, 2024
14c4dd5
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 17, 2024
dc70e70
Fix tests
tmpolaczyk Dec 17, 2024
0034ec8
Removed too many awaits, also tests are not working
tmpolaczyk Dec 17, 2024
98177bf
Fix tests
tmpolaczyk Dec 17, 2024
e37c0ff
Remove console.log
tmpolaczyk Dec 17, 2024
561542f
Undo debug logs runtime
tmpolaczyk Dec 17, 2024
8887011
Remove console log
tmpolaczyk Dec 19, 2024
5466276
Merge remote-tracking branch 'origin/master' into tomasz-starlight-st…
tmpolaczyk Dec 19, 2024
c07b40c
Merge branch 'master' into tomasz-starlight-staking-tests
tmpolaczyk Dec 19, 2024
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
17 changes: 9 additions & 8 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)],
tmpolaczyk marked this conversation as resolved.
Show resolved Hide resolved
});
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
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
Loading