Skip to content

testnet deploy 5/27/2025 #1692

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

Merged
merged 32 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
35e4c6e
udpate readme
open-junius May 20, 2025
9ffd3e0
add filter
camfairchild May 21, 2025
258eb3d
fmt
camfairchild May 21, 2025
5d51d40
add more tests
camfairchild May 21, 2025
62c8cef
Add unstake all call validation in signed ext
gztensor May 21, 2025
54bf122
Fix SubtokenEnabled
gztensor May 21, 2025
3ba9333
bump spec version
sam0x17 May 21, 2025
1c3f4c9
Merge remote-tracking branch 'origin/hotfix/add-call-filter-for-neste…
sam0x17 May 21, 2025
0c3c6a0
cargo fmt
sam0x17 May 21, 2025
3506ffa
Merge pull request #1663 from opentensor/hotfix/add-call-filter-for-n…
sam0x17 May 21, 2025
cb3a7ad
ignore stale drand
liamaharon May 21, 2025
5d185cf
spec version bump
liamaharon May 21, 2025
dd3dcb6
tests
liamaharon May 21, 2025
397e997
bump for safety
liamaharon May 21, 2025
da2c732
Merge pull request #1665 from liamaharon/ignore-stale-drand
sam0x17 May 21, 2025
4a602ff
fix everything
sam0x17 May 21, 2025
9e59313
add a log
sam0x17 May 21, 2025
268ea4a
fixes
sam0x17 May 21, 2025
705e2f8
cargo clippy
sam0x17 May 21, 2025
5a7dde1
use runtime call
camfairchild May 21, 2025
c34c688
fix everything
sam0x17 May 21, 2025
ed91975
bump spec
sam0x17 May 21, 2025
cd36344
Merge pull request #1669 from opentensor/fix-everything-devnet
sam0x17 May 21, 2025
494dfbd
refine
sam0x17 May 21, 2025
fdd5d93
typo
sam0x17 May 21, 2025
a1bf521
Merge pull request #1668 from opentensor/fix-everything
sam0x17 May 21, 2025
043e607
Merge pull request #1657 from opentensor/fix-readme-evm-test
sam0x17 May 24, 2025
186024f
Merge remote-tracking branch 'origin/main' into backpropagate-hotfixe…
sam0x17 May 27, 2025
42cf955
Merge pull request #1689 from opentensor/backpropagate-hotfixes-5-27-…
sam0x17 May 27, 2025
417f1bb
Merge pull request #1690 from opentensor/devnet-ready
sam0x17 May 27, 2025
1db0213
bump spec version
sam0x17 May 28, 2025
cad0ebc
Merge remote-tracking branch 'origin/devnet-ready' into devnet
sam0x17 May 28, 2025
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
19 changes: 17 additions & 2 deletions evm-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
# type-test

test with ts
The evm-tests folder includes all typescript code to test the basic EVM function
like token transfer, and all precompile contracts in Subtensor. It is
implemented in typescript, use both ethers and viem lib to interact with
contracts. The polkadot API is used to call extrinsic, get storage in Subtensor
. The developers can use it to verify the code change in precompile contracts.

It is also included in the CI process, all test cases are executed for new
commit. CI flow can get catch any failed test cases. The polkadot API get the
latest metadata from the runtime, the case also can find out any incompatibility
between runtime and precompile contracts.

## polkadot api

To get the metadata, you need start the localnet via run
`./scripts/localnet.sh`. then run following command to get metadata, a folder
name .papi will be created, which include the metadata and type definitions.

```bash
npx papi add devnet -w ws://10.0.0.11:9944
npx papi add devnet -w ws://localhost:9944
```

## get the new metadata

If the runtime is upgrade, need to get the metadata again.

