Loading...
Searching...
No Matches
utxo_executor_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
27#include "proto/utxo/rpc.pb.h"
28
29namespace resdb {
30namespace utxo {
31namespace {
32
33using ::testing::Test;
34
35TEST(UTXOExecutorTest, AddUTXO) {
36 Config config;
37
38 SecretKey key = KeyGenerator ::GeneratorKeys(SignatureInfo::ECDSA);
39
40 {
41 auto* gensis_txn = config.mutable_genesis_transactions();
42 UTXO* utxo = gensis_txn->add_transactions();
43 UTXOOut* out = utxo->add_out();
44 out->set_address("0001");
45 out->set_value(1234);
46 out->set_pub_key(key.public_key());
47 }
48 Wallet wallet;
49 Transaction transaction(config, &wallet);
50 UTXOExecutor txn_manager(config, &transaction, &wallet);
51
52 {
53 UTXO utxo;
54 UTXOIn* in = utxo.add_in();
55 in->set_prev_id(0);
56 in->set_out_idx(0);
57
58 UTXOOut* out = utxo.add_out();
59 out->set_address("1234");
60 out->set_value(234);
61 utxo.set_address("0001");
62
63 std::string signature = utils::ECDSASignString(
64 key.private_key(), utxo.address() + std::to_string(0));
65 utxo.set_sig(signature);
66
67 UTXORequest request;
68 *request.mutable_utxo() = utxo;
69
70 std::string request_str;
71 request.SerializeToString(&request_str);
72
73 auto ret_str = txn_manager.ExecuteData(request_str);
74 EXPECT_TRUE(ret_str != nullptr);
75 }
76}
77
78} // namespace
79} // namespace utxo
80} // namespace resdb
std::string ECDSASignString(const std::string &private_key, const std::string &message)
TEST(NetworkUtilsTest, GetDNSName)