Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e85cd8c
Add initial pallet-token-claims
MOZGIII Jul 26, 2022
7d8ba61
Add base pallet structure
MOZGIII Jul 26, 2022
5442342
Add events
MOZGIII Jul 26, 2022
a5d294e
Add weights
MOZGIII Jul 26, 2022
b2eac6d
Add call impl
MOZGIII Jul 26, 2022
bb41418
Add EthereumAddress type
MOZGIII Jul 26, 2022
99f660d
Add claims storage
MOZGIII Jul 26, 2022
b949698
Move ethereum types to primitives-ethereum crate
MOZGIII Jul 27, 2022
93b593f
Implement the initial claiming logic
MOZGIII Jul 27, 2022
6414cb0
Add genesis
MOZGIII Jul 27, 2022
3f02d8d
Implement basic tests and benches scaffold
MOZGIII Jul 27, 2022
11e8396
Fix a bug at claiming
MOZGIII Jul 28, 2022
f7fc390
Implement some tests
MOZGIII Jul 28, 2022
f7960d4
Proper guarding of the mock objects
MOZGIII Jul 28, 2022
2c517e8
Cleaner test interface
MOZGIII Jul 29, 2022
719ec33
Checkpoint mock contexts before the tests finish
MOZGIII Jul 29, 2022
48484ef
Assert noop instead of just error
MOZGIII Jul 29, 2022
24530b7
Test for vesting interface failure
MOZGIII Jul 29, 2022
5e877db
Execute the whole process_claim in a new storage layer
MOZGIII Jul 29, 2022
f4f7112
Proper benchmarking interface and implementation
MOZGIII Jul 29, 2022
2b6dacc
Drop unused data from the test runtime
MOZGIII Jul 29, 2022
30de7b6
Use pot account and ensure proper balances everywhere
MOZGIII Jul 29, 2022
3217d10
Fix the comment for Claims storage accessor
MOZGIII Aug 1, 2022
12568fa
Compute and maintain the total claimable balance
MOZGIII Aug 1, 2022
40cdb5a
Update the tests with more explicit and easy to use eth addr parameters
MOZGIII Aug 1, 2022
be7ff9b
Check the pot balance in tests
MOZGIII Aug 1, 2022
214b537
Add a test for non-existing claims
MOZGIII Aug 1, 2022
a62b410
Proper genesis tests
MOZGIII Aug 1, 2022
2eb7913
Correct the claiming_works_no_vesting test
MOZGIII Aug 1, 2022
897af4f
Check the total issuance and the pot account balance deduction
MOZGIII Aug 1, 2022
4ea4fc6
Ensure we can sequentially consume all of the claims
MOZGIII Aug 1, 2022
1b27916
Avoid using `returning` needlessly
MOZGIII Aug 1, 2022
b182847
Ensure total claimable balance is updated correctly
MOZGIII Aug 1, 2022
9dd01e2
Check total issuance at benches
MOZGIII Aug 1, 2022
edea265
Correct the mock expectations at benches
MOZGIII Aug 1, 2022
eb9098e
Add the total claimable balance assertion
MOZGIII Aug 1, 2022
7b78ec6
Correct no_std use
MOZGIII Aug 1, 2022
2600ba8
Export types and traits
MOZGIII Aug 2, 2022
26e7762
Fix typo findings from code review
MOZGIII Aug 2, 2022
f7bcabc
Fix another typo
MOZGIII Aug 3, 2022
aa3764a
Move the update_total_claimable_balance to the bottom
MOZGIII Aug 3, 2022
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
113 changes: 104 additions & 9 deletions Cargo.lock

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

41 changes: 41 additions & 0 deletions crates/pallet-token-claims/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "pallet-token-claims"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
primitives-ethereum = { version = "0.1", path = "../primitives-ethereum", default-features = false }

codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
frame-benchmarking = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master", optional = true }
frame-support = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" }
frame-system = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1", optional = true }

[dev-dependencies]
pallet-pot = { version = "0.1", path = "../pallet-pot" }

mockall = "0.11"
once_cell = "1"
pallet-balances = { git = "https://github.com/humanode-network/substrate", branch = "master" }
serde_json = "1"
sp-core = { git = "https://github.com/humanode-network/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/humanode-network/substrate", branch = "master" }

[features]
default = ["std"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"primitives-ethereum/std",
"serde",
]
109 changes: 109 additions & 0 deletions crates/pallet-token-claims/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//! The benchmarks for the pallet.

use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use primitives_ethereum::{EcdsaSignature, EthereumAddress};

use crate::*;

/// The benchmark interface into the environment.
pub trait Interface: super::Config {
/// Obtain an Account ID.
///
/// This is an account to claim the funds to.
fn account_id_to_claim_to() -> <Self as frame_system::Config>::AccountId;

/// Obtain an ethereum address.
///
/// This is an ethereum account that is supposed to have a valid calim associated with it
/// in the runtime genesis.
fn ethereum_address() -> EthereumAddress;

/// Obtain an ECDSA signature that would fit the provided Account ID and the Ethereum address
/// under the associated runtime.
fn create_ecdsa_signature(
account_id: &<Self as frame_system::Config>::AccountId,
ethereum_address: &EthereumAddress,
) -> EcdsaSignature;
}

benchmarks! {
where_clause {
where
T: Interface
}

claim {
let account_id = <T as Interface>::account_id_to_claim_to();
let ethereum_address = <T as Interface>::ethereum_address();
let ethereum_signature = <T as Interface>::create_ecdsa_signature(&account_id, &ethereum_address);

// We assume the genesis has the corresponding claim; crash the bench if it doesn't.
let claim_info = Claims::<T>::get(ethereum_address).unwrap();

let account_balance_before = <CurrencyOf<T>>::total_balance(&account_id);
let currency_total_issuance_before = <CurrencyOf<T>>::total_issuance();

#[cfg(test)]
let test_data = {
use crate::mock;

let mock_runtime_guard = mock::runtime_lock();

let recover_signer_ctx = mock::MockEthereumSignatureVerifier::recover_signer_context();
recover_signer_ctx.expect().times(1..).return_const(Some(ethereum_address));

let lock_under_vesting_ctx = mock::MockVestingInterface::lock_under_vesting_context();
lock_under_vesting_ctx.expect().times(1..).return_const(Ok(()));

(mock_runtime_guard, recover_signer_ctx, lock_under_vesting_ctx)
};

let origin = RawOrigin::Signed(account_id.clone());

}: _(origin, ethereum_address, ethereum_signature)
verify {
assert_eq!(Claims::<T>::get(ethereum_address), None);

let account_balance_after = <CurrencyOf<T>>::total_balance(&account_id);
assert_eq!(account_balance_after - account_balance_before, claim_info.balance);
assert_eq!(
currency_total_issuance_before,
<CurrencyOf<T>>::total_issuance(),
);

#[cfg(test)]
{
let (mock_runtime_guard, recover_signer_ctx, lock_under_vesting_ctx) = test_data;

recover_signer_ctx.checkpoint();
lock_under_vesting_ctx.checkpoint();

drop(mock_runtime_guard);
}
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Test,
);
}

#[cfg(test)]
impl Interface for crate::mock::Test {
fn account_id_to_claim_to() -> <Self as frame_system::Config>::AccountId {
42
}

fn ethereum_address() -> EthereumAddress {
mock::eth(mock::EthAddr::WithVesting)
}

fn create_ecdsa_signature(
_account_id: &<Self as frame_system::Config>::AccountId,
_ethereum_address: &EthereumAddress,
) -> EcdsaSignature {
EcdsaSignature::default()
}
}
Loading