forked from dtr-org/unit-e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpcvalidator_tests.cpp
69 lines (49 loc) · 2.18 KB
/
rpcvalidator_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2018 The Unit-e developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <wallet/rpcvalidator.h>
#include <test/rpc_test_utils.h>
#include <test/test_unite.h>
#include <wallet/test/wallet_test_fixture.h>
#include <boost/test/unit_test.hpp>
struct ValidatorWalletSetup : WalletTestingSetup {
ValidatorWalletSetup()
: WalletTestingSetup([](Settings &settings) {
settings.node_is_proposer = false;
settings.node_is_validator = true;
}) {}
};
BOOST_AUTO_TEST_SUITE(rpcvalidator_tests)
CTxDestination GetDestination(CWallet &wallet, OutputType type) {
CPubKey pk;
{
LOCK(wallet.cs_wallet);
CKey k;
InsecureNewKey(k, true);
wallet.AddKey(k);
pk = k.GetPubKey();
}
return GetDestinationForKey(pk, type);
}
//Test deposit
BOOST_FIXTURE_TEST_CASE(deposit_p2sh_segwit_not_supported, ValidatorWalletSetup) {
CTxDestination p2sh = GetDestination(*pwalletMain, OUTPUT_TYPE_P2SH_SEGWIT);
std::string command = "deposit " + EncodeDestination(p2sh) + " 1500";
AssertRPCError(command, RPC_INVALID_ADDRESS_OR_KEY, "Address must be a P2PKH address.");
}
BOOST_FIXTURE_TEST_CASE(deposit_bech32_not_supported, ValidatorWalletSetup) {
CTxDestination bech32 = GetDestination(*pwalletMain, OUTPUT_TYPE_BECH32);
std::string command = "deposit " + EncodeDestination(bech32) + " 1500";
AssertRPCError(command, RPC_INVALID_ADDRESS_OR_KEY, "Address must be a P2PKH address.");
}
BOOST_FIXTURE_TEST_CASE(deposit_p2pkh_supported_but_not_enough_funds, ValidatorWalletSetup) {
CTxDestination p2pkh = GetDestination(*pwalletMain, OUTPUT_TYPE_LEGACY);
std::string command = "deposit " + EncodeDestination(p2pkh) + " 1499";
AssertRPCError(command, RPC_INVALID_PARAMETER, "Amount is below minimum allowed.");
}
BOOST_FIXTURE_TEST_CASE(deposit_not_a_validator, WalletTestingSetup) {
CTxDestination p2pkh = GetDestination(*pwalletMain, OUTPUT_TYPE_LEGACY);
std::string command = "deposit " + EncodeDestination(p2pkh) + " 0";
AssertRPCError(command, RPC_INVALID_REQUEST, "The node must be enabled to be a finalizer.");
}
BOOST_AUTO_TEST_SUITE_END()