Skip to content

Commit

Permalink
Fix iOS: change runpaths so we dont need any action from user to run …
Browse files Browse the repository at this point in the history
…app on simulator or real device
  • Loading branch information
KhalilBellakrid committed Oct 22, 2018
1 parent 4d9bc44 commit 59cd848
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 230 deletions.
1 change: 1 addition & 0 deletions .circleci/build_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function command_ios {
cp `pwd`/../lib-ledger-core/tools/build_ios/framework.plist.in `pwd`
cp `pwd`/../lib-ledger-core/tools/build_ios/install_name.sh `pwd`


BUILD_CONFIG="Release"
add_to_cmake_params -G "Xcode" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_TESTS=OFF -DCMAKE_OSX_ARCHITECTURES:STRING=${ARCH} -DCMAKE_MACOSX_BUNDLE:BOOL=ON -DCMAKE_OSX_SYSROOT:STRING=${OSX_SYSROOT} -DCMAKE_TOOLCHAIN_FILE=${POLLY_ROOT}/${TOOLCHAIN_NAME}.cmake
}
Expand Down
1 change: 1 addition & 0 deletions .circleci/deploy_fat_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ lipo -create armv7/ledger-core.framework/ledger-core arm64/ledger-core.framework
mkdir ledger-core.framework
mv ledger-core ledger-core.framework/
cp arm64/ledger-core.framework/Info.plist ledger-core.framework/
install_name_tool -add_rpath "@executable_path/Frameworks/universal" ledger-core.framework/ledger-core
lipo -info ledger-core.framework/ledger-core

echo "======> Deploy from $branchstr branch, version : $LIB_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(UseBackportedModules)
# The project version number.
set(VERSION_MAJOR 1 CACHE STRING "Project major version number.")
set(VERSION_MINOR 1 CACHE STRING "Project minor version number.")
set(VERSION_PATCH 1 CACHE STRING "Project patch version number.")
set(VERSION_PATCH 2 CACHE STRING "Project patch version number.")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branches:
image:
- Visual Studio 2015
environment:
LIB_VERSION: 1.1.1 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
LIB_VERSION: 1.1.2 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
nodejs_version: "9"
appveyor_rdp_password:
secure: jb1LsDmcxCww7tA38S3xSw==
Expand Down
2 changes: 1 addition & 1 deletion core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if(IS_IOS GREATER_EQUAL 0)
add_custom_command(
TARGET ledger-core
POST_BUILD
COMMAND /bin/bash -c "${CMAKE_BINARY_DIR}/install_name.sh \${BUILT_PRODUCTS_DIR}/\${PRODUCT_NAME}.framework/\${PRODUCT_NAME}"
COMMAND /bin/bash -c "${CMAKE_BINARY_DIR}/install_name.sh \${BUILT_PRODUCTS_DIR}/\${PRODUCT_NAME}.framework/\${PRODUCT_NAME} ${CMAKE_OSX_ARCHITECTURES}"
)
add_custom_command(
TARGET ledger-core
Expand Down
196 changes: 94 additions & 102 deletions core/test/integration/synchronization/synchronization_P2SH_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,105 +35,11 @@
#include <api/KeychainEngines.hpp>
#include <utils/DateUtils.hpp>
#include <wallet/bitcoin/database/BitcoinLikeAccountDatabaseHelper.h>

class BitcoinLikeWalletP2SHSynchronization : public BaseFixture {

};

TEST_F(BitcoinLikeWalletP2SHSynchronization, TestNetSynchronization) {
auto pool = newDefaultPool();
{
auto configuration = DynamicObject::newInstance();
configuration->putString(api::Configuration::KEYCHAIN_ENGINE,api::KeychainEngines::BIP49_P2SH);
configuration->putString(api::Configuration::KEYCHAIN_DERIVATION_SCHEME,"49'/<coin_type>'/<account>'/<node>/<address>");
auto wallet = wait(pool->createWallet("testnet_wallet", "bitcoin_testnet",configuration));
std::set<std::string> emittedOperations;
{
auto nextIndex = wait(wallet->getNextAccountIndex());
auto info = wait(wallet->getNextExtendedKeyAccountCreationInfo());
info.extendedKeys.push_back("tpubDCcvqEHx7prGddpWTfEviiew5YLMrrKy4oJbt14teJZenSi6AYMAs2SNXwYXFzkrNYwECSmobwxESxMCrpfqw4gsUt88bcr8iMrJmbb8P2q");
EXPECT_EQ(nextIndex, 0);
auto account = createBitcoinLikeAccount(wallet, nextIndex, info);
auto receiver = make_receiver([&](const std::shared_ptr<api::Event> &event) {
if (event->getCode() == api::EventCode::NEW_OPERATION) {
auto uid = event->getPayload()->getString(
api::Account::EV_NEW_OP_UID).value();
EXPECT_EQ(emittedOperations.find(uid), emittedOperations.end());
}
});

pool->getEventBus()->subscribe(dispatcher->getMainExecutionContext(),receiver);
receiver.reset();
receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;
EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
dispatcher->stop();
});

account->synchronize()->subscribe(dispatcher->getMainExecutionContext(),receiver);
dispatcher->waitUntilStopped();
}
}
}

