Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply storage fees on Polkadot LOC creation #40

Merged
merged 1 commit into from
Oct 28, 2023
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
12 changes: 12 additions & 0 deletions pallet-logion-loc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ pub mod pallet {
let mut loc = Self::build_open_loc(&legal_officer, &requester, LocType::Identity, None, legal_fee);
loc.ensure_can_add::<T>(&items)?;
Self::ensure_valid_links(&items.links)?;
let tot_size = items.files.iter()
.map(|file| file.size)
.fold(0, |tot, current| tot + current);
Self::apply_file_storage_fee(&requester_account_id, items.files.len(), tot_size)?;
loc.add_items(&requester_account_id, &items);

Self::apply_legal_fee(&loc)?;
Expand Down Expand Up @@ -920,6 +924,10 @@ pub mod pallet {
let mut loc = Self::build_open_loc(&legal_officer, &requester, LocType::Transaction, None, legal_fee);
loc.ensure_can_add::<T>(&items)?;
Self::ensure_valid_links(&items.links)?;
let tot_size = items.files.iter()
.map(|file| file.size)
.fold(0, |tot, current| tot + current);
Self::apply_file_storage_fee(&requester_account_id, items.files.len(), tot_size)?;
loc.add_items(&requester_account_id, &items);

Self::apply_legal_fee(&loc)?;
Expand Down Expand Up @@ -1001,6 +1009,10 @@ pub mod pallet {
);
loc.ensure_can_add::<T>(&items)?;
Self::ensure_valid_links(&items.links)?;
let tot_size = items.files.iter()
.map(|file| file.size)
.fold(0, |tot, current| tot + current);
Self::apply_file_storage_fee(&requester_account_id, items.files.len(), tot_size)?;
loc.add_items(&requester_account_id, &items);

Self::apply_legal_fee(&loc)?;
Expand Down
51 changes: 51 additions & 0 deletions pallet-logion-loc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3043,3 +3043,54 @@ fn it_fails_creating_collection_loc_with_invalid_link_submitter() {
);
});
}

#[test]
fn it_applies_storage_fees_on_transaction_creation() {
new_test_ext().execute_with(|| {
setup_default_balances();
let snapshot = BalancesSnapshot::take(LOC_REQUESTER_ID, LOC_OWNER1);
let file = FileParams {
hash: sha256(&"test".as_bytes().to_vec()),
nature: sha256(&"Test".as_bytes().to_vec()),
submitter: SupportedAccountId::Polkadot(LOC_REQUESTER_ID),
size: 4,
};
assert_ok!(LogionLoc::create_polkadot_transaction_loc(RuntimeOrigin::signed(LOC_REQUESTER_ID), LOC_ID, LOC_OWNER1, Some(0u128), ItemsParams::only_files(Vec::from([ file.clone() ]))));
let fees = Fees::only_storage(1, 4);
fees.assert_balances_events(snapshot);
});
}

#[test]
fn it_applies_storage_fees_on_identity_creation() {
new_test_ext().execute_with(|| {
setup_default_balances();
let snapshot = BalancesSnapshot::take(LOC_REQUESTER_ID, LOC_OWNER1);
let file = FileParams {
hash: sha256(&"test".as_bytes().to_vec()),
nature: sha256(&"Test".as_bytes().to_vec()),
submitter: SupportedAccountId::Polkadot(LOC_REQUESTER_ID),
size: 4,
};
assert_ok!(LogionLoc::create_polkadot_identity_loc(RuntimeOrigin::signed(LOC_REQUESTER_ID), LOC_ID, LOC_OWNER1, Some(0u128), ItemsParams::only_files(Vec::from([ file.clone() ]))));
let fees = Fees::only_storage(1, 4);
fees.assert_balances_events(snapshot);
});
}

#[test]
fn it_applies_storage_fees_on_collection_creation() {
new_test_ext().execute_with(|| {
setup_default_balances();
let snapshot = BalancesSnapshot::take(LOC_REQUESTER_ID, LOC_OWNER1);
let file = FileParams {
hash: sha256(&"test".as_bytes().to_vec()),
nature: sha256(&"Test".as_bytes().to_vec()),
submitter: SupportedAccountId::Polkadot(LOC_REQUESTER_ID),
size: 4,
};
assert_ok!(LogionLoc::create_collection_loc(RuntimeOrigin::signed(LOC_REQUESTER_ID), LOC_ID, LOC_OWNER1, None, Some(10), true, 0, Some(0u128), ItemsParams::only_files(Vec::from([ file ]))));
let fees = Fees::only_storage(1, 4);
fees.assert_balances_events(snapshot);
});
}
Loading