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

feat: charge a fee for opening swap deposit addresses #4512

Merged
merged 9 commits into from
Feb 15, 2024
2 changes: 1 addition & 1 deletion state-chain/cf-integration-tests/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use state_chain_runtime::{Reputation, Runtime, Validator};

#[test]
fn account_deletion_removes_relevant_storage_items() {
super::genesis::default().build().execute_with(|| {
super::genesis::with_test_defaults().build().execute_with(|| {
let genesis_nodes = Validator::current_authorities();

// Create a single backup node which we will use to test deletion
Expand Down
16 changes: 8 additions & 8 deletions state-chain/cf-integration-tests/src/authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn fund_authorities_and_join_auction(
fn authority_rotates_with_correct_sequence() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -154,7 +154,7 @@ fn authorities_earn_rewards_for_authoring_blocks() {
// Reduce our validating set and hence the number of nodes we need to have a backup
// set
const MAX_AUTHORITIES: AuthorityCount = 3;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -198,7 +198,7 @@ fn genesis_nodes_rotated_out_accumulate_rewards_correctly() {
// Reduce our validating set and hence the number of nodes we need to have a backup
// set
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -263,7 +263,7 @@ fn genesis_nodes_rotated_out_accumulate_rewards_correctly() {
fn authority_rotation_can_succeed_after_aborted_by_safe_mode() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -318,7 +318,7 @@ fn authority_rotation_cannot_be_aborted_after_key_handover_and_completes_even_on
{
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -361,7 +361,7 @@ fn authority_rotation_cannot_be_aborted_after_key_handover_and_completes_even_on
fn authority_rotation_can_recover_after_keygen_fails() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -409,7 +409,7 @@ fn authority_rotation_can_recover_after_keygen_fails() {
fn authority_rotation_can_recover_after_key_handover_fails() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -477,7 +477,7 @@ fn authority_rotation_can_recover_after_key_handover_fails() {
fn can_move_through_multiple_epochs() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down
2 changes: 1 addition & 1 deletion state-chain/cf-integration-tests/src/broadcasting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use state_chain_runtime::{
fn bitcoin_broadcast_delay_works() {
const EPOCH_BLOCKS: u32 = 200;
const MAX_AUTHORITIES: AuthorityCount = 150;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down
12 changes: 6 additions & 6 deletions state-chain/cf-integration-tests/src/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use state_chain_runtime::{
fn cannot_redeem_funds_out_of_redemption_period() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 3;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -124,7 +124,7 @@ fn cannot_redeem_funds_out_of_redemption_period() {
#[test]
fn funded_node_is_added_to_backups() {
const EPOCH_BLOCKS: u32 = 10_000_000;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
// As we run a rotation at genesis we will need accounts to support
// having 5 authorities as the default is 3 (Alice, Bob and Charlie)
Expand All @@ -148,7 +148,7 @@ fn backup_reward_is_calculated_linearly() {
const EPOCH_BLOCKS: u32 = 1_000;
const MAX_AUTHORITIES: u32 = 10;
const NUM_BACKUPS: u32 = 20;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -193,7 +193,7 @@ fn can_calculate_account_apy() {
const EPOCH_BLOCKS: u32 = 1_000;
const MAX_AUTHORITIES: u32 = 10;
const NUM_BACKUPS: u32 = 20;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -245,7 +245,7 @@ fn apy_can_be_above_100_percent() {
const EPOCH_BLOCKS: u32 = 1_000;
const MAX_AUTHORITIES: u32 = 2;
const NUM_BACKUPS: u32 = 2;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
Expand Down Expand Up @@ -280,7 +280,7 @@ fn backup_rewards_event_gets_emitted_on_heartbeat_interval() {
const EPOCH_BLOCKS: u32 = 1_000;
const NUM_BACKUPS: u32 = 20;
const MAX_AUTHORITIES: u32 = 100;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.accounts(
(0..MAX_AUTHORITIES as u8)
Expand Down
4 changes: 2 additions & 2 deletions state-chain/cf-integration-tests/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const GENESIS_BALANCE: FlipBalance = TOTAL_ISSUANCE / 100;

const BLOCKS_PER_EPOCH: u32 = 1000;

pub fn default() -> ExtBuilder {
pub fn with_test_defaults() -> ExtBuilder {
ExtBuilder::default()
.accounts(vec![
(AccountId::from(ALICE), AccountRole::Validator, GENESIS_BALANCE),
Expand All @@ -30,7 +30,7 @@ pub fn default() -> ExtBuilder {

#[test]
fn state_of_genesis_is_as_expected() {
default().build().execute_with(|| {
with_test_defaults().build().execute_with(|| {
// Confirmation that we have our assumed state at block 1
assert_eq!(Flip::total_issuance(), TOTAL_ISSUANCE, "we have issued the total issuance");

Expand Down
2 changes: 1 addition & 1 deletion state-chain/cf-integration-tests/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pallet_transaction_payment::OnChargeTransaction;
#[test]
// Governance is allowed to make free calls to governance gated extrinsics.
fn governance_members_pay_no_fees_for_governance_extrinsics() {
super::genesis::default().build().execute_with(|| {
super::genesis::with_test_defaults().build().execute_with(|| {
let call: state_chain_runtime::RuntimeCall =
frame_system::Call::remark { remark: vec![] }.into();
let gov_call: state_chain_runtime::RuntimeCall =
Expand Down
17 changes: 16 additions & 1 deletion state-chain/cf-integration-tests/src/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl ExtBuilder {
self
}

pub fn with_additional_accounts(
mut self,
accounts: &[(AccountId, AccountRole, FlipBalance)],
) -> Self {
self.genesis_accounts.extend_from_slice(accounts);
self
}

pub fn root(mut self, root: AccountId) -> Self {
self.root = Some(root);
self
Expand Down Expand Up @@ -161,7 +169,14 @@ impl ExtBuilder {
genesis_backups: Default::default(),
genesis_vanity_names: Default::default(),
blocks_per_epoch: self.blocks_per_epoch,
bond: self.genesis_accounts.iter().map(|(.., amount)| *amount).min().unwrap(),
bond: self
.genesis_accounts
.iter()
.filter_map(|(.., role, amount)| {
matches!(role, AccountRole::Validator).then_some(*amount)
})
.min()
.unwrap(),
redemption_period_as_percentage: Percent::from_percent(
REDEMPTION_PERIOD_AS_PERCENTAGE,
),
Expand Down
28 changes: 23 additions & 5 deletions state-chain/cf-integration-tests/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

use crate::threshold_signing::{BtcThresholdSigner, DotThresholdSigner, EthThresholdSigner};

use cf_chains::address::EncodedAddress;
use cf_primitives::{AccountRole, BlockNumber, EpochIndex, FlipBalance, TxId, GENESIS_EPOCH};
use cf_test_utilities::assert_events_eq;
use cf_traits::{AccountRoleRegistry, Chainflip, EpochInfo, KeyRotator};
Expand All @@ -17,8 +18,8 @@ use pallet_cf_funding::{MinimumFunding, RedemptionAmount};
use sp_consensus_aura::SlotDuration;
use sp_std::collections::btree_set::BTreeSet;
use state_chain_runtime::{
AccountRoles, AllPalletsWithSystem, BitcoinInstance, PalletExecutionOrder, PolkadotInstance,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Validator, Weight,
AccountRoles, AllPalletsWithSystem, BitcoinInstance, LiquidityProvider, PalletExecutionOrder,
PolkadotInstance, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Validator, Weight,
};
use std::{
cell::RefCell,
Expand Down Expand Up @@ -736,10 +737,11 @@ pub fn fund_authorities_and_join_auction(
(testnet, genesis_authorities, init_backup_nodes)
}

// Helper function that registers account role for a new account.
pub fn new_account(account_id: &AccountId, role: AccountRole) {
<Runtime as frame_system::Config>::OnNewAccount::on_new_account(account_id);
System::inc_providers(account_id);
use cf_traits::Funding;

Flip::credit_funds(account_id, FLIPPERINOS_PER_FLIP);
AccountRoles::on_new_account(account_id);
assert_ok!(AccountRoles::register_account_role(account_id, role));
assert_events_eq!(
Runtime,
Expand All @@ -748,5 +750,21 @@ pub fn new_account(account_id: &AccountId, role: AccountRole) {
role,
})
);
if role == AccountRole::LiquidityProvider {
register_refund_addresses(account_id);
}
System::reset_events();
}

pub fn register_refund_addresses(account_id: &AccountId) {
for encoded_address in [
EncodedAddress::Eth(Default::default()),
EncodedAddress::Dot(Default::default()),
EncodedAddress::Btc("bcrt1qs758ursh4q9z627kt3pp5yysm78ddny6txaqgw".as_bytes().to_vec()),
] {
assert_ok!(LiquidityProvider::register_liquidity_refund_address(
RuntimeOrigin::signed(account_id.clone()),
encoded_address
));
}
}
4 changes: 2 additions & 2 deletions state-chain/cf-integration-tests/src/new_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use state_chain_runtime::Validator;
#[test]
fn auction_repeats_after_failure_because_of_liveness() {
const EPOCH_BLOCKS: BlockNumber = 1000;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
// As we run a rotation at genesis we will need accounts to support
// having 5 authorities as the default is 3 (Alice, Bob and Charlie)
Expand Down Expand Up @@ -96,7 +96,7 @@ fn auction_repeats_after_failure_because_of_liveness() {
fn epoch_rotates() {
const EPOCH_BLOCKS: BlockNumber = 1000;
const MAX_SET_SIZE: AuthorityCount = 5;
super::genesis::default()
super::genesis::with_test_defaults()
.blocks_per_epoch(EPOCH_BLOCKS)
.min_authorities(MAX_SET_SIZE)
.build()
Expand Down
4 changes: 2 additions & 2 deletions state-chain/cf-integration-tests/src/signer_nomination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type RuntimeThresholdSignerNomination =

#[test]
fn threshold_signer_nomination_respects_epoch() {
super::genesis::default().build().execute_with(|| {
super::genesis::with_test_defaults().build().execute_with(|| {
let genesis_authorities = Validator::current_authorities();
let genesis_epoch = Validator::epoch_index();

Expand Down Expand Up @@ -76,7 +76,7 @@ fn test_not_nominated_for_offence<F: Fn(crate::AccountId)>(penalise: F) {

#[test]
fn nodes_who_failed_to_sign_excluded_from_threshold_nomination() {
super::genesis::default().build().execute_with(|| {
super::genesis::with_test_defaults().build().execute_with(|| {
test_not_nominated_for_offence(|node_id| {
Reputation::report(PalletOffence::ParticipateSigningFailed, node_id)
});
Expand Down
Loading
Loading