1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! Unit testing
18
use sp_runtime::BoundedVec;
19
use xcm::latest::Junction;
20

            
21
use crate::mock::{Erc20XcmBridge, Erc20XcmBridgeTransferGasLimit};
22

            
23
#[test]
24
1
fn general_key_data_size_32() {
25
1
	let junction: Junction = (BoundedVec::new()).into();
26
1

            
27
1
	// Assert that GeneralKey data length is 32 bytes
28
1
	match junction {
29
1
		Junction::GeneralKey { length: _, data } => {
30
1
			let _: [u8; 32] = data;
31
1
		}
32
		_ => assert!(false),
33
	}
34

            
35
1
	assert_eq!(
36
1
		Erc20XcmBridge::gas_limit_of_erc20_transfer(&junction.into()),
37
1
		Erc20XcmBridgeTransferGasLimit::get()
38
1
	)
39
1
}
40

            
41
#[test]
42
1
fn gas_limit_override() {
43
1
	let text = "gas_limit:".as_bytes();
44
1
	let limit = 300_000u64;
45
1
	let data = [text, &limit.to_le_bytes()].concat();
46
1
	let vec = BoundedVec::try_from(data).expect("vec should convert");
47
1
	let junction: Junction = (vec).into();
48
1
	assert_eq!(
49
1
		Erc20XcmBridge::gas_limit_of_erc20_transfer(&junction.into()),
50
1
		limit
51
1
	)
52
1
}
53

            
54
#[test]
55
1
fn gas_limit_override_typo() {
56
1
	let text = "gaslimit:".as_bytes();
57
1
	let limit = 300_000u64;
58
1
	let data = [text, &limit.to_le_bytes()].concat();
59
1
	let vec = BoundedVec::try_from(data).expect("vec should convert");
60
1
	let junction: Junction = (vec).into();
61
1
	assert_eq!(
62
1
		Erc20XcmBridge::gas_limit_of_erc20_transfer(&junction.into()),
63
1
		Erc20XcmBridgeTransferGasLimit::get()
64
1
	)
65
1
}