git.delta.rocks / unique-network / refs/commits / 4e00e0c4cd4e

difftreelog

Fix inflation build

Greg Zaitsev2021-12-07parent: #1ba63c8.patch.diff
in: master

3 files changed

modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
55
6#![recursion_limit = "1024"]6// #![recursion_limit = "1024"]
7#![cfg_attr(not(feature = "std"), no_std)]7#![cfg_attr(not(feature = "std"), no_std)]
8#![allow(8
9 clippy::too_many_arguments,
10 clippy::unnecessary_mut_passed,
11 clippy::unused_unit
12)]
13
14mod benchmarking;
15#[cfg(test)]9#[cfg(feature = "runtime-benchmarks")]
16mod mock;10mod benchmarking;
11
17#[cfg(test)]12#[cfg(test)]
18mod tests;13mod tests;
1914
20use frame_support::{15use frame_support::{
21 dispatch::{DispatchResult},16 dispatch::{DispatchResult},
22 ensure,
23 traits::{Currency, Get},17 traits::{Currency, Get},
24};18};
25pub use pallet::*;19pub use pallet::*;
28 traits::{BlockNumberProvider}22 traits::{BlockNumberProvider}
29};23};
3024
31use std::convert::TryInto;25use sp_std::convert::TryInto;
3226
33type BalanceOf<T> =27type BalanceOf<T> =
34 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;28 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
45 use frame_support::pallet_prelude::*;39 use frame_support::pallet_prelude::*;
46 use frame_system::pallet_prelude::*;40 use frame_system::pallet_prelude::*;
47
48 #[pallet::error]
49 pub enum Error<T> {
50 /// Inflation has already been initialized
51 AlreadyInitialized,
52 }
5341
54 #[pallet::config]42 #[pallet::config]
55 pub trait Config: frame_system::Config {43 pub trait Config: frame_system::Config {
144 where <T as frame_system::Config>::BlockNumber: From<u32> {132 where <T as frame_system::Config>::BlockNumber: From<u32> {
145 ensure_root(origin)?;133 ensure_root(origin)?;
146134
147 // Ensure inflation has not been yet initialized135 // Start inflation if it has not been yet initialized
148 let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();136 let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();
149 ensure!(next_inflation == 0u32.into(), Error::<T>::AlreadyInitialized);137 if next_inflation == 0u32.into() {
150
151 // Recalculate inflation. This can be backdated and will catch up.138 // Recalculate inflation. This can be backdated and will catch up.
152 Self::recalculate_inflation(inflation_start_relay_block);139 Self::recalculate_inflation(inflation_start_relay_block);
155142
156 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else143 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
157 T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());144 T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());
145 }
158146
159 Ok(())147 Ok(())
160 }148 }
modifiedruntime/Cargo.tomldiffbeforeafterboth
379pallet-unique = { path = '../pallets/unique', default-features = false }379pallet-unique = { path = '../pallets/unique', default-features = false }
380up-rpc = { path = "../primitives/rpc", default-features = false }380up-rpc = { path = "../primitives/rpc", default-features = false }
381up-evm-mapping = { path = "../primitives/evm-mapping", default-features = false }381up-evm-mapping = { path = "../primitives/evm-mapping", default-features = false }
382pallet-inflation = { path = '../pallets/inflation' }382pallet-inflation = { path = '../pallets/inflation', default-features = false }
383up-data-structs = { path = '../primitives/data-structs', default-features = false }383up-data-structs = { path = '../primitives/data-structs', default-features = false }
384pallet-common = { default-features = false, path = "../pallets/common" }384pallet-common = { default-features = false, path = "../pallets/common" }
385pallet-fungible = { default-features = false, path = "../pallets/fungible" }385pallet-fungible = { default-features = false, path = "../pallets/fungible" }
modifiedtests/src/inflation.test.tsdiffbeforeafterboth
55
6import chai from 'chai';6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised';7import chaiAsPromised from 'chai-as-promised';
8import {default as usingApi} from './substrate/substrate-api';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
9import privateKey from './substrate/privateKey';
910
10chai.use(chaiAsPromised);11chai.use(chaiAsPromised);
11const expect = chai.expect;12const expect = chai.expect;
14 it('First year inflation is 10%', async () => {15 it('First year inflation is 10%', async () => {
15 await usingApi(async (api) => {16 await usingApi(async (api) => {
1617
17 // Start inflation on relay block 118 // Make sure non-sudo can't start inflation
18 await api.tx.inflation.start_inflation(1);19 const tx = api.tx.inflation.startInflation(1);
20 const bob = privateKey('//Bob');
21 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
22
23 // Start inflation on relay block 1 (Alice is sudo)
24 const alice = privateKey('//Alice');
25 const sudoTx = api.tx.sudo.sudo(tx as any);
26 await submitTransactionAsync(alice, sudoTx);
1927
20 const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();28 const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();
21 const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();29 const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();