| 364 | } |
| 365 | |
| 366 | static int64_t AddTx(ChainstateManager& chainman, CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64_t blockTime) |
| 367 | { |
| 368 | CMutableTransaction tx; |
| 369 | TxState state = TxStateInactive{}; |
| 370 | tx.nLockTime = lockTime; |
| 371 | SetMockTime(mockTime); |
| 372 | CBlockIndex* block = nullptr; |
| 373 | if (blockTime > 0) { |
| 374 | LOCK(cs_main); |
| 375 | auto inserted = chainman.BlockIndex().emplace(GetRandHash(), new CBlockIndex); |
| 376 | assert(inserted.second); |
| 377 | const uint256& hash = inserted.first->first; |
| 378 | block = inserted.first->second; |
| 379 | block->nTime = blockTime; |
| 380 | block->phashBlock = &hash; |
| 381 | state = TxStateConfirmed{hash, block->nHeight, /*position_in_block=*/0}; |
| 382 | } |
| 383 | return wallet.AddToWallet(MakeTransactionRef(tx), state, [&](CWalletTx& wtx, bool /* new_tx */) { |
| 384 | // Assign wtx.m_state to simplify test and avoid the need to simulate |
| 385 | // reorg events. Without this, AddToWallet asserts false when the same |
| 386 | // transaction is confirmed in different blocks. |
| 387 | wtx.m_state = state; |
| 388 | return true; |
| 389 | })->nTimeSmart; |
| 390 | } |
| 391 | |
| 392 | // Simple test to verify assignment of CWalletTx::nSmartTime value. Could be |
| 393 | // expanded to cover more corner cases of smart time logic. |
no test coverage detected