Skip to content

Commit 6540ed4

Browse files
committed
Add unit tests for setting chain ID admin extrinsic
1 parent 5b90f6c commit 6540ed4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pallets/admin-utils/src/tests/mock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ frame_support::construct_runtime!(
2828
AdminUtils: crate = 3,
2929
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>} = 4,
3030
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 5,
31+
EVMChainId: pallet_evm_chain_id = 6,
3132
}
3233
);
3334

@@ -272,6 +273,8 @@ impl pallet_scheduler::Config for Test {
272273
type Preimages = ();
273274
}
274275

276+
impl pallet_evm_chain_id::Config for Test {}
277+
275278
// Build genesis storage according to the mock runtime.
276279
pub fn new_test_ext() -> sp_io::TestExternalities {
277280
sp_tracing::try_init_simple();

pallets/admin-utils/src/tests/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,3 +1433,36 @@ fn sudo_set_commit_reveal_weights_interval() {
14331433
assert_eq!(SubtensorModule::get_reveal_period(netuid), to_be_set);
14341434
});
14351435
}
1436+
1437+
#[test]
1438+
fn test_sudo_root_sets_evm_chain_id() {
1439+
new_test_ext().execute_with(|| {
1440+
let chain_id: u64 = 945;
1441+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1442+
1443+
assert_ok!(AdminUtils::sudo_set_evm_chain_id(
1444+
<<Test as Config>::RuntimeOrigin>::root(),
1445+
chain_id
1446+
));
1447+
1448+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), chain_id);
1449+
});
1450+
}
1451+
1452+
#[test]
1453+
fn test_sudo_non_root_cannot_set_evm_chain_id() {
1454+
new_test_ext().execute_with(|| {
1455+
let chain_id: u64 = 945;
1456+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1457+
1458+
assert_eq!(
1459+
AdminUtils::sudo_set_evm_chain_id(
1460+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
1461+
chain_id
1462+
),
1463+
Err(DispatchError::BadOrigin)
1464+
);
1465+
1466+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1467+
});
1468+
}

0 commit comments

Comments
 (0)