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
--- 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(())
 		}
modifiedruntime/Cargo.tomldiffbeforeafterboth
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -379,7 +379,7 @@
 pallet-unique = { path = '../pallets/unique', default-features = false }
 up-rpc = { path = "../primitives/rpc", default-features = false }
 up-evm-mapping = { path = "../primitives/evm-mapping", default-features = false }
-pallet-inflation = { path = '../pallets/inflation' }
+pallet-inflation = { path = '../pallets/inflation', default-features = false }
 up-data-structs = { path = '../primitives/data-structs', default-features = false }
 pallet-common = { default-features = false, path = "../pallets/common" }
 pallet-fungible = { default-features = false, path = "../pallets/fungible" }
modifiedtests/src/inflation.test.tsdiffbeforeafterboth
after · tests/src/inflation.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';9import privateKey from './substrate/privateKey';1011chai.use(chaiAsPromised);12const expect = chai.expect;1314describe('integration test: Inflation', () => {15  it('First year inflation is 10%', async () => {16    await usingApi(async (api) => {1718      // Make sure non-sudo can't start inflation19      const tx = api.tx.inflation.startInflation(1);20      const bob = privateKey('//Bob');21      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;2223      // 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);2728      const blockInterval = (api.consts.inflation.inflationBlockInterval).toBigInt();29      const totalIssuanceStart = (await api.query.inflation.startingYearTotalIssuance()).toBigInt();30      const blockInflation = (await api.query.inflation.blockInflation()).toBigInt();3132      const YEAR = 5259600n;  // 6-second block. Blocks in one year33      // const YEAR = 2629800n; // 12-second block. Blocks in one year3435      const totalExpectedInflation = totalIssuanceStart / 10n;36      const totalActualInflation = blockInflation * YEAR / blockInterval;3738      const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation39      const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;4041      expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);42    });43  });4445});