Loading...
Searching...
No Matches
transaction_test.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
21
22#include <glog/logging.h>
23#include <gtest/gtest.h>
24
25#include "common/crypto/hash.h"
28
29namespace resdb {
30namespace utxo {
31namespace {
32
33using ::testing::Test;
34
35TEST(TransanctionTest, InvalidInputString) {
36 Wallet wallet;
37 Transaction transaction(Config(), &wallet);
38 EXPECT_EQ(transaction.AddTransaction("123"), -1);
39}
40
41TEST(TransanctionTest, NoAddress) {
42 UTXO utxo;
43
44 UTXOOut* out = utxo.add_out();
45 out->set_address("1234");
46 out->set_value(1234);
47
48 std::string str;
49 utxo.SerializeToString(&str);
50
51 Wallet wallet;
52 Transaction transaction(Config(), &wallet);
53
54 EXPECT_EQ(transaction.AddTransaction(str), -1);
55}
56
57TEST(TransanctionTest, EmptyInputUtxo) {
58 UTXO utxo;
59
60 UTXOOut* out = utxo.add_out();
61 out->set_address("1234");
62 out->set_value(1234);
63
64 utxo.set_address("0001");
65
66 std::string str;
67 utxo.SerializeToString(&str);
68
69 Wallet wallet;
70 Transaction transaction(Config(), &wallet);
71
72 EXPECT_EQ(transaction.AddTransaction(str), -1);
73}
74
75TEST(TransanctionTest, DefaultUTXO) {
76 SecretKey key = KeyGenerator ::GeneratorKeys(SignatureInfo::ECDSA);
77
78 Config config;
79 {
80 auto* gensis_txn = config.mutable_genesis_transactions();
81 UTXO* utxo = gensis_txn->add_transactions();
82 UTXOOut* out = utxo->add_out();
83 out->set_address("0001");
84 out->set_value(1234);
85 out->set_pub_key(key.public_key());
86 }
87
88 Wallet wallet;
89 Transaction transaction(config, &wallet);
90
91 {
92 UTXO utxo;
93 UTXOIn* in = utxo.add_in();
94 in->set_prev_id(0);
95 in->set_out_idx(0);
96
97 UTXOOut* out = utxo.add_out();
98 out->set_address("1234");
99 out->set_value(234);
100 utxo.set_address("0001");
101
102 std::string signature = utils::ECDSASignString(
103 key.private_key(), utxo.address() + std::to_string(0));
104 utxo.set_sig(signature);
105
106 std::string str;
107 utxo.SerializeToString(&str);
108
109 EXPECT_EQ(transaction.AddTransaction(str), 1);
110 }
111
112 EXPECT_EQ(wallet.GetCoin("1234"), 234);
113}
114
115} // namespace
116} // namespace utxo
117} // namespace resdb
std::string ECDSASignString(const std::string &private_key, const std::string &message)
TEST(NetworkUtilsTest, GetDNSName)