-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#include "TestUtilities.h" | ||
#include "Pactus/Entry.h" | ||
#include "PrivateKey.h" | ||
#include "PublicKey.h" | ||
#include <TrustWalletCore/TWCoinTypeConfiguration.h> | ||
#include <TrustWalletCore/TWAnyAddress.h> | ||
#include <TrustWalletCore/TWHDWallet.h> | ||
#include <gtest/gtest.h> | ||
|
||
namespace TW::Pactus::tests { | ||
|
||
TEST(PactusCoinType, TWCoinType) { | ||
const auto coin = TWCoinTypePactus; | ||
const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); | ||
const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin)); | ||
const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin)); | ||
const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("")); | ||
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); | ||
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("")); | ||
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); | ||
|
||
assertStringsEqual(id, "pactus"); | ||
assertStringsEqual(name, "Pactus"); | ||
assertStringsEqual(symbol, "PAC"); | ||
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 9); | ||
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainPactus); | ||
ASSERT_EQ(TWCoinTypeP2pkhPrefix(coin), 0); | ||
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0); | ||
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0); | ||
assertStringsEqual(txUrl, "https://pacviewer.com/transaction/"); | ||
assertStringsEqual(accUrl, "https://pacviewer.com/address/"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#include "HexCoding.h" | ||
#include "PrivateKey.h" | ||
#include "PublicKey.h" | ||
#include "TestUtilities.h" | ||
#include "TransactionCompiler.h" | ||
#include "proto/Pactus.pb.h" | ||
#include "proto/TransactionCompiler.pb.h" | ||
#include "TestCases.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace TW; | ||
|
||
TEST(PactusCompiler, CompileAndSign) { | ||
// Set up a signing input. | ||
|
||
auto input = TransferTransaction1::createSigningInput(); | ||
|
||
auto inputString = input.SerializeAsString(); | ||
auto inputStrData = TW::Data(inputString.begin(), inputString.end()); | ||
|
||
// Pre-hash the transaction. | ||
auto preImageHashesData = TransactionCompiler::preImageHashes(TWCoinTypePactus, inputStrData); | ||
TxCompiler::Proto::PreSigningOutput preSigningOutput; | ||
preSigningOutput.ParseFromArray(preImageHashesData.data(), static_cast<int>(preImageHashesData.size())); | ||
auto actualDataToSign = data(preSigningOutput.data()); | ||
|
||
EXPECT_EQ(preSigningOutput.error(), Common::Proto::OK); | ||
EXPECT_EQ(hex(actualDataToSign), TransferTransaction1::DATA_TO_SIGN); | ||
|
||
// // Sign the pre-hash data. | ||
|
||
auto privateKey = PrivateKey(parse_hex(TransferTransaction1::PRIVATE_KEY_HEX)); | ||
auto publicKey = privateKey.getPublicKey(TWPublicKeyTypeED25519).bytes; | ||
auto signature = privateKey.sign(actualDataToSign, TWCurveED25519); | ||
EXPECT_EQ(hex(signature), "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"); | ||
|
||
// Compile the transaction. | ||
|
||
auto outputData = TransactionCompiler::compileWithSignatures(TWCoinTypePactus, inputStrData, {signature}, {publicKey}); | ||
TW::Pactus::Proto::SigningOutput output; | ||
output.ParseFromArray(outputData.data(), static_cast<int>(outputData.size())); | ||
|
||
EXPECT_EQ(output.error(), Common::Proto::OK); | ||
ASSERT_EQ(hex(output.signed_transaction_data()), "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa"); | ||
ASSERT_EQ(hex(output.signature()), "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"); | ||
ASSERT_EQ(hex(output.transaction_id()), "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#include "HexCoding.h" | ||
#include "PrivateKey.h" | ||
#include "PublicKey.h" | ||
#include "TestUtilities.h" | ||
#include "TransactionCompiler.h" | ||
#include "proto/Pactus.pb.h" | ||
#include "proto/TransactionCompiler.pb.h" | ||
#include "TestCases.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace TW; | ||
|
||
TEST(PactusSigner, Sign) { | ||
// Set up a signing input. | ||
auto input = TransferTransaction1::createSigningInput(); | ||
|
||
auto privateKey = PrivateKey(parse_hex(TransferTransaction1::PRIVATE_KEY_HEX)); | ||
input.set_private_key(privateKey.bytes.data(), privateKey.bytes.size()); | ||
|
||
TW::Pactus::Proto::SigningOutput output; | ||
ANY_SIGN(input, TWCoinTypePactus); | ||
|
||
EXPECT_EQ(output.error(), Common::Proto::OK); | ||
ASSERT_EQ(hex(output.signed_transaction_data()), "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa"); | ||
ASSERT_EQ(hex(output.signature()), "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"); | ||
ASSERT_EQ(hex(output.transaction_id()), "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#pragma once | ||
|
||
#include "proto/Pactus.pb.h" | ||
#include "proto/TransactionCompiler.pb.h" | ||
|
||
#include <string> | ||
|
||
namespace TransferTransaction1 { | ||
|
||
static TW::Pactus::Proto::SigningInput createSigningInput() { | ||
TW::Pactus::Proto::SigningInput input; | ||
|
||
// Set up the transaction message | ||
TW::Pactus::Proto::TransactionMessage* trx = input.mutable_transaction(); | ||
trx->set_lock_time(0x00030201); | ||
trx->set_fee(1000); | ||
trx->set_memo("test"); | ||
|
||
// Set up the transfer payload | ||
TW::Pactus::Proto::TransferPayload* pld = trx->mutable_transfer(); | ||
pld->set_sender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"); | ||
pld->set_receiver("pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra"); | ||
pld->set_amount(20000); | ||
|
||
return input; | ||
} | ||
|
||
const std::string PRIVATE_KEY_HEX = "4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"; | ||
const std::string PRE_HASH = | ||
"b5e97db07fa0bd0e5598aa3643a9bc6f6693bddc1a9fec9e674a461eaa00b19307968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f3063000000000000000200000000000000000000000000000000000000000000000000000000000000010d6170746f735f6163636f756e74087472616e7366657200022007968dab936c1bad187c60ce4082f307d030d780e91e694ae03aef16aba73f3008e803000000000000fe4d3200000000006400000000000000c2276ada0000000021"; | ||
const std::string SIGNATURE = | ||
"50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09"; | ||
const std::string DATA_TO_SIGN = | ||
"0101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c01"; | ||
const std::string SIGNED_TRANSACTION_DATA = | ||
"000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa"; | ||
const std::string TRANSACTION_ID = "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311"; | ||
} // namespace TransferTransaction1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters