-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sdk.cpp
More file actions
62 lines (49 loc) · 2.52 KB
/
test_sdk.cpp
File metadata and controls
62 lines (49 loc) · 2.52 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
#include <iostream>
#include <epicchaincpp/epicchaincpp.hpp>
using namespace epicchaincpp;
int main() {
std::cout << "EpicChain C++ SDK Test" << std::endl;
std::cout << "=================" << std::endl;
// Test 1: Generate a new key pair
std::cout << "\n1. Generating new key pair..." << std::endl;
ECKeyPair keyPair = ECKeyPair::generate();
std::cout << " Address: " << keyPair.getAddress() << std::endl;
std::cout << " WIF: " << keyPair.exportAsWIF() << std::endl;
// Test 2: Create a wallet
std::cout << "\n2. Creating wallet..." << std::endl;
auto wallet = std::make_shared<Wallet>("TestWallet", "1.0");
auto account = wallet->createAccount("Test Account");
std::cout << " Account created: " << account->getAddress() << std::endl;
// Test 3: Test hashing
std::cout << "\n3. Testing hash functions..." << std::endl;
std::string message = "Hello, Neo!";
Bytes messageBytes(message.begin(), message.end());
Bytes hash = HashUtils::sha256(messageBytes);
std::cout << " SHA256 of '" << message << "': " << ByteUtils::toHex(hash) << std::endl;
// Test 4: Create a transaction
std::cout << "\n4. Creating transaction..." << std::endl;
auto tx = std::make_shared<Transaction>();
tx->setNonce(12345);
tx->setSystemFee(1000000);
tx->setNetworkFee(500000);
tx->setValidUntilBlock(1000);
Hash256 txHash = tx->getHash();
std::cout << " Transaction hash: " << txHash.toString() << std::endl;
// Test 5: Sign a message
std::cout << "\n5. Signing message..." << std::endl;
Bytes msgHash = HashUtils::sha256(messageBytes);
auto signature = keyPair.sign(msgHash);
std::cout << " Signature: " << signature->toHex() << std::endl;
bool valid = keyPair.getPublicKey()->verify(msgHash, *signature);
std::cout << " Signature valid: " << (valid ? "true" : "false") << std::endl;
// Test 6: XEP-2 encryption
std::cout << "\n6. Testing XEP-2 encryption..." << std::endl;
std::string password = "TestPassword123";
std::string xep2 = XEP2::encrypt(keyPair, password);
std::cout << " XEP-2 encrypted: " << xep2 << std::endl;
ECKeyPair decrypted = XEP2::decryptToKeyPair(xep2, password);
std::cout << " Decrypted address: " << decrypted.getAddress() << std::endl;
std::cout << " Addresses match: " << (keyPair.getAddress() == decrypted.getAddress() ? "true" : "false") << std::endl;
std::cout << "\nAll tests completed successfully!" << std::endl;
return 0;
}