difftreelog
Fix inflation build
in: master
3 files changed
pallets/inflation/src/lib.rsdiffbeforeafterboth--- a/pallets/inflation/src/lib.rs
+++ b/pallets/inflation/src/lib.rs
@@ -3,23 +3,17 @@
// file 'LICENSE', which is part of this source code package.
//
-#![recursion_limit = "1024"]
+// #![recursion_limit = "1024"]
#![cfg_attr(not(feature = "std"), no_std)]
-#![allow(
- clippy::too_many_arguments,
- clippy::unnecessary_mut_passed,
- clippy::unused_unit
-)]
+#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
-#[cfg(test)]
-mod mock;
+
#[cfg(test)]
mod tests;
use frame_support::{
dispatch::{DispatchResult},
- ensure,
traits::{Currency, Get},
};
pub use pallet::*;
@@ -28,7 +22,7 @@
traits::{BlockNumberProvider}
};
-use std::convert::TryInto;
+use sp_std::convert::TryInto;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
@@ -44,12 +38,6 @@
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
-
- #[pallet::error]
- pub enum Error<T> {
- /// Inflation has already been initialized
- AlreadyInitialized,
- }
#[pallet::config]
pub trait Config: frame_system::Config {
@@ -144,17 +132,17 @@
where <T as frame_system::Config>::BlockNumber: From<u32> {
ensure_root(origin)?;
- // Ensure inflation has not been yet initialized
+ // Start inflation if it has not been yet initialized
let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();
- ensure!(next_inflation == 0u32.into(), Error::<T>::AlreadyInitialized);
-
- // Recalculate inflation. This can be backdated and will catch up.
- Self::recalculate_inflation(inflation_start_relay_block);
- let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);
- <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());
+ if next_inflation == 0u32.into() {
+ // Recalculate inflation. This can be backdated and will catch up.
+ Self::recalculate_inflation(inflation_start_relay_block);
+ let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);
+ <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());
- // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
- T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());
+ // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
+ T::Currency::deposit_creating(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get());
+ }
Ok(())
}
runtime/Cargo.tomldiffbeforeafterboth379pallet-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" }tests/src/inflation.test.tsdiffbeforeafterboth--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -5,7 +5,8 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi} from './substrate/substrate-api';
+import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import privateKey from './substrate/privateKey';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -14,8 +15,15 @@
it('First year inflation is 10%', async () => {
await usingApi(async (api) => {
- // Start inflation on relay block 1
- await api.tx.inflation.start_inflation(1);
+ // Make sure non-sudo can't start inflation
+ const tx = api.tx.inflation.startInflation(1);
+ const bob = privateKey('//Bob');
+ await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
+
+ // Start inflation on relay block 1 (Alice is sudo)
+ const alice = privateKey('//Alice');
+ const sudoTx = api.tx.sudo.sudo(tx as any);
+ await submitTransactionAsync(alice, sudoTx);
const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();
const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();