TEST_F(BitcoinLikeWalletP2SHSynchronization, EraseDataSinceAfterSynchronization) {
auto pool = newDefaultPool();
{
//Set configuration
auto configuration = DynamicObject::newInstance();
configuration->putString(api::Configuration::KEYCHAIN_ENGINE, api::KeychainEngines::BIP49_P2SH);
configuration->putString(api::Configuration::KEYCHAIN_DERIVATION_SCHEME,
"49'/<coin_type>'/<account>'/<node>/<address>");
//Create wallet
auto wallet = wait(pool->createWallet("e847815f-488a-4301-b67c-378a5e9c8a63", "bitcoin_testnet", configuration));
//Create account
auto account = createBitcoinLikeAccount(wallet, 0, P2SH_XPUB_INFO);
//Sync account
auto bus = account->synchronize();
auto receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;

EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
dispatcher->stop();
});
bus->subscribe(dispatcher->getMainExecutionContext(),receiver);
dispatcher->waitUntilStopped();

auto accountCount = wait(wallet->getAccountCount());
EXPECT_EQ(accountCount, 1);
auto accountFromWallet = wait(wallet->getAccount(0));
EXPECT_EQ(account, accountFromWallet);

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());
BitcoinLikeAccountDatabaseEntry entry;
auto result = BitcoinLikeAccountDatabaseHelper::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(BitcoinLikeWalletP2SHSynchronization, MediumXpubSynchronization) {
auto pool = newDefaultPool();
{
Expand Down Expand Up @@ -251,15 +157,101 @@ TEST_F(BitcoinLikeWalletP2SHSynchronization, SynchronizeFromLastBlock) {
};

auto b1 = synchronize(true);
/*
* TODO: Investigate later: this second synchro is OK for this test,
* but for some reason it is affecting following tests (in this case synchronization_tests.cpp)
* making them fail
*/
//auto b2 = synchronize(false);
//EXPECT_NE(b1, b2);
auto b2 = synchronize(false);
EXPECT_NE(b1, b2);
}
}

TEST_F(BitcoinLikeWalletP2SHSynchronization, EraseDataSinceAfterSynchronization) {
auto pool = newDefaultPool();
{
//Set configuration
auto configuration = DynamicObject::newInstance();
configuration->putString(api::Configuration::KEYCHAIN_ENGINE, api::KeychainEngines::BIP49_P2SH);
configuration->putString(api::Configuration::KEYCHAIN_DERIVATION_SCHEME,
"49'/<coin_type>'/<account>'/<node>/<address>");
//Create wallet
auto wallet = wait(pool->createWallet("e847815f-488a-4301-b67c-378a5e9c8a63", "bitcoin_testnet", configuration));
//Create account
auto account = createBitcoinLikeAccount(wallet, 0, P2SH_XPUB_INFO);
//Sync account
auto bus = account->synchronize();
auto receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;

EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
dispatcher->stop();
});
bus->subscribe(dispatcher->getMainExecutionContext(),receiver);
dispatcher->waitUntilStopped();

