From dc2ba647f471d34cf1656373333b3db83e830a9d Mon Sep 17 00:00:00 2001 From: Aleksandr Starun Date: Fri, 19 Jul 2019 16:49:01 +0300 Subject: [PATCH] swap: fixed validation of subtransactions --- wallet/swaps/swap_transaction.cpp | 2 ++ wallet/unittests/swap_test.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wallet/swaps/swap_transaction.cpp b/wallet/swaps/swap_transaction.cpp index 27a0819e2..6f678104a 100644 --- a/wallet/swaps/swap_transaction.cpp +++ b/wallet/swaps/swap_transaction.cpp @@ -781,6 +781,7 @@ namespace beam::wallet auto transaction = lockTxBuilder->CreateTransaction(); TxBase::Context::Params pars; TxBase::Context context(pars); + context.m_Height.m_Min = lockTxBuilder->GetMinHeight(); if (!transaction->IsValid(context)) { OnSubTxFailed(TxFailureReason::InvalidTransaction, SubTxIndex::BEAM_LOCK_TX, true); @@ -931,6 +932,7 @@ namespace beam::wallet auto transaction = builder.CreateTransaction(); TxBase::Context::Params pars; TxBase::Context context(pars); + context.m_Height.m_Min = builder.GetMinHeight(); if (!transaction->IsValid(context)) { OnSubTxFailed(TxFailureReason::InvalidTransaction, subTxID, true); diff --git a/wallet/unittests/swap_test.cpp b/wallet/unittests/swap_test.cpp index 49f8ae5d6..fd47d380a 100644 --- a/wallet/unittests/swap_test.cpp +++ b/wallet/unittests/swap_test.cpp @@ -127,7 +127,7 @@ namespace } } -void TestSwapTransaction(bool isBeamOwnerStart) +void TestSwapTransaction(bool isBeamOwnerStart, beam::Height fork1Height) { cout << "\nTesting atomic swap transaction...\n"; @@ -181,7 +181,7 @@ void TestSwapTransaction(bool isBeamOwnerStart) NodeObserver observer([&]() { auto cursor = node.get_Processor().m_Cursor; - if (cursor.m_Sid.m_Height == 5) + if (cursor.m_Sid.m_Height == fork1Height + 5) { if (isBeamOwnerStart) { @@ -747,9 +747,11 @@ int main() auto logger = beam::Logger::create(logLevel, logLevel); Rules::get().FakePoW = true; Rules::get().UpdateChecksum(); + beam::Height fork1Height = 10; + Rules::get().pForks[1].m_Height = fork1Height; - TestSwapTransaction(true); - TestSwapTransaction(false); + TestSwapTransaction(true, fork1Height); + TestSwapTransaction(false, fork1Height); TestSwapTransactionWithoutChange(true); TestSwapBTCRefundTransaction();