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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "gtest/gtest.h"
#include "common/util.h"
#include "cryptonote_core/cryptonote_format_utils.h"
TEST(parse_and_validate_tx_extra, is_correct_parse_and_validate_tx_extra)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
cryptonote::account_base acc;
acc.generate();
std::vector<size_t> bss;
cryptonote::blobdata b = "dsdsdfsdfsf";
bool r = cryptonote::construct_miner_tx(0, 10000000000000, acc.get_keys().m_account_address, tx, DEFAULT_FEE, bss, 1000, b, 1);
ASSERT_TRUE(r);
crypto::public_key tx_pub_key;
r = cryptonote::parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_TRUE(r);
}
TEST(parse_and_validate_tx_extra, is_correct_extranonce_too_big)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
cryptonote::account_base acc;
acc.generate();
std::vector<size_t> bss;
cryptonote::blobdata b(260, 0);
bool r = cryptonote::construct_miner_tx(0, 10000000000000, acc.get_keys().m_account_address, tx, DEFAULT_FEE, bss, 1000, b, 1);
ASSERT_FALSE(r);
}
TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_couner_too_big)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
tx.extra.resize(20, 0);
tx.extra[0] = TX_EXTRA_NONCE;
tx.extra[1] = 255;
crypto::public_key tx_pub_key;
bool r = parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_FALSE(r);
}
TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_nonce_double_entry)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
tx.extra.resize(20, 0);
cryptonote::blobdata v = "asasdasd";
cryptonote::add_tx_extra_nonce(tx, v);
cryptonote::add_tx_extra_nonce(tx, v);
crypto::public_key tx_pub_key;
bool r = parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_FALSE(r);
}
TEST(validate_parse_amount_case, validate_parse_amount)
{
uint64_t res = 0;
bool r = cryptonote::parse_amount(res, "0.0001");
ASSERT_TRUE(r);
ASSERT_EQ(res, 10000);
r = cryptonote::parse_amount(res, "100.0001");
ASSERT_TRUE(r);
ASSERT_EQ(res, 10000010000);
r = cryptonote::parse_amount(res, "000.0000");
ASSERT_TRUE(r);
ASSERT_EQ(res, 0);
r = cryptonote::parse_amount(res, "0");
ASSERT_TRUE(r);
ASSERT_EQ(res, 0);
r = cryptonote::parse_amount(res, " 100.0001 ");
ASSERT_TRUE(r);
ASSERT_EQ(res, 10000010000);
r = cryptonote::parse_amount(res, " 100.0000 ");
ASSERT_TRUE(r);
ASSERT_EQ(res, 10000000000);
r = cryptonote::parse_amount(res, " 100. 0000 ");
ASSERT_FALSE(r);
r = cryptonote::parse_amount(res, "100. 0000");
ASSERT_FALSE(r);
r = cryptonote::parse_amount(res, "100 . 0000");
ASSERT_FALSE(r);
r = cryptonote::parse_amount(res, "100.00 00");
ASSERT_FALSE(r);
r = cryptonote::parse_amount(res, "1 00.00 00");
ASSERT_FALSE(r);
}
|