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

Set Existential Deposit to Zero and Refactor Related Tests #170

Merged
merged 30 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
baf5110
create the test
asiniscalchi Nov 10, 2023
9de068c
existential deposit to 1
asiniscalchi Nov 10, 2023
f3b3a49
Merge branch 'main' into feature/existential_deposit_is_0
asiniscalchi Nov 10, 2023
6e669c3
removed tests not necessary
asiniscalchi Nov 10, 2023
b58bbf9
Merge branch 'feature/existential_deposit_is_0' of github.com:freever…
asiniscalchi Nov 10, 2023
0419844
refactoring
asiniscalchi Nov 10, 2023
0bfa523
refactoring
asiniscalchi Nov 10, 2023
e7b23ab
using existential balance == 0
asiniscalchi Nov 10, 2023
7266d95
fmt
asiniscalchi Nov 10, 2023
c773ed7
fix compilation error
asiniscalchi Nov 13, 2023
f2c557f
add test for minimum amount
asiniscalchi Nov 13, 2023
ba7e5bc
fmt
asiniscalchi Nov 13, 2023
641fff7
add ese test for minimum amount
asiniscalchi Nov 13, 2023
f7b042c
Merge branch 'feature/test_sending_1_wei' into feature/existential_de…
asiniscalchi Nov 13, 2023
9170541
sending 1 wei
asiniscalchi Nov 13, 2023
8ba1833
Update ownership-chain/runtime/src/tests.rs
asiniscalchi Nov 13, 2023
5ccfa29
better commnet
asiniscalchi Nov 13, 2023
5dc42de
Merge branch 'main' into feature/existential_deposit_is_0
asiniscalchi Nov 13, 2023
8a5d78f
fix the merge
asiniscalchi Nov 13, 2023
c8da0a8
better test name
asiniscalchi Nov 14, 2023
f68dd61
comment identation
asiniscalchi Nov 14, 2023
25c9ddc
using assert! in test
asiniscalchi Nov 14, 2023
c1aeab6
protect the candidacy_bond from a 0 Esitential deposit
asiniscalchi Nov 14, 2023
67cd3c0
some consmetics
asiniscalchi Nov 14, 2023
3e64cc7
Merge branch 'main' into feature/existential_deposit_is_0
asiniscalchi Nov 14, 2023
812813e
fmt
asiniscalchi Nov 14, 2023
241474f
not needed to have a candidacy bond so high
asiniscalchi Nov 14, 2023
614f9ba
move e2e test -> unit test
asiniscalchi Nov 15, 2023
bbe24de
removed unuseful test
asiniscalchi Nov 15, 2023
db07a6a
Merge branch 'main' into feature/existential_deposit_is_0
asiniscalchi Nov 15, 2023
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
5 changes: 3 additions & 2 deletions ownership-chain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use cumulus_primitives_core::ParaId;
use fp_evm::GenesisAccount;
use hex_literal::hex;
use laos_ownership_runtime::{AccountId, AuraId, Precompiles, EXISTENTIAL_DEPOSIT};
use laos_ownership_runtime::{AccountId, AuraId, Precompiles};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public, H160, U256};
use sp_runtime::traits::Zero;
use std::{collections::BTreeMap, str::FromStr};

/// List of endowed accounts.
Expand Down Expand Up @@ -181,7 +182,7 @@ fn testnet_genesis(
},
collator_selection: laos_ownership_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
candidacy_bond: Zero::zero(),
..Default::default()
},
session: laos_ownership_runtime::SessionConfig {
Expand Down
2 changes: 1 addition & 1 deletion ownership-chain/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-balances = { workspace = true , features = ["insecure_zero_ed"] }
pallet-multisig = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
Expand Down
12 changes: 8 additions & 4 deletions ownership-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ pub const UNIT: Balance = 1_000_000_000_000_000_000;
pub const MILLIUNIT: Balance = UNIT / 1000;
pub const MICROUNIT: Balance = MILLIUNIT / 1000;

/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;

/// Current approximation of the gas/s consumption considering
/// EVM execution over compiled WASM (on 4.4Ghz CPU).
/// Given the 500ms Weight, from which 75% only are used for transactions,
Expand Down Expand Up @@ -333,7 +330,14 @@ impl pallet_authorship::Config for Runtime {
}

parameter_types! {
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
/// The minimum amount required to keep an account open, set to zero in this case.
///
/// While it's generally advised to have this value greater than zero to avoid potential
/// DoS vectors, we set it to zero here due to specific concerns about relay attacks.
/// In such attacks, the reset of the nonce upon account deletion can be exploited.
/// By setting the ExistentialDeposit to zero, we prevent the scenario where an account's
/// balance drops to a level that would trigger its deletion and subsequent nonce reset.
pub const ExistentialDeposit: Balance = 0;
}

impl pallet_balances::Config for Runtime {
Expand Down
38 changes: 35 additions & 3 deletions ownership-chain/runtime/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
use super::*;
use frame_support::assert_ok;
use fp_rpc::runtime_decl_for_ethereum_runtime_rpc_api::EthereumRuntimeRPCApiV5;
use frame_support::{
assert_ok,
traits::tokens::{fungible::Balanced, Precision},
};
use sp_core::U256;
use std::str::FromStr;

const ALICE: &str = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac";

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap()
.into()
}

#[test]
fn test_block_and_gas_limit_constants() {
use crate::Runtime;
fn minimum_balance_should_be_0() {
assert_eq!(Balances::minimum_balance(), 0);
}

#[test]
fn test_block_and_gas_limit_constants() {
let system_block_weights = <Runtime as frame_system::Config>::BlockWeights::get();

assert_ok!(system_block_weights.clone().validate());
Expand All @@ -27,3 +45,17 @@ fn test_multisig_constants() {
assert_eq!(<Runtime as pallet_multisig::Config>::DepositFactor::get(), UNIT / 10);
assert_eq!(<Runtime as pallet_multisig::Config>::MaxSignatories::get(), 20);
}

#[test]
fn send_1_minimum_unit_to_wallet_with_0_wei_balance_should_increase_balance_by_1_wei() {
new_test_ext().execute_with(|| {
let alice = AccountId::from_str(ALICE).unwrap();
assert_eq!(Runtime::account_basic(alice.into()).balance, 0.into());

let minimum_amount = 1;
assert!(Balances::deposit(&alice, minimum_amount, Precision::Exact).is_ok());
assert_eq!(Balances::total_balance(&alice), minimum_amount);

assert_eq!(Runtime::account_basic(alice.into()).balance, 1.into());
})
}