auto accountCount = wait(wallet->getAccountCount());
EXPECT_EQ(accountCount, 1);
auto accountFromWallet = wait(wallet->getAccount(0));
EXPECT_EQ(account, accountFromWallet);

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());
BitcoinLikeAccountDatabaseEntry entry;
auto result = BitcoinLikeAccountDatabaseHelper::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(BitcoinLikeWalletP2SHSynchronization, TestNetSynchronization) {
auto pool = newDefaultPool();
{
auto configuration = DynamicObject::newInstance();
configuration->putString(api::Configuration::KEYCHAIN_ENGINE,api::KeychainEngines::BIP49_P2SH);
configuration->putString(api::Configuration::KEYCHAIN_DERIVATION_SCHEME,"49'/<coin_type>'/<account>'/<node>/<address>");
auto wallet = wait(pool->createWallet("testnet_wallet", "bitcoin_testnet",configuration));
std::set<std::string> emittedOperations;
{
auto nextIndex = wait(wallet->getNextAccountIndex());
auto info = wait(wallet->getNextExtendedKeyAccountCreationInfo());
info.extendedKeys.push_back("tpubDCcvqEHx7prGddpWTfEviiew5YLMrrKy4oJbt14teJZenSi6AYMAs2SNXwYXFzkrNYwECSmobwxESxMCrpfqw4gsUt88bcr8iMrJmbb8P2q");
EXPECT_EQ(nextIndex, 0);
auto account = createBitcoinLikeAccount(wallet, nextIndex, info);
auto receiver = make_receiver([&](const std::shared_ptr<api::Event> &event) {
if (event->getCode() == api::EventCode::NEW_OPERATION) {
auto uid = event->getPayload()->getString(
api::Account::EV_NEW_OP_UID).value();
EXPECT_EQ(emittedOperations.find(uid), emittedOperations.end());
}
});

pool->getEventBus()->subscribe(dispatcher->getMainExecutionContext(),receiver);
receiver.reset();
receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;
EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
dispatcher->stop();
});

account->synchronize()->subscribe(dispatcher->getMainExecutionContext(),receiver);
dispatcher->waitUntilStopped();
}
}
}
108 changes: 51 additions & 57 deletions core/test/integration/synchronization/synchronization_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,6 @@ class BitcoinLikeWalletSynchronization : public BaseFixture {

};

TEST_F(BitcoinLikeWalletSynchronization, TestNetSynchronization) {
auto pool = newDefaultPool();
{
auto wallet = wait(pool->createWallet("e847815f-488a-4301-b67c-378a5e9c8a61", "bitcoin_testnet",
api::DynamicObject::newInstance()));
std::set<std::string> emittedOperations;
{
auto nextIndex = wait(wallet->getNextAccountIndex());
auto info = wait(wallet->getNextExtendedKeyAccountCreationInfo());
info.extendedKeys.push_back("tpubDCJarhe7f951cUufTWeGKh1w6hDgdBcJfvQgyMczbxWvwvLdryxZuchuNK3KmTKXwBNH6Ze6tHGrUqvKGJd1VvSZUhTVx58DrLn9hR16DVr");
EXPECT_EQ(nextIndex, 0);
auto account = createBitcoinLikeAccount(wallet, nextIndex, info);

auto receiver = make_receiver([&](const std::shared_ptr<api::Event> &event) {
if (event->getCode() == api::EventCode::NEW_OPERATION) {
auto uid = event->getPayload()->getString(
api::Account::EV_NEW_OP_UID).value();
EXPECT_EQ(emittedOperations.find(uid), emittedOperations.end());
}
});

pool->getEventBus()->subscribe(dispatcher->getMainExecutionContext(),receiver);

receiver.reset();
receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;
EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
//EXPECT_EQ(event->getCode(),
// api::EventCode::SYNCHRONIZATION_SUCCEED_ON_PREVIOUSLY_EMPTY_ACCOUNT);
auto amount = wait(account->getBalance());
auto ops = wait(std::dynamic_pointer_cast<OperationQuery>(account->queryOperations()->complete())->execute());
std::cout << "Amount: " << amount->toLong() << std::endl;
std::cout << "Ops: " << ops.size() << std::endl;
for (auto& op : ops) {
std::cout << "op: " << op->asBitcoinLikeOperation()->getTransaction()->getHash() << std::endl;
std::cout << " amount: " << op->getAmount()->toLong() << std::endl;
std::cout << " type: " << api::to_string(op->getOperationType()) << std::endl;
}
dispatcher->stop();
});

account->synchronize()->subscribe(dispatcher->getMainExecutionContext(),receiver);

dispatcher->waitUntilStopped();
}
}
}

