Repository: paritytech/substrate
File: frame/glutton/src/tests.rs (Rust)

Code before:
		assert_eq!(TrashDataCount::<Test>::get(), 6000);
		assert_eq!(TrashData::<Test>::iter_keys().count(), 6000);

		assert_noop!(
			Glutton::initialize_pallet(RuntimeOrigin::root(), 0, None),
			Error::<Test>::AlreadyInitialized
		);
		assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 0, Some(6000)));
		assert_eq!(TrashDataCount::<Test>::get(), 0);
		assert_eq!(TrashData::<Test>::iter_keys().count(), 0);
	});
}

#[test]
fn setting_compute_works() {
	new_test_ext().execute_with(|| {
		assert_eq!(Compute::<Test>::get(), Zero::zero());

		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(0.3)));
		assert_eq!(Compute::<Test>::get(), FixedU64::from_float(0.3));
		System::assert_last_event(
			Event::ComputationLimitSet { compute: FixedU64::from_float(0.3) }.into(),
		);

		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.3)),
			DispatchError::BadOrigin
		);
		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.3)),
			DispatchError::BadOrigin
		);
	});
}

#[test]
fn setting_compute_respects_limit() {
	new_test_ext().execute_with(|| {
		// < 1000% is fine
		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(9.99)),);
		// == 1000% is fine
		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_u32(10)),);
		// > 1000% is not
		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(10.01)),
			Error::<Test>::InsaneLimit
		);
	});
}

#[test]

Review comment (suggestion):
Maybe better to set a different value than current one, otherwise it would be no-op even if it is set, no ?
```suggestion
			Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)),
```

Code after:
		assert_eq!(TrashDataCount::<Test>::get(), 6000);
		assert_eq!(TrashData::<Test>::iter_keys().count(), 6000);

		assert_noop!(
			Glutton::initialize_pallet(RuntimeOrigin::root(), 0, None),
			Error::<Test>::AlreadyInitialized
		);
		assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 0, Some(6000)));
		assert_eq!(TrashDataCount::<Test>::get(), 0);
		assert_eq!(TrashData::<Test>::iter_keys().count(), 0);
	});
}

#[test]
fn setting_compute_works() {
	new_test_ext().execute_with(|| {
		assert_eq!(Compute::<Test>::get(), Zero::zero());

		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(0.3)));
		assert_eq!(Compute::<Test>::get(), FixedU64::from_float(0.3));
		System::assert_last_event(
			Event::ComputationLimitSet { compute: FixedU64::from_float(0.3) }.into(),
		);

		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)),
			DispatchError::BadOrigin
		);
		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.5)),
			DispatchError::BadOrigin
		);
	});
}

#[test]
fn setting_compute_respects_limit() {
	new_test_ext().execute_with(|| {
		// < 1000% is fine
		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(9.99)),);
		// == 1000% is fine
		assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_u32(10)),);
		// > 1000% is not
		assert_noop!(
			Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(10.01)),
			Error::<Test>::InsaneLimit
		);
	});
}

#[test]