datahaven/operator/runtime/testnet/tests/lib.rs
Ahmad Kaouk ac09a4f2bb
feat: Add SafeMode and TxPause Pallets (#192)
### Overview
This PR integrates the `pallet-safe-mode` and `pallet-tx-pause` from
Polkadot SDK to provide comprehensive emergency governance controls
across all DataHaven runtime networks (mainnet, stagenet, testnet).

### Key Changes

#### 🔧 **Core Integration**
- **Dependencies**: Added `pallet-safe-mode` and `pallet-tx-pause` from
`polkadot-stable2412-6`
- **Runtime Integration**: Integrated both pallets across all three
runtime networks with pallet indices 103 and 104
- **Call Filtering**: Implemented unified `RuntimeCallFilter` that
combines Normal, SafeMode, and TxPause restrictions

#### 🛡️ **SafeMode Pallet Configuration**
- **Duration**: 1 day activation period (`DAYS` constant)
- **Deposits**: Disabled permissionless entry/extension (all `None`)
- **Origins**: Root-only for all force operations (`force_enter`,
`force_exit`, `force_extend`, etc.)
- **Whitelisting**: SafeMode and Sudo calls are immune to restrictions

#### ⏸️ **TxPause Pallet Configuration** 
- **Origins**: Root-only pause/unpause control
- **Whitelisting**: SafeMode and Sudo calls cannot be paused
- **Max Call Name Length**: 256 characters

#### 🏗️ **Architecture**
- **Shared Types**: Created `operator/runtime/common/src/safe_mode.rs`
with reusable configurations
- **Combined Filtering**: `RuntimeCallFilter` applies all three filter
layers (Normal + SafeMode + TxPause)
- **Consistent Config**: Identical configuration across mainnet,
stagenet, and testnet

#### 📊 **Infrastructure Updates**
- **Benchmarking**: Added both pallets to benchmark suites across all
networks
- **Weight Mappings**: Placeholder weights using Substrate defaults
(ready for chain-specific benchmarking)
- **Metadata**: Updated runtime metadata for new pallet exposure

#### 🧪 **Testing Framework**
- **Coverage**: Tests for individual pallet behavior, combined
restrictions, whitelisting, and edge cases

### Emergency Control Capabilities

**SafeMode Pallet** (8 calls):
- User calls: `enter`, `extend`, `release_deposit`
- Force calls: `force_enter`, `force_exit`, `force_extend`,
`force_slash_deposit`, `force_release_deposit`

**TxPause Pallet** (2 calls):
- `pause_call` / `unpause_call` - Granular transaction type pausing

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
2025-10-06 17:00:10 +00:00

62 lines
1.9 KiB
Rust

//! Integration tests for DataHaven testnet runtime
pub mod common;
pub mod governance;
mod native_token_transfer;
mod proxy;
mod safe_mode_tx_pause;
use common::*;
use datahaven_testnet_runtime::{
currency::HAVE, Balances, Runtime, System, UncheckedExtrinsic, VERSION,
};
use sp_core::H160;
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionSource, TransactionValidityError,
};
use sp_transaction_pool::runtime_api::runtime_decl_for_tagged_transaction_queue::TaggedTransactionQueueV3;
// Runtime Tests
#[test]
fn test_runtime_version_and_metadata() {
ExtBuilder::default().build().execute_with(|| {
assert!(!VERSION.spec_name.is_empty());
assert!(VERSION.spec_version > 0);
assert_eq!(System::block_number(), 1);
});
}
#[test]
fn test_balances_functionality() {
ExtBuilder::default()
.with_balances(vec![(account_id(ALICE), 2_000_000 * HAVE)])
.build()
.execute_with(|| {
assert_eq!(Balances::free_balance(&account_id(ALICE)), 2_000_000 * HAVE);
});
}
#[test]
fn validate_transaction_fails_on_filtered_call() {
ExtBuilder::default().build().execute_with(|| {
let xt = UncheckedExtrinsic::new_bare(
pallet_evm::Call::<Runtime>::call {
source: H160::default(),
target: H160::default(),
input: Vec::new(),
value: sp_core::U256::zero(),
gas_limit: 21000,
max_fee_per_gas: sp_core::U256::zero(),
max_priority_fee_per_gas: Some(sp_core::U256::zero()),
nonce: None,
access_list: Vec::new(),
}
.into(),
);
assert_eq!(
Runtime::validate_transaction(TransactionSource::External, xt, Default::default(),),
Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
);
});
}