TEST_F(BitcoinLikeWalletSynchronization, MediumXpubSynchronization) {
auto pool = newDefaultPool();
{
Expand Down Expand Up @@ -190,13 +140,57 @@ TEST_F(BitcoinLikeWalletSynchronization, SynchronizeFromLastBlock) {
return bus;
};
auto b1 = synchronize(true);
/*
* TODO: Investigate later: this second synchro is OK for this test,
* but for some reason it is affecting following tests (in this case bitcoin_P2PKH_transaction_tests.cpp)
* making them fail
*/
//auto b2 = synchronize(false);
//EXPECT_NE(b1, b2);
auto b2 = synchronize(false);
EXPECT_NE(b1, b2);
}
}

TEST_F(BitcoinLikeWalletSynchronization, TestNetSynchronization) {
auto pool = newDefaultPool();
{
auto wallet = wait(pool->createWallet("e847815f-488a-4301-b67c-378a5e9c8a61", "bitcoin_testnet",
api::DynamicObject::newInstance()));
std::set<std::string> emittedOperations;
{
auto nextIndex = wait(wallet->getNextAccountIndex());
auto info = wait(wallet->getNextExtendedKeyAccountCreationInfo());
info.extendedKeys.push_back("tpubDCJarhe7f951cUufTWeGKh1w6hDgdBcJfvQgyMczbxWvwvLdryxZuchuNK3KmTKXwBNH6Ze6tHGrUqvKGJd1VvSZUhTVx58DrLn9hR16DVr");
EXPECT_EQ(nextIndex, 0);
auto account = createBitcoinLikeAccount(wallet, nextIndex, info);

auto receiver = make_receiver([&](const std::shared_ptr<api::Event> &event) {
if (event->getCode() == api::EventCode::NEW_OPERATION) {
auto uid = event->getPayload()->getString(
api::Account::EV_NEW_OP_UID).value();
EXPECT_EQ(emittedOperations.find(uid), emittedOperations.end());
}
});

pool->getEventBus()->subscribe(dispatcher->getMainExecutionContext(),receiver);

receiver.reset();
receiver = make_receiver([=](const std::shared_ptr<api::Event> &event) {
fmt::print("Received event {}\n", api::to_string(event->getCode()));
if (event->getCode() == api::EventCode::SYNCHRONIZATION_STARTED)
return;
EXPECT_NE(event->getCode(), api::EventCode::SYNCHRONIZATION_FAILED);
//EXPECT_EQ(event->getCode(),
// api::EventCode::SYNCHRONIZATION_SUCCEED_ON_PREVIOUSLY_EMPTY_ACCOUNT);
auto amount = wait(account->getBalance());
auto ops = wait(std::dynamic_pointer_cast<OperationQuery>(account->queryOperations()->complete())->execute());
std::cout << "Amount: " << amount->toLong() << std::endl;
std::cout << "Ops: " << ops.size() << std::endl;
for (auto& op : ops) {
std::cout << "op: " << op->asBitcoinLikeOperation()->getTransaction()->getHash() << std::endl;
std::cout << " amount: " << op->getAmount()->toLong() << std::endl;
std::cout << " type: " << api::to_string(op->getOperationType()) << std::endl;
}
dispatcher->stop();
});

account->synchronize()->subscribe(dispatcher->getMainExecutionContext(),receiver);

dispatcher->waitUntilStopped();
}
}
}
Loading

0 comments on commit 59cd848

Please sign in to comment.