```bash
sh get-metadata.sh
```
Expand Down
4 changes: 4 additions & 0 deletions pallets/drand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ pub mod pallet {
pulses_payload: payload,
signature,
} => {
// Blacklist stale pulses in the txpool that can stall finalization.
if payload.block_number < BlockNumberFor::<T>::from(5612500u32) {
return InvalidTransaction::Stale.into();
}
let signature = signature.as_ref().ok_or(InvalidTransaction::BadSigner)?;
Self::validate_signature_and_parameters(
payload,
Expand Down
20 changes: 10 additions & 10 deletions pallets/drand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn it_can_submit_valid_pulse_when_beacon_config_exists() {
let p: Pulse = u_p.try_into_pulse().unwrap();

let alice = sp_keyring::Sr25519Keyring::Alice;
let block_number = 1;
let block_number = 100_000_000;
System::set_block_number(block_number);

// Set the beacon config
Expand Down Expand Up @@ -91,7 +91,7 @@ fn it_can_submit_valid_pulse_when_beacon_config_exists() {
fn it_rejects_invalid_pulse_due_to_bad_signature() {
new_test_ext().execute_with(|| {
let alice = sp_keyring::Sr25519Keyring::Alice;
let block_number = 1;
let block_number = 100_000_000;
System::set_block_number(block_number);

// Set the beacon config using Root origin
Expand Down Expand Up @@ -139,7 +139,7 @@ fn it_rejects_invalid_pulse_due_to_bad_signature() {
#[test]
fn it_rejects_pulses_with_non_incremental_round_numbers() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);

Expand Down Expand Up @@ -189,7 +189,7 @@ fn it_rejects_pulses_with_non_incremental_round_numbers() {
#[test]
fn it_blocks_non_root_from_submit_beacon_info() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);

Expand Down Expand Up @@ -239,7 +239,7 @@ fn it_blocks_non_root_from_submit_beacon_info() {
#[test]
fn signed_cannot_submit_beacon_info() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);

Expand Down Expand Up @@ -268,7 +268,7 @@ fn signed_cannot_submit_beacon_info() {
#[test]
fn test_validate_unsigned_write_pulse() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);
let pulses_payload = PulsesPayload {
Expand All @@ -293,7 +293,7 @@ fn test_validate_unsigned_write_pulse() {
#[test]
fn test_not_validate_unsigned_write_pulse_with_bad_proof() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);
let pulses_payload = PulsesPayload {
Expand All @@ -319,7 +319,7 @@ fn test_not_validate_unsigned_write_pulse_with_bad_proof() {
#[test]
fn test_not_validate_unsigned_write_pulse_with_no_payload_signature() {
new_test_ext().execute_with(|| {
let block_number = 1;
let block_number = 100_000_000;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);
let pulses_payload = PulsesPayload {
Expand Down Expand Up @@ -388,8 +388,8 @@ fn can_execute_and_handle_valid_http_responses() {
#[test]
fn validate_unsigned_rejects_future_block_number() {
new_test_ext().execute_with(|| {
let block_number = 1;
let future_block_number = 100;
let block_number = 100_000_000;
let future_block_number = 100_000_100;
let alice = sp_keyring::Sr25519Keyring::Alice;
System::set_block_number(block_number);
let pulses_payload = PulsesPayload {
Expand Down
14 changes: 14 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,20 @@ where
// Self::get_priority_staking(who, hotkey, *amount_unstaked),
// )
// }
Some(Call::unstake_all { hotkey }) => {
// Fully validate the user input
Self::result_to_validity(
Pallet::<T>::validate_unstake_all(who, hotkey, false),
Self::get_priority_vanilla(),
)
}
Some(Call::unstake_all_alpha { hotkey }) => {
// Fully validate the user input
Self::result_to_validity(
Pallet::<T>::validate_unstake_all(who, hotkey, true),
Self::get_priority_vanilla(),
)
}
Some(Call::move_stake {
origin_hotkey,
destination_hotkey,
Expand Down
36 changes: 36 additions & 0 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,42 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/// Validate if unstake_all can be executed
///
pub fn validate_unstake_all(
coldkey: &T::AccountId,
hotkey: &T::AccountId,
only_alpha: bool,
) -> Result<(), Error<T>> {
// Get all netuids (filter out root)
let subnets: Vec<u16> = Self::get_all_subnet_netuids();

// Ensure that the hotkey account exists this is only possible through registration.
ensure!(
Self::hotkey_account_exists(hotkey),
Error::<T>::HotKeyAccountNotExists
);

let mut unstaking_any = false;
for netuid in subnets.iter() {
if only_alpha && (*netuid == Self::get_root_netuid()) {
continue;
}

// Get user's stake in this subnet
let alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet(hotkey, coldkey, *netuid);

if Self::validate_remove_stake(coldkey, hotkey, *netuid, alpha, alpha, false).is_ok() {
unstaking_any = true;
}
}

// If no unstaking happens, return error
ensure!(unstaking_any, Error::<T>::AmountTooLow);

Ok(())
}

/// Validate stake transition user input
/// That works for move_stake, transfer_stake, and swap_stake
///
Expand Down
86 changes: 85 additions & 1 deletion pallets/subtensor/src/tests/batch_tx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::mock::*;
use frame_support::{assert_ok, traits::Currency};
use frame_support::{
assert_ok,
traits::{Contains, Currency},
};
use frame_system::Config;
use sp_core::U256;

Expand Down Expand Up @@ -33,3 +36,84 @@ fn test_batch_txs() {
assert_eq!(Balances::total_balance(&charlie), 2_000_000_000);
});
}

#[test]
fn test_cant_nest_batch_txs() {
let bob = U256::from(1);
let charlie = U256::from(2);

new_test_ext(1).execute_with(|| {
let call = RuntimeCall::Utility(pallet_utility::Call::batch {
calls: vec![
RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: bob,
value: 1_000_000_000,
}),
RuntimeCall::Utility(pallet_utility::Call::batch {
calls: vec![RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: charlie,
value: 1_000_000_000,
})],
}),
],
});

assert!(!<Test as Config>::BaseCallFilter::contains(&call));
});
}

#[test]
fn test_can_batch_txs() {
let bob = U256::from(1);

new_test_ext(1).execute_with(|| {
let call = RuntimeCall::Utility(pallet_utility::Call::batch {
calls: vec![RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: bob,
value: 1_000_000_000,
})],
});

assert!(<Test as Config>::BaseCallFilter::contains(&call));
});
}

#[test]
fn test_cant_nest_batch_diff_batch_txs() {
let charlie = U256::from(2);

new_test_ext(1).execute_with(|| {
let call = RuntimeCall::Utility(pallet_utility::Call::batch {
calls: vec![RuntimeCall::Utility(pallet_utility::Call::force_batch {
calls: vec![RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: charlie,
value: 1_000_000_000,
})],
})],
});

assert!(!<Test as Config>::BaseCallFilter::contains(&call));

let call2 = RuntimeCall::Utility(pallet_utility::Call::batch_all {
calls: vec![RuntimeCall::Utility(pallet_utility::Call::batch {
calls: vec![RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: charlie,
value: 1_000_000_000,
})],
})],
});

assert!(!<Test as Config>::BaseCallFilter::contains(&call2));

let call3 = RuntimeCall::Utility(pallet_utility::Call::force_batch {
calls: vec![RuntimeCall::Utility(pallet_utility::Call::batch_all {
calls: vec![RuntimeCall::Balances(BalanceCall::transfer_allow_death {
dest: charlie,
value: 1_000_000_000,
})],
})],
});

assert!(!<Test as Config>::BaseCallFilter::contains(&call3));
});
}
27 changes: 25 additions & 2 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
use crate::utils::rate_limiting::TransactionType;
use frame_support::derive_impl;
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::traits::{Contains, Everything, InsideBoth};
use frame_support::weights::Weight;
use frame_support::weights::constants::RocksDbWeight;
use frame_support::{
assert_ok, parameter_types,
traits::{Everything, Hooks, PrivilegeCmp},
traits::{Hooks, PrivilegeCmp},
};
use frame_system as system;
use frame_system::{EnsureNever, EnsureRoot, RawOrigin, limits};
Expand Down Expand Up @@ -88,9 +89,31 @@ impl pallet_balances::Config for Test {
type MaxFreezes = ();
}

pub struct NoNestingCallFilter;

impl Contains<RuntimeCall> for NoNestingCallFilter {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Utility(inner) => {
let calls = match inner {
pallet_utility::Call::force_batch { calls } => calls,
pallet_utility::Call::batch { calls } => calls,
pallet_utility::Call::batch_all { calls } => calls,
_ => &Vec::new(),
};

!calls.iter().any(|call| {
matches!(call, RuntimeCall::Utility(inner) if matches!(inner, pallet_utility::Call::force_batch { .. } | pallet_utility::Call::batch_all { .. } | pallet_utility::Call::batch { .. }))
})
}
_ => true,
}
}
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl system::Config for Test {
type BaseCallFilter = Everything;
type BaseCallFilter = InsideBoth<Everything, NoNestingCallFilter>;
type BlockWeights = BlockWeights;
type BlockLength = ();
type DbWeight = RocksDbWeight;
Expand Down
51 changes: 51 additions & 0 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,57 @@ fn test_unstake_low_liquidity_validate() {
});
}

#[test]
fn test_unstake_all_validate() {
// Testing the signed extension validate function
// correctly filters the `unstake_all` transaction.

new_test_ext(0).execute_with(|| {
let subnet_owner_coldkey = U256::from(1001);
let subnet_owner_hotkey = U256::from(1002);
let hotkey = U256::from(2);
let coldkey = U256::from(3);
let amount_staked = DefaultMinStake::<Test>::get() * 10 + DefaultStakingFee::<Test>::get();

let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey);
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
SubtensorModule::add_balance_to_coldkey_account(&coldkey, amount_staked);

// Simulate stake for hotkey
SubnetTAO::<Test>::insert(netuid, u64::MAX / 1000);
SubnetAlphaIn::<Test>::insert(netuid, u64::MAX / 1000);
SubtensorModule::stake_into_subnet(&hotkey, &coldkey, netuid, amount_staked, 0);

// Set the liquidity at lowest possible value so that all staking requests fail
SubnetTAO::<Test>::insert(
netuid,
DefaultMinimumPoolLiquidity::<Test>::get().to_num::<u64>(),
);
SubnetAlphaIn::<Test>::insert(
netuid,
DefaultMinimumPoolLiquidity::<Test>::get().to_num::<u64>(),
);

// unstake_all call
let call = RuntimeCall::SubtensorModule(SubtensorCall::unstake_all { hotkey });

let info: DispatchInfo =
DispatchInfoOf::<<Test as frame_system::Config>::RuntimeCall>::default();

let extension = SubtensorSignedExtension::<Test>::new();
// Submit to the signed extension validate function
let result_no_stake = extension.validate(&coldkey, &call.clone(), &info, 10);

// Should fail due to insufficient stake
assert_err!(
result_no_stake,
TransactionValidityError::Invalid(InvalidTransaction::Custom(
CustomTransactionError::StakeAmountTooLow.into()
))
);
});
}

#[test]
fn test_max_amount_add_root() {
new_test_ext(0).execute_with(|| {
Expand Down
Loading
Loading