Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions runtime-modules/content-working-group/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ pub struct GenesisConfigBuilder<T: Trait> {
}

impl<T: Trait> GenesisConfigBuilder<T> {
/*
pub fn set_mint(mut self, mint: <T as minting::Trait>::MintId) -> Self {
self.mint = mint;
pub fn with_mint_capacity(mut self, capacity: minting::BalanceOf<T>) -> Self {
self.mint_capacity = capacity;
self
}
/*
pub fn set_channel_handle_constraint(mut self, constraint: InputValidationLengthConstraint) -> Self {
self.channel_description_constraint = constraint;
self
Expand Down
47 changes: 45 additions & 2 deletions runtime-modules/content-working-group/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,9 @@ decl_event! {
CuratorApplicationId = CuratorApplicationId<T>,
CuratorId = CuratorId<T>,
CuratorApplicationIdToCuratorIdMap = CuratorApplicationIdToCuratorIdMap<T>,
MintBalanceOf = minting::BalanceOf<T>,
<T as system::Trait>::AccountId,
<T as minting::Trait>::MintId,
{
ChannelCreated(ChannelId),
ChannelOwnershipTransferred(ChannelId),
Expand All @@ -1100,6 +1102,8 @@ decl_event! {
CuratorRewardAccountUpdated(CuratorId, AccountId),
ChannelUpdatedByCurationActor(ChannelId),
ChannelCreationEnabledUpdated(bool),
MintCapacityIncreased(MintId, MintBalanceOf, MintBalanceOf),
MintCapacityDecreased(MintId, MintBalanceOf, MintBalanceOf),
}
}

Expand Down Expand Up @@ -2022,7 +2026,11 @@ decl_module! {
Self::deposit_event(RawEvent::ChannelCreationEnabledUpdated(enabled));
}

/// Add to capacity of current acive mint
/// Add to capacity of current acive mint.
/// This may be deprecated in the future, since set_mint_capacity is sufficient to
/// both increase and decrease capacity. Although when considering that it may be executed
/// by a proposal, given the temporal delay in approving a proposal, it might be more suitable
/// than set_mint_capacity?
pub fn increase_mint_capacity(
origin,
additional_capacity: minting::BalanceOf<T>
Expand All @@ -2032,7 +2040,42 @@ decl_module! {
let mint_id = Self::mint();
let mint = <minting::Module<T>>::mints(mint_id); // must exist
let new_capacity = mint.capacity() + additional_capacity;
let _ = <minting::Module<T>>::set_mint_capacity(mint_id, new_capacity);
<minting::Module<T>>::set_mint_capacity(mint_id, new_capacity)?;

Self::deposit_event(RawEvent::MintCapacityIncreased(
mint_id, additional_capacity, new_capacity
));
}

/// Sets the capacity of the current active mint
pub fn set_mint_capacity(
origin,
new_capacity: minting::BalanceOf<T>
) {
ensure_root(origin)?;

let mint_id = Self::mint();

// Mint must exist - it is set at genesis
let mint = <minting::Module<T>>::mints(mint_id);

let current_capacity = mint.capacity();

if new_capacity != current_capacity {
// Cannot fail if mint exists
<minting::Module<T>>::set_mint_capacity(mint_id, new_capacity)?;

if new_capacity > current_capacity {
Self::deposit_event(RawEvent::MintCapacityIncreased(
mint_id, new_capacity - current_capacity, new_capacity
));
} else {
Self::deposit_event(RawEvent::MintCapacityDecreased(
mint_id, current_capacity - new_capacity, new_capacity
));
}
}

}
}
}
Expand Down
9 changes: 7 additions & 2 deletions runtime-modules/content-working-group/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ pub type RawLibTestEvent = RawEvent<
CuratorApplicationId<Test>,
CuratorId<Test>,
CuratorApplicationIdToCuratorIdMap<Test>,
minting::BalanceOf<Test>,
<Test as system::Trait>::AccountId,
<Test as minting::Trait>::MintId,
>;

pub fn get_last_event_or_panic() -> RawLibTestEvent {
Expand Down Expand Up @@ -220,11 +222,13 @@ impl<T: Trait> TestExternalitiesBuilder<T> {
self.membership_config = Some(membership_config);
self
}
pub fn set_content_wg_config(mut self, conteng_wg_config: GenesisConfig<T>) -> Self {
*/

pub fn with_content_wg_config(mut self, conteng_wg_config: GenesisConfig<T>) -> Self {
self.content_wg_config = Some(conteng_wg_config);
self
}
*/

pub fn build(self) -> runtime_io::TestExternalities {
// Add system
let mut t = self
Expand Down Expand Up @@ -260,3 +264,4 @@ impl<T: Trait> TestExternalitiesBuilder<T> {
pub type System = system::Module<Test>;
pub type Balances = balances::Module<Test>;
pub type ContentWorkingGroup = Module<Test>;
pub type Minting = minting::Module<Test>;
86 changes: 85 additions & 1 deletion runtime-modules/content-working-group/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

//use super::genesis;
use super::genesis;
use super::mock::{self, *};
//use crate::membership;
use hiring;
Expand Down Expand Up @@ -2184,3 +2184,87 @@ pub fn generate_too_short_length_buffer(constraint: &InputValidationLengthConstr
pub fn generate_too_long_length_buffer(constraint: &InputValidationLengthConstraint) -> Vec<u8> {
generate_text((constraint.max() + 1) as usize)
}

#[test]
fn increasing_mint_capacity() {
const MINT_CAPACITY: u64 = 50000;

TestExternalitiesBuilder::<Test>::default()
.with_content_wg_config(
genesis::GenesisConfigBuilder::<Test>::default()
.with_mint_capacity(MINT_CAPACITY)
.build(),
)
.build()
.execute_with(|| {
let mint_id = ContentWorkingGroup::mint();
let mint = Minting::mints(mint_id);
assert_eq!(mint.capacity(), MINT_CAPACITY);

let increase = 25000;
// Increasing mint capacity
let expected_new_capacity = MINT_CAPACITY + increase;
assert_ok!(ContentWorkingGroup::increase_mint_capacity(
Origin::ROOT,
increase
));
// Excpected event after increasing
assert_eq!(
get_last_event_or_panic(),
crate::RawEvent::MintCapacityIncreased(mint_id, increase, expected_new_capacity)
);
// Excpected value of capacity after increasing
let mint = Minting::mints(mint_id);
assert_eq!(mint.capacity(), expected_new_capacity);
});
}

#[test]
fn setting_mint_capacity() {
const MINT_CAPACITY: u64 = 50000;

TestExternalitiesBuilder::<Test>::default()
.with_content_wg_config(
genesis::GenesisConfigBuilder::<Test>::default()
.with_mint_capacity(MINT_CAPACITY)
.build(),
)
.build()
.execute_with(|| {
let mint_id = ContentWorkingGroup::mint();
let mint = Minting::mints(mint_id);
assert_eq!(mint.capacity(), MINT_CAPACITY);

// Decreasing mint capacity
let new_lower_capacity = 10000;
let decrease = MINT_CAPACITY - new_lower_capacity;
assert_ok!(ContentWorkingGroup::set_mint_capacity(
Origin::ROOT,
new_lower_capacity
));
// Correct event after decreasing
assert_eq!(
get_last_event_or_panic(),
crate::RawEvent::MintCapacityDecreased(mint_id, decrease, new_lower_capacity)
);
// Correct value of capacity after decreasing
let mint = Minting::mints(mint_id);
assert_eq!(mint.capacity(), new_lower_capacity);

// Increasing mint capacity
let new_higher_capacity = 25000;
let increase = new_higher_capacity - mint.capacity();
assert_ok!(ContentWorkingGroup::set_mint_capacity(
Origin::ROOT,
new_higher_capacity
));
// Excpected event after increasing
assert_eq!(
get_last_event_or_panic(),
crate::RawEvent::MintCapacityIncreased(mint_id, increase, new_higher_capacity)
);
// Excpected value of capacity after increasing
let mint = Minting::mints(mint_id);
assert_eq!(mint.capacity(), new_higher_capacity);
});
}
9 changes: 9 additions & 0 deletions runtime-modules/token-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ impl From<MintingError> for TransferError {
}
}

impl From<GeneralError> for &'static str {
fn from(err: GeneralError) -> &'static str {
match err {
GeneralError::MintNotFound => "MintNotFound",
GeneralError::NextAdjustmentInPast => "NextAdjustmentInPast",
}
}
}

#[derive(Encode, Decode, Copy, Clone, Debug, Eq, PartialEq)]
pub enum Adjustment<Balance: Zero, BlockNumber> {
// First adjustment will be after AdjustOnInterval.block_interval
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = '2018'
name = 'joystream-node-runtime'
# Follow convention: https://github.com/Joystream/substrate-runtime-joystream/issues/1
# {Authoring}.{Spec}.{Impl} of the RuntimeVersion
version = '6.8.1'
version = '6.9.0'

[features]
default = ['std']
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("joystream-node"),
impl_name: create_runtime_str!("joystream-node"),
authoring_version: 6,
spec_version: 8,
spec_version: 9,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
Expand Down