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

Proxy sudo validator, session-key management, and staking #794

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ pub enum ProxyType {
Auction,
OnDemandOrdering,
SudoRegistrar,
SudoValidatorManagement,
SessionKeyManagement,
Staking,
}
impl Default for ProxyType {
fn default() -> Self {
Expand Down Expand Up @@ -914,6 +917,22 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
}
_ => false,
},
ProxyType::SudoValidatorManagement => match c {
RuntimeCall::Sudo(pallet_sudo::Call::sudo { call: ref x }) => {
matches!(
x.as_ref(),
&RuntimeCall::ExternalValidators(..)
| &RuntimeCall::ExternalValidatorSlashes(..)
)
}
_ => false,
},
ProxyType::SessionKeyManagement => {
matches!(c, RuntimeCall::Session(..))
}
ProxyType::Staking => {
matches!(c, RuntimeCall::Session(..) | RuntimeCall::PooledStaking(..))
}
}
}
fn is_superset(&self, o: &Self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import "@tanssi/api-augment";
import { describeSuite, expect, beforeAll } from "@moonwall/cli";
import { KeyringPair } from "@moonwall/util";
import { ApiPromise } from "@polkadot/api";
import { initializeCustomCreateBlock } from "../../../util/block";

describeSuite({
id: "DTR1201",
title: "Proxy test suite",
foundationMethods: "dev",
testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;
let sudoAlice: KeyringPair;
let delegateBob: KeyringPair;
const VALIDATOR_PROXY_INDEX = 8;

beforeAll(() => {
initializeCustomCreateBlock(context);

sudoAlice = context.keyring.alice;
delegateBob = context.keyring.bob;

polkadotJs = context.polkadotJs();
});

it({
id: "E01",
title: "Can add proxy",
test: async function () {
await context.createBlock();

const tx = polkadotJs.tx.proxy.addProxy(delegateBob.address, VALIDATOR_PROXY_INDEX, 0);
await context.createBlock([await tx.signAsync(sudoAlice)]);

const proxies = await polkadotJs.query.proxy.proxies(sudoAlice.address);
expect(proxies.toJSON()[0]).to.deep.equal([
{
delegate: delegateBob.address,
proxyType: "SudoValidatorManagement",
delay: 0,
},
]);
},
});

it({
id: "E02",
title: "Delegated account can sudo txs in external validators",
test: async function () {
const txAddWhitelisted = polkadotJs.tx.proxy.proxy(
sudoAlice.address,
null,
polkadotJs.tx.sudo.sudo(polkadotJs.tx.externalValidators.addWhitelisted(delegateBob.address))
);
await context.createBlock([await txAddWhitelisted.signAsync(delegateBob)]);

const whitelistedValidatorInfo = await polkadotJs.query.externalValidators.whitelistedValidators();
expect(whitelistedValidatorInfo.toHuman().includes(delegateBob.address)).to.be.true;
},
});

it({
id: "E02",
title: "Delegated account can sudo txs in external validator slashes",
test: async function () {
const txAddWhitelisted = polkadotJs.tx.proxy.proxy(
sudoAlice.address,
null,
polkadotJs.tx.sudo.sudo(
polkadotJs.tx.externalValidatorSlashes.forceInjectSlash(0, sudoAlice.address, 1000)
)
);
await context.createBlock([await txAddWhitelisted.signAsync(delegateBob)]);

const DeferPeriod = (await polkadotJs.consts.externalValidatorSlashes.slashDeferDuration).toNumber();

// scheduled slashes
const expectedSlashes = await polkadotJs.query.externalValidatorSlashes.slashes(DeferPeriod + 1);
expect(expectedSlashes.length).to.be.eq(1);
},
});
},
});
77 changes: 77 additions & 0 deletions test/suites/dev-tanssi-relay/proxy/test-session-keys-management.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import "@polkadot/api-augment";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";

describeSuite({
id: "DT0601",
title: "Proxy test suite - ProxyType::SessionKeyManagement",
foundationMethods: "dev",
testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;
const sessionKeysManagementProxy = 9;
const someKeys = "0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF";

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

it({
id: "E01",
title: "Delegate account can manage keys",
test: async function () {
const delegator_alice = context.keyring.alice;
const delegate_charlie = context.keyring.charlie;

let tx = polkadotJs.tx.proxy.addProxy(delegate_charlie.address, sessionKeysManagementProxy, 0);
await context.createBlock([await tx.signAsync(delegator_alice)]);

let events = await polkadotJs.query.system.events();
let ev1 = events.filter((a) => {
return a.event.method == "ProxyAdded";
});
expect(ev1.length).to.be.equal(1);

await context.createBlock();

tx = polkadotJs.tx.proxy.proxy(
delegator_alice.address,
null,
polkadotJs.tx.session.setKeys(someKeys, "0x")
);
await context.createBlock([await tx.signAsync(delegate_charlie)]);
events = await polkadotJs.query.system.events();
ev1 = events.filter((a) => {
return a.event.method == "ProxyExecuted";
});
expect(ev1.length).to.be.equal(1);
expect(ev1[0].event.data[0].toString()).to.be.eq("Ok");
},
});

it({
id: "E02",
title: "Non-Delegate account fails to manage other account's keys",
test: async function () {
const alice = context.keyring.alice;
const non_delegate_dave = context.keyring.dave;

await context.createBlock();

const tx = polkadotJs.tx.proxy.proxy(
alice.address,
null,
polkadotJs.tx.session.setKeys(
"0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF",
"0x"
)
);
await context.createBlock([await tx.signAsync(non_delegate_dave)]);
const events = await polkadotJs.query.system.events();
const ev1 = events.filter((a) => {
return a.event.method == "ProxyExecuted";
});
expect(ev1.length).to.be.equal(0);
},
});
},
});
18 changes: 18 additions & 0 deletions typescript-api/src/dancelight/interfaces/augment-api-tx.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions typescript-api/src/dancelight/interfaces/lookup.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion typescript-api/src/dancelight/interfaces/types-lookup.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading