public async Task LoadPoolTest_WithGoodTransactions()
        {
            string         fileName   = "mempool.dat";
            var            tx1_parent = new Transaction("0100000001c4fadb806f9679c27c30c11b694523f6ac9614f7a69076b8940082ce636040fb000000006b4830450221009ad4b969a40b95017d133b13f7d465031829731f3b0ae4bcdcb5e393f5e919f902207f33aad2c3af48d6d65aaf5dd15a85a1f588ee3d6f477b2236cda1d81d88c43b012102eb184a906e082db44a95347de64110952b5821c42068a2054947aec4bc60db2fffffffff02685e3e00000000001976a9149ed35c9c42543ec67f9e6d1033e2ac1ac76f86ba88acd33e4500000000001976a9143c88fada9101f660d77feec1dd8db4ee9ea01d6788ac00000000");
            var            tx1        = new Transaction("0100000001055c4c42511f9d05f2fa817c7f023df567f3d501bebec14ddce7c05a9d5fda52000000006b483045022100de552f011768887141b9a767ae184f61aa3743a32aad394ac1e1ec35345415420220070b3d0afd28414f188c966e334e9f7b65e7440538d93bc1d61f82067fcfd3fa012103b47b6ffce08f54be286620a29f45407fedb7b33acfec938551938ec96a1e1b0bffffffff019f053e000000000017a91493e31884769545a237f164aa07b3caef6b62f6b68700000000");
            NodeSettings   settings   = CreateSettings("LoadPoolTest_WithGoodTransactions");
            TxMempool      txMemPool;
            MempoolManager mempoolManager = CreateTestMempool(settings, out txMemPool);
            var            fee            = Money.Satoshis(0.00001m);

            txMemPool.AddUnchecked(tx1_parent.GetHash(), new TxMempoolEntry(tx1_parent, fee, 0, 0.0, 0, tx1_parent.TotalOut + fee, false, 0, null, new PowConsensusOptions()));
            long expectedTx1FeeDelta = 123;
            List <MempoolPersistenceEntry> toSave = new List <MempoolPersistenceEntry>
            {
                new MempoolPersistenceEntry {
                    Tx       = tx1,
                    Time     = 1491948625,
                    FeeDelta = expectedTx1FeeDelta
                },
            };
            MemPoolSaveResult result = (new MempoolPersistence(settings, new LoggerFactory())).Save(toSave, fileName);

            long expectedSize = 2;
            await mempoolManager.LoadPool(fileName);

            long actualSize = await mempoolManager.MempoolSize();

            TxMempoolEntry actualEntry        = txMemPool.MapTx.TryGet(tx1.GetHash());
            long?          actualTx1FeedDelta = actualEntry?.feeDelta;

            Assert.Equal(expectedSize, actualSize);
            Assert.Equal(expectedTx1FeeDelta, actualTx1FeedDelta);
        }
コード例 #2
0
        public void LoadPoolTest_WithBadTransactions()
        {
            int          numTx    = 5;
            string       fileName = "mempool.dat";
            NodeSettings settings = this.CreateSettings("LoadPoolTest_WithBadTransactions");
            IEnumerable <MempoolPersistenceEntry> toSave = this.CreateTestEntries(numTx);
            MempoolManager mempoolManager = CreateTestMempool(settings, out TxMempool unused);

            MemPoolSaveResult result = (new MempoolPersistence(settings, new LoggerFactory())).Save(settings.Network, toSave, fileName);

            mempoolManager.LoadPoolAsync(fileName).GetAwaiter().GetResult();
            long actualSize = mempoolManager.MempoolSize().GetAwaiter().GetResult();

            Assert.Equal(0, actualSize);
        }
コード例 #3
0
ファイル: MempoolManagerTest.cs プロジェクト: georgepinca/src
        public async Task AddMempoolEntriesToMempool_WithExpiredTx_PurgesTxAsync()
        {
            MempoolManager manager = this.TxExpiryManager;

            Assert.NotNull(manager);

            long expiryInSeconds = MempoolValidator.DefaultMempoolExpiry * 60 * 60;

            // tx with expiry twice as long as default expiry
            var txs = new List <MempoolPersistenceEntry>
            {
                new MempoolPersistenceEntry
                {
                    Tx   = new Transaction(),
                    Time = manager.DateTimeProvider.GetTime() - expiryInSeconds * 2
                }
            };
            await manager.AddMempoolEntriesToMempoolAsync(txs);

            long entries = await manager.MempoolSize();

            // Should not add it because it's expired
            Assert.Equal(0L, entries);
        }
コード例 #4
0
ファイル: MempoolManagerTest.cs プロジェクト: georgepinca/src
        public async Task AddMempoolEntriesToMempool_WithUnexpiredTx_AddsTxAsync()
        {
            MempoolManager manager = this.TxExpiryManager;

            Assert.NotNull(manager);

            long expiryInSeconds = MempoolValidator.DefaultMempoolExpiry * 60 * 60;

            // tx with expiry half as long as default expiry
            var txs = new List <MempoolPersistenceEntry>
            {
                new MempoolPersistenceEntry
                {
                    Tx   = new Transaction(),
                    Time = manager.DateTimeProvider.GetTime() - expiryInSeconds / 2
                }
            };
            await manager.AddMempoolEntriesToMempoolAsync(txs);

            long entries = await manager.MempoolSize();

            // Not expired so should have been added
            Assert.Equal(1L, entries);
        }