MCPcopy Create free account
hub / github.com/ElementsProject/elements / AddTx

Function AddTx

src/wallet/test/wallet_tests.cpp:366–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366static 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.

Callers 6

BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_FIXTURE_TEST_CASEFunction · 0.85
ComplexMemPoolFunction · 0.85
MempoolCheckFunction · 0.85
RpcMempoolFunction · 0.85
MempoolEvictionFunction · 0.85

Calls 4

SetMockTimeFunction · 0.85
GetRandHashFunction · 0.85
AddToWalletMethod · 0.80
MakeTransactionRefFunction · 0.50

Tested by

no test coverage detected