Repository navigation
Expand file tree
/
Copy pathSignerTests.cpp
More file actions
65 lines (54 loc) · 2.5 KB
/
Copy pathSignerTests.cpp
File metadata and controls
65 lines (54 loc) · 2.5 KB
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
// Copyright © 2017-2020 Trust Wallet.
//
// This file is part of Trust. The full Trust copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
#include "HexCoding.h"
#include "PrivateKey.h"
#include <gtest/gtest.h>
#include "NULS/Signer.h"
using namespace TW;
using namespace TW::NULS;
inline auto makeInput(std::string priKey, std::string addressFrom, std::string addressTo,
uint256_t amount, uint32_t chainId, uint32_t assetId, std::string nonce, std::string remark,
uint256_t balance) {
Proto::SigningInput input;
Data key = parse_hex(priKey);
std::string keyStr;
keyStr.insert(keyStr.begin(), key.begin(), key.end());
input.set_private_key(keyStr);
input.set_from(addressFrom);
input.set_to(addressTo);
Data amountData = store(amount);
std::string amountStr;
amountStr.insert(amountStr.begin(), amountData.begin(), amountData.end());
input.set_amount(amountStr);
input.set_chain_id(chainId);
input.set_idassets_id(assetId);
input.set_nonce(nonce);
input.set_remark(remark);
Data balanceData = store(balance);
std::string balanceStr;
balanceStr.insert(balanceStr.begin(), balanceData.begin(), balanceData.end());
input.set_balance(balanceStr);
input.set_timestamp(0x5d8885f8);
return input;
}
TEST(NULSSigner, Sign) {
auto input = makeInput("9ce21dad67e0f0af2599b41b515a7f7018059418bab892a7b68f283d489abc4b",
"NULSd6Hgj7ZoVgsPN9ybB4C1N2TbvkgLc8Z9H", "NULSd6Hgied7ym6qMEfVzZanMaa9qeqA6TZSe",
10000000, 1, 1, "0000000000000000", "", 100000000);
auto signer = Signer(input);
Data signature = signer.sign();
std::string signedTransaction = hex(signature);
ASSERT_EQ(
signedTransaction,
"0200f885885d00008c0117010001f7ec6473df12e751d64cf20a8baa7edd50810f8101000100201d9a"
"0000000000000000000000000000000000000000000000000000000000080000000000000000000117"
"010001f05e7878971f3374515eabb6f16d75219d887312010001008096980000000000000000000000"
"0000000000000000000000000000000000000000000000000000692103958b790c331954ed367d37ba"
"c901de5c2f06ac8368b37d7bd6cd5ae143c1d7e3463044022028019c0099e2233c7adb84bb03a9a566"
"6ece4a5b65a026a090fa460f3679654702204df0fcb8762b5944b3aba033fa1a287ccb098150035dd8"
"b66f52dc58d3d0843a"
);
}