Skip to content

Commit

Permalink
Local/Shibuya v1 governance integration (#1260)
Browse files Browse the repository at this point in the history
* v1 governance integration

* Separate register & unregister origins for dApp staking

* Init treasury integration

* Treasury

* Community council

* Community treasury

* Remove redundant function

* Community proxy attempt

* Rename

* Missing box dep

* Dummy weights

* Tests

* Fixes

* Shibuya governance

* Cargo

* Zepter

* dApp staking improvements

* Align local

* Remove TODOs

* Extra UT

* Formating

* Benchmarks

* clippy

* fix tests

* Integration tests setup

* Basic governance integration tests

* Finish integration tests

* Review comment

* Review comments

* Benchmarks
  • Loading branch information
Dinonard authored Jul 2, 2024
1 parent eea4653 commit dc58446
Show file tree
Hide file tree
Showing 31 changed files with 3,660 additions and 2,588 deletions.
3,980 changes: 1,675 additions & 2,305 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-democracy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }

# EVM & Ethereum
# (wasm)
Expand Down Expand Up @@ -290,6 +293,7 @@ pallet-unified-accounts = { path = "./pallets/unified-accounts", default-feature
astar-xcm-benchmarks = { path = "./pallets/astar-xcm-benchmarks", default-features = false }
pallet-static-price-provider = { path = "./pallets/static-price-provider", default-features = false }
pallet-price-aggregator = { path = "./pallets/price-aggregator", default-features = false }
pallet-collective-proxy = { path = "./pallets/collective-proxy", default-features = false }

# Get rid of this once orml-oracle has been updated with benchmarks
oracle-benchmarks = { path = "./pallets/oracle-benchmarks", default-features = false }
Expand Down
43 changes: 39 additions & 4 deletions bin/collator/src/local/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
//! Chain specifications.
use local_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig, DappStakingConfig,
EVMConfig, GrandpaConfig, GrandpaId, InflationConfig, InflationParameters, Precompiles,
RuntimeGenesisConfig, Signature, SudoConfig, SystemConfig, TierThreshold, VestingConfig, AST,
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, BalancesConfig,
CommunityCouncilMembershipConfig, CommunityTreasuryPalletId, CouncilMembershipConfig,
DappStakingConfig, EVMConfig, GrandpaConfig, GrandpaId, InflationConfig, InflationParameters,
Precompiles, RuntimeGenesisConfig, Signature, SudoConfig, SystemConfig,
TechnicalCommitteeMembershipConfig, TierThreshold, TreasuryPalletId, VestingConfig, AST,
};
use sc_service::ChainType;
use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
traits::{AccountIdConversion, IdentifyAccount, Verify},
Permill,
};

Expand Down Expand Up @@ -75,6 +77,8 @@ pub fn development_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
TreasuryPalletId::get().into_account_truncating(),
CommunityTreasuryPalletId::get().into_account_truncating(),
// Arrakis.TEST account in MetaMask
// Import known test account with private key
// 0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391
Expand All @@ -98,6 +102,11 @@ fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
) -> RuntimeGenesisConfig {
let accounts: Vec<AccountId> = vec!["Alice", "Bob", "Charlie", "Dave", "Eve"]
.iter()
.map(|s| get_account_id_from_seed::<sr25519::Public>(s))
.collect();

// This is supposed the be the simplest bytecode to revert without returning any data.
// We will pre-deploy it under all of our precompiles to ensure they can be called from
// within contracts.
Expand Down Expand Up @@ -186,6 +195,32 @@ fn testnet_genesis(
params: InflationParameters::default(),
..Default::default()
},
council_membership: CouncilMembershipConfig {
members: accounts
.clone()
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
technical_committee_membership: TechnicalCommitteeMembershipConfig {
members: accounts[..3]
.to_vec()
.try_into()
.expect("Should support at least 3 members."),
phantom: Default::default(),
},
community_council_membership: CommunityCouncilMembershipConfig {
members: accounts
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
council: Default::default(),
technical_committee: Default::default(),
community_council: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
}
}

Expand Down
39 changes: 35 additions & 4 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use cumulus_primitives_core::ParaId;
use sc_service::ChainType;
use shibuya_runtime::{
wasm_binary_unwrap, AccountId, AuraConfig, AuraId, Balance, BalancesConfig,
CollatorSelectionConfig, DappStakingConfig, EVMChainIdConfig, EVMConfig, InflationConfig,
InflationParameters, OracleMembershipConfig, ParachainInfoConfig, Precompiles,
PriceAggregatorConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig,
SystemConfig, TierThreshold, VestingConfig, SBY,
CollatorSelectionConfig, CommunityCouncilMembershipConfig, CouncilMembershipConfig,
DappStakingConfig, EVMChainIdConfig, EVMConfig, InflationConfig, InflationParameters,
OracleMembershipConfig, ParachainInfoConfig, Precompiles, PriceAggregatorConfig,
RuntimeGenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
TechnicalCommitteeMembershipConfig, TierThreshold, VestingConfig, SBY,
};
use sp_core::{sr25519, Pair, Public};

Expand Down Expand Up @@ -99,6 +100,10 @@ fn make_genesis(
get_from_seed::<AuraId>("Bob"),
),
];
let accounts: Vec<AccountId> = vec!["Alice", "Bob", "Charlie", "Dave", "Eve"]
.iter()
.map(|s| get_account_id_from_seed::<sr25519::Public>(s))
.collect();

