1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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 Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
#![cfg(test)]
18

            
19
use {
20
    crate::{tests::common::*, Sudo},
21
    frame_support::{assert_noop, assert_ok},
22
    sp_std::vec,
23
};
24

            
25
#[test]
26
1
fn sudo_is_set_to_alice_and_can_be_changed() {
27
1
    ExtBuilder::default()
28
1
        .with_balances(vec![
29
1
            // Alice gets 10k extra tokens for her mapping deposit
30
1
            (AccountId::from(ALICE), 210_000 * UNIT),
31
1
            (AccountId::from(BOB), 100_000 * UNIT),
32
1
            (AccountId::from(CHARLIE), 100_000 * UNIT),
33
1
            (AccountId::from(DAVE), 100_000 * UNIT),
34
1
        ])
35
1
        .with_sudo(AccountId::from(ALICE))
36
1
        .build()
37
1
        .execute_with(|| {
38
1
            run_to_block(2);
39
1
            // Alice should be able to execute this extrinsic
40
1
            assert_ok!(Sudo::sudo(
41
1
                origin_of(ALICE.into()),
42
1
                Box::new(
43
1
                    pallet_sudo::Call::set_key {
44
1
                        new: AccountId::from(BOB).into()
45
1
                    }
46
1
                    .into()
47
1
                )
48
1
            ));
49

            
50
            // Now Bob should be the sudo account. Trying again with Alice should not work
51
1
            assert_noop!(
52
1
                Sudo::sudo(
53
1
                    origin_of(ALICE.into()),
54
1
                    Box::new(
55
1
                        pallet_sudo::Call::set_key {
56
1
                            new: AccountId::from(BOB).into()
57
1
                        }
58
1
                        .into()
59
1
                    )
60
1
                ),
61
1
                pallet_sudo::Error::<Runtime>::RequireSudo
62
1
            );
63

            
64
1
            assert_ok!(Sudo::sudo(
65
1
                origin_of(BOB.into()),
66
1
                Box::new(
67
1
                    pallet_sudo::Call::set_key {
68
1
                        new: AccountId::from(ALICE).into()
69
1
                    }
70
1
                    .into()
71
1
                )
72
1
            ));
73
1
        });
74
1
}