forked from LedgerHQ/lib-ledger-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fixture for xrp and add test for transaction build
- Loading branch information
1 parent
fe71360
commit ed2bd8c
Showing
14 changed files
with
384 additions
and
22 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This file was GENERATED by command: | ||
// generate_fixtures.py | ||
// DO NOT EDIT BY HAND!!! | ||
#include "xrp_fixtures.h" | ||
|
||
namespace ledger { | ||
namespace testing { | ||
namespace xrp { | ||
core::api::AccountCreationInfo XPUB_INFO( | ||
0, {"xrp"}, {"44'/144'/0'"}, | ||
{ledger::core::hex::toByteArray("024819f9d4bd29318226e3c807cdd2da84161abaf5619c5d2bbfe5be63c74cc9ed")} , {ledger::core::hex::toByteArray("b4f8427e7e19f284dfe7b99f107c55d00b3eae56df9569f0c4d56722742a5d71")} | ||
); | ||
std::shared_ptr<core::RippleLikeAccount> inflate(const std::shared_ptr<core::WalletPool>& pool, const std::shared_ptr<core::AbstractWallet>& wallet) { | ||
auto account = std::dynamic_pointer_cast<core::RippleLikeAccount>(wait(wallet->newAccountWithInfo(XPUB_INFO))); | ||
soci::session sql(pool->getDatabaseSessionPool()->getPool()); | ||
sql.begin(); account->putTransaction(sql, *core::JSONUtils::parse<core::RippleLikeTransactionParser>(TX_1)); | ||
sql.commit(); | ||
return account; | ||
} | ||
const std::string TX_1 = "{\"status\": \"success\", \"Account\": \"rsvAf4P8Tx6tBUdWPNesMngXDmbZ2LMVF8\", \"Fee\": \"10\", \"hash\": \"AF4BB95DE86A640B90B2AF3C696EF26EFE7DD71864CC959D8030B448DD48E756\", \"ledger_index\": 44196232, \"LastLedgerSequence\": 44196239, \"Sequence\": 1, \"SigningPubKey\": \"0215A9EE08A4B4747E27F348365F93BEB5897FA7E8776BEDAE2CB56917DCDBBF2F\", \"Destination\": \"rMspb4Kxa3EwdF4uN5TMqhHfsAkBit6w7k\", \"date\": 600017851, \"Amount\": \"22000000\", \"meta\": {\"TransactionResult\": \"tesSUCCESS\", \"delivered_amount\": \"22000000\", \"TransactionIndex\": 1, \"AffectedNodes\": [{\"CreatedNode\": {\"NewFields\": {\"Account\": \"rMspb4Kxa3EwdF4uN5TMqhHfsAkBit6w7k\", \"Balance\": \"22000000\", \"Sequence\": 1}, \"LedgerEntryType\": \"AccountRoot\", \"LedgerIndex\": \"5AF22704F03359EC7B35095324F071B04A361CAB5BE44D03122E33143FE9343E\"}}, {\"ModifiedNode\": {\"LedgerEntryType\": \"AccountRoot\", \"PreviousTxnID\": \"B02920CA663943E272886C9216CB779028C82492EE9C4DD73BAA12C3190E9F10\", \"FinalFields\": {\"OwnerCount\": 0, \"Account\": \"rsvAf4P8Tx6tBUdWPNesMngXDmbZ2LMVF8\", \"Balance\": \"35169770\", \"Flags\": 0, \"Sequence\": 2}, \"LedgerIndex\": \"699C329231D8720F61CEC57756413A9967C822CE073FA3C8BEC305FAF1AB363E\", \"PreviousTxnLgrSeq\": 43216867, \"PreviousFields\": {\"Balance\": \"57169780\", \"Sequence\": 1}}}]}, \"Flags\": 2147483648, \"TxnSignature\": \"3045022100F2AB61EC941462D692514BFDDB00BC0D31BA7DA66981193E67A04E90578C18B1022064A2375ECB5A68C22EE3038B783BE6A9E1F2C882A8E8BBEE43C4CFA93B536926\", \"inLedger\": 44196232, \"validated\": true, \"TransactionType\": \"Payment\"}"; | ||
} | ||
} | ||
} |
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,44 @@ | ||
// This file was GENERATED by command: | ||
// generate_fixtures.py | ||
// DO NOT EDIT BY HAND!!! | ||
#ifndef LEDGER_FIXTURES_XRP | ||
#define LEDGER_FIXTURES_XRP | ||
#include <gtest/gtest.h> | ||
#include <async/QtThreadDispatcher.hpp> | ||
#include <src/database/DatabaseSessionPool.hpp> | ||
#include <NativePathResolver.hpp> | ||
#include <unordered_set> | ||
#include <src/wallet/pool/WalletPool.hpp> | ||
#include <CoutLogPrinter.hpp> | ||
#include <src/api/DynamicObject.hpp> | ||
#include <wallet/common/CurrencyBuilder.hpp> | ||
#include <wallet/ripple/explorers/api/RippleLikeTransactionParser.h> | ||
#include <wallet/ripple/RippleLikeWallet.h> | ||
#include <wallet/ripple/database/RippleLikeTransactionDatabaseHelper.h> | ||
#include <wallet/common/database/AccountDatabaseHelper.h> | ||
#include <wallet/pool/database/PoolDatabaseHelper.hpp> | ||
#include <utils/JSONUtils.h> | ||
#include <async/async_wait.h> | ||
#include <wallet/ripple/RippleLikeAccount.h> | ||
#include <api/RippleLikeOperation.hpp> | ||
#include <api/RippleLikeTransaction.hpp> | ||
#include <api/BigInt.hpp> | ||
#include <net/QtHttpClient.hpp> | ||
#include <events/LambdaEventReceiver.hpp> | ||
#include <soci.h> | ||
#include <utils/hex.h> | ||
#include <api/Account.hpp> | ||
#include <api/RippleLikeAccount.hpp> | ||
|
||
namespace ledger { | ||
namespace testing { | ||
namespace xrp { | ||
extern core::api::AccountCreationInfo XPUB_INFO; | ||
extern const std::string TX_1; | ||
|
||
std::shared_ptr<core::RippleLikeAccount> inflate(const std::shared_ptr<core::WalletPool>& pool, const std::shared_ptr<core::AbstractWallet>& wallet); | ||
} | ||
} | ||
} | ||
|
||
#endif // LEDGER_FIXTURES_XRP |
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
103 changes: 103 additions & 0 deletions
103
core/test/integration/transactions/ripple_transaction_tests.cpp
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,103 @@ | ||
/* | ||
* | ||
* ripple_transaction_tests | ||
* | ||
* Created by El Khalil Bellakrid on 14/07/2018. | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2018 Ledger | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "../BaseFixture.h" | ||
#include "../../fixtures/xrp_fixtures.h" | ||
#include <api/KeychainEngines.hpp> | ||
#include "transaction_test_helper.h" | ||
#include <utils/hex.h> | ||
#include <utils/DateUtils.hpp> | ||
#include <wallet/ripple/database/RippleLikeAccountDatabaseHelper.h> | ||
#include <wallet/ripple/api_impl/RippleLikeTransactionApi.h> | ||
#include <wallet/currencies.hpp> | ||
#include <iostream> | ||
using namespace std; | ||
|
||
struct RippleMakeTransaction : public RippleMakeBaseTransaction { | ||
void SetUpConfig() override { | ||
auto configuration = DynamicObject::newInstance(); | ||
testData.configuration = configuration; | ||
testData.walletName = "my_wallet"; | ||
testData.currencyName = "ripple"; | ||
testData.inflate_xrp = ledger::testing::xrp::inflate; | ||
} | ||
}; | ||
|
||
TEST_F(RippleMakeTransaction, CreateTx) { | ||
auto builder = tx_builder(); | ||
auto balance = wait(account->getBalance()); | ||
auto fromDate = "2018-01-01T13:38:23Z"; | ||
auto toDate = DateUtils::toJSON(DateUtils::now()); | ||
auto balanceHistory = wait(account->getBalanceHistory(fromDate, toDate, api::TimePeriod::MONTH)); | ||
|
||
EXPECT_EQ(balanceHistory[balanceHistory.size() - 1]->toLong(), balance->toLong()); | ||
|
||
builder->setFees(api::Amount::fromLong(currency, 200000)); | ||
builder->sendToAddress(api::Amount::fromLong(currency, 200000), "rMspb4Kxa3EwdF4uN5TMqhHfsAkBit6w7k"); | ||
auto f = builder->build(); | ||
auto tx = ::wait(f); | ||
auto serializedTx = tx->serialize(); | ||
auto parsedTx = RippleLikeTransactionBuilder::parseRawUnsignedTransaction(wallet->getCurrency(), serializedTx); | ||
auto serializedParsedTx = parsedTx->serialize(); | ||
EXPECT_EQ(serializedTx, serializedParsedTx); | ||
|
||
auto date = "2000-03-27T09:10:22Z"; | ||
auto formatedDate = DateUtils::fromJSON(date); | ||
|
||
//Delete account | ||
auto code = wait(wallet->eraseDataSince(formatedDate)); | ||
EXPECT_EQ(code, api::ErrorCode::FUTURE_WAS_SUCCESSFULL); | ||
|
||
//Check if account was successfully deleted | ||
auto newAccountCount = wait(wallet->getAccountCount()); | ||
EXPECT_EQ(newAccountCount, 0); | ||
{ | ||
soci::session sql(pool->getDatabaseSessionPool()->getPool()); | ||
RippleLikeAccountDatabaseEntry entry; | ||
auto result = RippleLikeAccountDatabaseHelper::queryAccount(sql, account->getAccountUid(), entry); | ||
EXPECT_EQ(result, false); | ||
} | ||
|
||
//Delete wallet | ||
auto walletCode = wait(pool->eraseDataSince(formatedDate)); | ||
EXPECT_EQ(walletCode, api::ErrorCode::FUTURE_WAS_SUCCESSFULL); | ||
|
||
//Check if wallet was successfully deleted | ||
auto walletCount = wait(pool->getWalletCount()); | ||
EXPECT_EQ(walletCount, 0); | ||
|
||
} | ||
|
||
TEST_F(RippleMakeTransaction, ParseUnsignedRawTransaction) { | ||
//Tx hash 4858a0a3d5f1de0c0f5729f25c3501bda946093aed07f842e53a90ac65d66f70 | ||
auto strTx = "E800850165A0BC0083030D4094A49386FFF4E0DD767B145E75D92F7FBA8854553E8301E0F380018080"; | ||
auto tx = api::RippleLikeTransactionBuilder::parseRawUnsignedTransaction(ledger::core::currencies::ETHEREUM, hex::toByteArray(strTx)); | ||
EXPECT_EQ(hex::toString(tx->serialize()), strTx); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
python generate_xrp_fixtures.py "xrp" "rMspb4Kxa3EwdF4uN5TMqhHfsAkBit6w7k" "024819f9d4bd29318226e3c807cdd2da84161abaf5619c5d2bbfe5be63c74cc9ed" "b4f8427e7e19f284dfe7b99f107c55d00b3eae56df9569f0c4d56722742a5d71" |
Oops, something went wrong.