// This is supposed the be the simplest bytecode to revert without returning any data.
// We will pre-deploy it under all of our precompiles to ensure they can be called from
Expand Down Expand Up @@ -212,6 +217,32 @@ fn make_genesis(
.try_into()
.expect("Must work since buffer should have at least a single value."),
},
council_membership: CouncilMembershipConfig {
members: accounts
.clone()
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
technical_committee_membership: TechnicalCommitteeMembershipConfig {
members: accounts[..3]
.to_vec()
.try_into()
.expect("Should support at least 3 members."),
phantom: Default::default(),
},
community_council_membership: CommunityCouncilMembershipConfig {
members: accounts
.try_into()
.expect("Should support at least 5 members."),
phantom: Default::default(),
},
council: Default::default(),
technical_committee: Default::default(),
community_council: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
community_treasury: Default::default(),
}
}

Expand Down
62 changes: 62 additions & 0 deletions pallets/collective-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[package]
name = "pallet-collective-proxy"
version = "0.1.0"
description = "Proxy for collective calls."
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
num-traits = { workspace = true }
parity-scale-codec = { workspace = true }

scale-info = { workspace = true }
serde = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

astar-primitives = { workspace = true }

frame-benchmarking = { workspace = true, optional = true }

[dev-dependencies]
pallet-balances = { workspace = true }

[features]
default = ["std"]
std = [
"serde/std",
"log/std",
"parity-scale-codec/std",
"astar-primitives/std",
"scale-info/std",
"num-traits/std",
"sp-core/std",
"sp-runtime/std",
"sp-io/std",
"sp-std/std",
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"frame-benchmarking/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"astar-primitives/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"astar-primitives/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
62 changes: 62 additions & 0 deletions pallets/collective-proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file is part of Astar.

// Copyright (C) Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use super::*;

use frame_benchmarking::v2::*;

/// Assert that the last event equals the provided one.
pub(super) fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

#[benchmarks()]
mod benchmarks {
use super::*;

#[benchmark]
fn execute_call() {
let origin = T::CollectiveProxy::try_successful_origin()
.expect("Must succeed in order to run benchmarks.");

// A bit dirty, but runtime should ensure to allow the `remark` call.
let call: <T as Config>::RuntimeCall =
frame_system::Call::<T>::remark { remark: vec![] }.into();

#[extrinsic_call]
_(origin as T::RuntimeOrigin, Box::new(call));

assert_last_event::<T>(Event::<T>::CollectiveProxyExecuted { result: Ok(()) }.into());
}

impl_benchmark_test_suite!(
Pallet,
crate::benchmarking::tests::new_test_ext(),
crate::mock::Test,
);
}

#[cfg(test)]
mod tests {
use crate::mock;
use sp_io::TestExternalities;

pub fn new_test_ext() -> TestExternalities {
mock::ExtBuilder::build()
}
}
Loading

0 comments on commit dc58446

Please sign in to comment.