Skip to content

Commit

Permalink
feat: sendTip and claimTips with octopusAssets (#135)
Browse files Browse the repository at this point in the history
* fix: remove unused methods

* feat: implement octopusAsset for sendTip and claimTip

* feat: implement octopusAsset for sendTip and claimTip

* fix: benchmarking tipping pallet

* fix: sendTip and claimTip test with octopusAssets

* chore: bump version 2.1.4

* fix: event when claiming reference
  • Loading branch information
abdulhakim2902 authored Jul 20, 2022
1 parent 6672032 commit 6ca93a5
Show file tree
Hide file tree
Showing 26 changed files with 661 additions and 2,192 deletions.
12 changes: 7 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'myriad'
version = '2.1.3'
version = '2.1.4'
edition = '2021'
license = 'AGPL-3.0'
authors = ['Myriad Dev Team <[email protected]>']
Expand Down
2 changes: 1 addition & 1 deletion pallets/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-server'
version = '2.1.3'
version = '2.1.4'
edition = '2021'
license = 'AGPL-3.0'
authors = ['Myriad Dev Team <[email protected]>']
Expand Down
4 changes: 3 additions & 1 deletion pallets/tipping/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-tipping'
version = '2.1.3'
version = '2.1.4'
edition = '2021'
license = 'AGPL-3.0'
authors = ['Myriad Dev Team <[email protected]>']
Expand Down Expand Up @@ -32,6 +32,7 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch =

# Substrate Pallet Dependencies
pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.13', default-features = false }
pallet-assets = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.13', default-features = false }

# Local Dependencies
pallet-server = { path = '../server', default-features = false }
Expand All @@ -58,6 +59,7 @@ std = [
'frame-benchmarking/std',

'pallet-balances/std',
'pallet-assets/std',

'pallet-server/std',
]
Expand Down
4 changes: 3 additions & 1 deletion pallets/tipping/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-tipping-benchmarking'
version = '2.1.3'
version = '2.1.4'
edition = '2021'
license = 'AGPL-3.0'
authors = ['Myriad Dev Team <[email protected]>']
Expand All @@ -26,6 +26,7 @@ frame-benchmarking = { git = 'https://github.com/paritytech/substrate', branch =

# Substrate Pallet Dependencies
pallet-balances = { git = 'https://github.com/paritytech/substrate', branch = 'polkadot-v0.9.13', default-features = false }
pallet-assets = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.13', default-features = false }

# Substrate Local Dependencies
pallet-server = { path = '../../server', default-features = false }
Expand Down Expand Up @@ -56,6 +57,7 @@ std = [
'frame-benchmarking/std',

'pallet-balances/std',
'pallet-assets/std',

'pallet-server/std',
'pallet-tipping/std',
Expand Down
128 changes: 6 additions & 122 deletions pallets/tipping/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,59 +58,6 @@ benchmarks! {
let balance = 1000000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&tipping_account_id, balance);

let admin: T::AccountId = AdminKey::<T>::get();
let admin_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(admin));
let server_name = b"myriad".to_vec();
let server_id = b"server".to_vec();
let server_api_url = b"https://api.dev.myriad.social".to_vec();
let server_web_url = b"https://app.dev.myriad.social".to_vec();
let _server = Server::<T>::register(
admin_origin,
caller.clone(),
server_id.clone(),
server_name,
server_api_url,
server_web_url
);

// Send Tipping
let account_1: T::AccountId = account("account_1", 0, SEED);
let account_1_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(account_1.clone()));
let tips_balance_info = TipsBalanceInfo::new(
&server_id,
b"people",
b"people_id",
b"native"
);

let tipping_amount = 10000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&account_1, balance);
let _ = Tipping::<T>::send_tip(account_1_origin, tips_balance_info.clone(), tipping_amount);

// Send Tipping
let account_2: T::AccountId = account("account_2", 0, SEED);
let account_2_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(account_2.clone()));
let main_tips_balance_info = TipsBalanceInfo::new(
&server_id,
b"user",
b"user_id",
b"native"
);

let _ = <T as TippingConfig>::Currency::deposit_creating(&account_2, balance);
let _ = Tipping::<T>::send_tip(account_2_origin, main_tips_balance_info, tipping_amount);

let trx_fee = 1000000000000000u128.saturated_into();
let account_3: T::AccountId = account("account_3", 0, SEED);
}: _(RawOrigin::Signed(caller), tips_balance_info, b"user".to_vec(), b"user_id".to_vec(), Some(account_3), trx_fee)

batch_claim_reference {
let caller: T::AccountId = whitelisted_caller();
let tipping_account_id = Tipping::<T>::tipping_account_id();

let balance = 1000000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&tipping_account_id, balance);

let admin: T::AccountId = AdminKey::<T>::get();
let admin_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(admin));
let server_name = b"myriad".to_vec();
Expand Down Expand Up @@ -187,70 +134,6 @@ benchmarks! {
server_web_url
);

// Send Tipping
let account_1: T::AccountId = account("account", 0, SEED);
let account_1_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(account_1.clone()));
let tips_balance_info = TipsBalanceInfo::new(&server_id,
b"people",
b"people_id",
b"native"
);

let tipping_amount = 10000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&account_1, balance);
let _ = Tipping::<T>::send_tip(account_1_origin, tips_balance_info.clone(), tipping_amount);

// Claim Reference
let account_2: T::AccountId = account("account_2", 0, SEED);
let account_2_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(account_2.clone()));
let tips_balance_info_user = TipsBalanceInfo::new(
&server_id,
b"user",
b"user_id",
b"native"
);

let _ = <T as TippingConfig>::Currency::deposit_creating(&account_2, balance);
let _ = Tipping::<T>::send_tip(account_2_origin, tips_balance_info_user.clone(), tipping_amount);

let tx_fee = 10000000000000u128.saturated_into();
let _ = Tipping::<T>::claim_reference(
server_origin,
tips_balance_info,
b"user".to_vec(),
b"user_id".to_vec(),
Some(caller.clone()),
tx_fee,
);
}: _(RawOrigin::Signed(caller), tips_balance_info_user)

batch_claim_tip {
let caller: T::AccountId = whitelisted_caller();
let tipping_account_id = Tipping::<T>::tipping_account_id();

let balance = 1000000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&caller, balance);
let _ = <T as TippingConfig>::Currency::deposit_creating(&tipping_account_id, balance);

// Register Server
// Server admin => server_account
let admin: T::AccountId = AdminKey::<T>::get();
let server_account: T::AccountId = account("server_account", 0, SEED);
let admin_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(admin));
let server_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(server_account.clone()));
let server_id = b"server".to_vec();
let server_api_url = b"https://api.dev.myriad.social".to_vec();
let server_web_url = b"https://app.dev.myriad.social".to_vec();

let _ = Server::<T>::register(
admin_origin,
server_account,
server_id.clone(),
b"myriad".to_vec(),
server_api_url,
server_web_url
);

// Send Tipping
let account_1: T::AccountId = account("account", 0, SEED);
let account_1_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(account_1.clone()));
Expand All @@ -263,7 +146,7 @@ benchmarks! {

let tipping_amount = 10000000000000000000u128.saturated_into();
let _ = <T as TippingConfig>::Currency::deposit_creating(&account_1, balance);
let _ = Tipping::<T>::send_tip(account_1_origin, tips_balance_info.clone(), tipping_amount);
let _ = Tipping::<T>::send_tip(account_1_origin, tips_balance_info, tipping_amount);

// Claim Reference
let account_2: T::AccountId = account("account", 2, SEED);
Expand All @@ -280,10 +163,11 @@ benchmarks! {
let tx_fee = 10000000000000u128.saturated_into();
let _ = Tipping::<T>::claim_reference(
server_origin,
tips_balance_info,
b"user".to_vec(),
b"user_id".to_vec(),
Some(caller.clone()),
b"server".to_vec(),
References::new(b"people", &[b"people_id".to_vec()]),
References::new(b"user", &[b"user_id".to_vec()]),
vec![b"native".to_vec()],
caller.clone(),
tx_fee,
);
}: _(RawOrigin::Signed(caller), server_id, b"user".to_vec(), b"user_id".to_vec(), vec![b"native".to_vec()])
Expand Down
54 changes: 27 additions & 27 deletions pallets/tipping/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use frame_system as system;
use pallet_balances::AccountData;
use sp_core::{sr25519::Signature, H256};
use sp_runtime::{
testing::{Header, TestXt},
traits::{BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify},
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand All @@ -22,6 +22,7 @@ construct_runtime!(
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Tipping: pallet_tipping::{Pallet, Call, Storage, Event<T>},
Server: pallet_server::{Pallet, Call, Storage, Event<T>},
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -79,11 +80,11 @@ impl pallet_balances::Config for Test {
}

impl pallet_tipping::Config for Test {
type AuthorityId = pallet_tipping::crypto::TestAuthId;
type Call = Call;
type Event = Event;
type Currency = Balances;
type Server = Server;
type Assets = Assets;
type WeightInfo = ();
}

Expand All @@ -92,32 +93,31 @@ impl pallet_server::Config for Test {
type WeightInfo = ();
}

type Extrinsic = TestXt<Call, ()>;
type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub type OctopusAssetId = u32;
pub type OctopusAssetBalance = u128;

impl frame_system::offchain::SigningTypes for Test {
type Public = <Signature as Verify>::Signer;
type Signature = Signature;
parameter_types! {
pub const ApprovalDeposit: Balance = 1;
pub const AssetDeposit: Balance = 1;
pub const MetadataDepositBase: Balance = 1;
pub const MetadataDepositPerByte: Balance = 1;
pub const StringLimit: u32 = 50;
}

impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Test
where
Call: From<LocalCall>,
{
type OverarchingCall = Call;
type Extrinsic = Extrinsic;
}
type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

impl<LocalCall> system::offchain::CreateSignedTransaction<LocalCall> for Test
where
Call: From<LocalCall>,
{
fn create_transaction<C: system::offchain::AppCrypto<Self::Public, Self::Signature>>(
call: Call,
_public: <Signature as Verify>::Signer,
_account: AccountId,
nonce: u64,
) -> Option<(Call, <Extrinsic as ExtrinsicT>::SignaturePayload)> {
Some((call, (nonce, ())))
}
impl pallet_assets::Config for Test {
type Event = Event;
type Balance = OctopusAssetBalance;
type AssetId = OctopusAssetId;
type Currency = Balances;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type AssetDeposit = AssetDeposit;
type MetadataDepositBase = MetadataDepositBase;
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Freezer = ();
type Extra = ();
type WeightInfo = ();
}
27 changes: 0 additions & 27 deletions pallets/tipping/src/crypto.rs

This file was deleted.

Loading

0 comments on commit 6ca93a5

Please sign in to comment.