Repository navigation
Expand file tree
/
Copy pathSignerTests.cpp
More file actions
45 lines (33 loc) · 1.71 KB
/
Copy pathSignerTests.cpp
File metadata and controls
45 lines (33 loc) · 1.71 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
// 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 "Base64.h"
#include "Base58.h"
#include "proto/NEAR.pb.h"
#include "NEAR/Signer.h"
#include <TrustWalletCore/TWHRP.h>
#include <gtest/gtest.h>
namespace TW::NEAR {
TEST(NEARSigner, SignTx) {
auto publicKey = Base58::bitcoin.decode("Anu7LYDfpLtkP7E16LT9imXF694BdQaa9ufVkQiwTQxC");
auto input = Proto::SigningInput();
input.set_signer_id("test.near");
input.set_nonce(1);
input.set_receiver_id("whatever.near");
input.add_actions();
auto &transfer = *input.mutable_actions(0)->mutable_transfer();
Data deposit(16, 0);
deposit[0] = 1;
transfer.set_deposit(deposit.data(), deposit.size());
auto blockHash = Base58::bitcoin.decode("244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM");
input.set_block_hash(blockHash.data(), blockHash.size());
auto privateKey = Base58::bitcoin.decode("3hoMW1HvnRLSFCLZnvPzWeoGwtdHzke34B2cTHM8rhcbG3TbuLKtShTv3DvyejnXKXKBiV7YPkLeqUHN1ghnqpFv");
input.set_private_key(privateKey.data(), 32);
auto output = Signer::sign(std::move(input));
auto signed_transaction = output.signed_transaction();
auto outputInBase64 = Base64::encode(Data(signed_transaction.begin(), signed_transaction.end()));
ASSERT_EQ(outputInBase64, "CQAAAHRlc3QubmVhcgCRez0mjUtY9/7BsVC9aNab4+5dTMOYVeNBU4Rlu3eGDQEAAAAAAAAADQAAAHdoYXRldmVyLm5lYXIPpHP9JpAd8pa+atxMxN800EDvokNSJLaYaRDmMML+9gEAAAADAQAAAAAAAAAAAAAAAAAAAACWmoMzIYbul1Xkg5MlUlgG4Ymj0tK7S0dg6URD6X4cTyLe7vAFmo6XExAO2m4ZFE2n6KDvflObIHCLodjQIb0B");
}
}