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 crate::mock::{ExtBuilder, Proxy, Test};
19
use pallet_proxy::ProxyDefinition;
20

            
21
#[test]
22
1
fn empty_genesis_works() {
23
1
	ExtBuilder::default()
24
1
		.build()
25
1
		.execute_with(|| assert_eq!(pallet_proxy::Proxies::<Test>::iter().count(), 0))
26
1
}
27

            
28
#[test]
29
1
fn non_empty_genesis_works() {
30
1
	ExtBuilder::default()
31
1
		// Account 1 delegates to account 2
32
1
		.with_proxies(vec![(1, 2)])
33
1
		// Account 1 is funded to pay the proxy deposit
34
1
		.with_balances(vec![(1, 10)])
35
1
		.build()
36
1
		.execute_with(|| {
37
1
			// Lookup info that we expect to be stored from genesis
38
1
			let (proxy_defs, deposit) = Proxy::proxies(1);
39
1

            
40
1
			// Make sure that Account 100 delegates to Account 101 and nobody else
41
1
			assert_eq!(proxy_defs.len(), 1);
42
1
			assert_eq!(
43
1
				proxy_defs[0],
44
1
				ProxyDefinition {
45
1
					delegate: 2,
46
1
					proxy_type: (),
47
1
					delay: 100
48
1
				}
49
1
			);
50

            
51
			// Make sure that Account 100 has the proper deposit amount reserved
52
1
			assert_eq!(deposit, 2);
53
1
		})
54
1
}
55

            
56
#[test]
57
#[should_panic(expected = "Genesis proxy could not be added: Module(ModuleError \
58
	{ index: 1, error: [2, 0, 0, 0], message: Some(\"InsufficientBalance\") })")]
59
1
fn genesis_fails_if_balance_insufficient() {
60
1
	ExtBuilder::default()
61
1
		.with_proxies(vec![(1, 2)])
62
1
		.build()
63
1
		.execute_with(|| ())
64
1
}