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

Code before:
			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]
fn setting_storage_works() {
	new_test_ext().execute_with(|| {
		assert!(Storage::<Test>::get().is_zero());


Review comment (suggestion):
```suggestion
			Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.5)),
```

Code after:
			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]
fn setting_storage_works() {
	new_test_ext().execute_with(|| {
		assert!(Storage::<Test>::get().is_zero());