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

[MOON-1737] adds IdentityJudgement Proxy type support #1597

Merged
merged 8 commits into from
Jun 20, 2022
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
6 changes: 6 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ pub enum ProxyType {
Balances = 5,
/// Allow extrinsic related to AuthorMapping.
AuthorMapping = 6,
/// Allow extrinsic related to IdentityJudgement.
IdentityJudgement = 7,
}

impl Default for ProxyType {
Expand Down Expand Up @@ -833,6 +835,10 @@ impl InstanceFilter<Call> for ProxyType {
),
ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)),
ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)),
ProxyType::IdentityJudgement => matches!(
c,
Call::Identity(pallet_identity::Call::provide_judgement { .. }) | Call::Utility(..)
),
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ fn verify_proxy_type_indices() {
assert_eq!(moonbase_runtime::ProxyType::CancelProxy as u8, 4);
assert_eq!(moonbase_runtime::ProxyType::Balances as u8, 5);
assert_eq!(moonbase_runtime::ProxyType::AuthorMapping as u8, 6);
assert_eq!(moonbase_runtime::ProxyType::IdentityJudgement as u8, 7);
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ pub enum ProxyType {
Balances = 5,
/// Allow extrinsic related to AuthorMapping.
AuthorMapping = 6,
/// Allow extrinsic related to IdentityJudgement.
IdentityJudgement = 7,
}

impl Default for ProxyType {
Expand Down Expand Up @@ -844,6 +846,10 @@ impl InstanceFilter<Call> for ProxyType {
),
ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)),
ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)),
ProxyType::IdentityJudgement => matches!(
c,
Call::Identity(pallet_identity::Call::provide_judgement { .. }) | Call::Utility(..)
),
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ fn verify_proxy_type_indices() {
assert_eq!(moonbeam_runtime::ProxyType::CancelProxy as u8, 4);
assert_eq!(moonbeam_runtime::ProxyType::Balances as u8, 5);
assert_eq!(moonbeam_runtime::ProxyType::AuthorMapping as u8, 6);
assert_eq!(moonbeam_runtime::ProxyType::IdentityJudgement as u8, 7);
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ pub enum ProxyType {
Balances = 5,
/// Allow extrinsic related to AuthorMapping.
AuthorMapping = 6,
/// Allow extrinsic related to IdentityJudgement.
IdentityJudgement = 7,
}

impl Default for ProxyType {
Expand Down Expand Up @@ -850,6 +852,10 @@ impl InstanceFilter<Call> for ProxyType {
),
ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)),
ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)),
ProxyType::IdentityJudgement => matches!(
c,
Call::Identity(pallet_identity::Call::provide_judgement { .. }) | Call::Utility(..)
),
}
}

Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ fn verify_proxy_type_indices() {
assert_eq!(moonriver_runtime::ProxyType::CancelProxy as u8, 4);
assert_eq!(moonriver_runtime::ProxyType::Balances as u8, 5);
assert_eq!(moonriver_runtime::ProxyType::AuthorMapping as u8, 6);
assert_eq!(moonriver_runtime::ProxyType::IdentityJudgement as u8, 7);
}

#[test]
Expand Down
115 changes: 115 additions & 0 deletions tests/tests/test-proxy/test-proxy-identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import "@polkadot/api-augment";
import "@moonbeam-network/api-augment";
import { expect } from "chai";
import { alith, baltathar } from "../../util/accounts";

import { describeDevMoonbeam } from "../../util/setup-dev-tests";

describeDevMoonbeam("Proxy : IdentityJudgement fails without proxy", (context) => {
before("setup one identity and registrar", async () => {
const block = await context.createBlock([
context.polkadotApi.tx.sudo.sudo(context.polkadotApi.tx.identity.addRegistrar(alith.address)),
context.polkadotApi.tx.identity
.setIdentity({
display: { Raw: "foobar" },
})
.signAsync(baltathar),
]);

block.result.forEach((r, idx) => {
expect(r.successful, `tx[${idx}] - ${r.error?.name}`).to.be.true;
});
});

it("should fail providing judgement", async () => {
const blockExecute = await context.createBlock(
context.polkadotApi.tx.proxy
.proxy(
alith.address,
null,
context.polkadotApi.tx.identity.provideJudgement(0, baltathar.address, {
Reasonable: true,
})
)
.signAsync(baltathar)
);

expect(blockExecute.result.successful).to.be.false;
expect(blockExecute.result.error.name).to.equal("NotProxy");
});
});

describeDevMoonbeam("Proxy : IdentityJudgement succeeds with proxy", (context) => {
before("setup one identity and registrar", async () => {
const block = await context.createBlock([
context.polkadotApi.tx.sudo.sudo(context.polkadotApi.tx.identity.addRegistrar(alith.address)),
context.polkadotApi.tx.identity
.setIdentity({
display: { Raw: "foobar" },
})
.signAsync(baltathar),
]);

block.result.forEach((r, idx) => {
expect(r.successful, `tx[${idx}] - ${r.error?.name}`).to.be.true;
});
});

it("should succeed providing judgement", async () => {
const blockAdd = await context.createBlock(
context.polkadotApi.tx.proxy
.addProxy(baltathar.address, "IdentityJudgement" as any, 0)
.signAsync(alith)
);

expect(blockAdd.result.successful).to.be.true;
const proxyAddEvent = blockAdd.result.events.reduce((acc, e) => {
if (context.polkadotApi.events.proxy.ProxyAdded.is(e.event)) {
acc.push({
proxyType: e.event.data[2].toString(),
});
}
return acc;
}, []);
expect(proxyAddEvent).to.deep.equal([
{
proxyType: "IdentityJudgement",
},
]);

const blockExecute = await context.createBlock(
context.polkadotApi.tx.proxy
.proxy(
alith.address,
null,
context.polkadotApi.tx.identity.provideJudgement(0, baltathar.address, {
Reasonable: true,
})
)
.signAsync(baltathar)
);

expect(blockExecute.result.successful).to.be.true;
const proxyExecuteEvent = blockExecute.result.events.reduce(
(acc, e) => {
if (context.polkadotApi.events.proxy.ProxyExecuted.is(e.event)) {
acc.proxyExecuted = e.event.data[0].toString();
} else if (context.polkadotApi.events.identity.JudgementGiven.is(e.event)) {
acc.judgementGiven = {
address: e.event.data[0].toString(),
decision: e.event.data[1].toString(),
};
}
return acc;
},
{ proxyExecuted: null, judgementGiven: null }
);
expect(proxyExecuteEvent).to.deep.equal({
proxyExecuted: "Ok",
judgementGiven: {
address: baltathar.address,
decision: "0",
},
});
});
});