Skip to content

Commit

Permalink
swap: fixed validation of subtransactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr-Starun committed Jul 19, 2019
1 parent 04b244a commit dc2ba64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions wallet/swaps/swap_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions wallet/unittests/swap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace
}
}

void TestSwapTransaction(bool isBeamOwnerStart)
void TestSwapTransaction(bool isBeamOwnerStart, beam::Height fork1Height)
{
cout << "\nTesting atomic swap transaction...\n";

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit dc2ba64

Please sign in to comment.