Skip to content
lib.rs 66.2 KiB
Newer Older
			TEST_LANE_ID,
			InboundLaneData {
				last_confirmed_nonce: 0,
				relayers: vec![unrewarded_relayer(1, 3, TEST_RELAYER_A)].into_iter().collect(),
			},
		)));
		let relayers_state = UnrewardedRelayersState {
			unrewarded_relayer_entries: 1,
			total_messages: 3,
			..Default::default()
		};
		let pre_dispatch_weight = <TestRuntime as Config>::WeightInfo::receive_messages_delivery_proof_weight(
			&proof,
			&relayers_state,
			crate::mock::DbWeight::get(),
		);
		let post_dispatch_weight =
			Pallet::<TestRuntime>::receive_messages_delivery_proof(Origin::signed(1), proof, relayers_state)
				.expect("confirmation has failed")
				.actual_weight
				.expect("receive_messages_delivery_proof always returns Some");
		(pre_dispatch_weight, post_dispatch_weight)
	}

	#[test]
	fn receive_messages_delivery_proof_refunds_zero_weight() {
		run_test(|| {
			let (pre_dispatch_weight, post_dispatch_weight) = confirm_3_messages_delivery();
			assert_eq!(pre_dispatch_weight, post_dispatch_weight);
		});
	}

	#[test]
	fn receive_messages_delivery_proof_refunds_non_zero_weight() {
		run_test(|| {
			TestOnDeliveryConfirmed1::set_consumed_weight_per_message(crate::mock::DbWeight::get().writes(1));

			let (pre_dispatch_weight, post_dispatch_weight) = confirm_3_messages_delivery();
			assert_eq!(
				pre_dispatch_weight.saturating_sub(post_dispatch_weight),
				crate::mock::DbWeight::get().reads(1) * 3
			);
		});
	}

	#[test]
	#[should_panic]
	fn receive_messages_panics_in_debug_mode_if_callback_is_wrong() {
		run_test(|| {
			TestOnDeliveryConfirmed1::set_consumed_weight_per_message(crate::mock::DbWeight::get().reads_writes(2, 2));
			confirm_3_messages_delivery()