예제 #1
0
        public async Task DoesntUpdateAsync(Network network)
        {
            await using var txStore = new AllTransactionStore(PrepareWorkDir(), network);
            await txStore.InitializeAsync(ensureBackwardsCompatibility : false);

            var tx = Common.RandomSmartTransaction();

            Assert.False(txStore.TryUpdate(tx));

            // Assert TryUpdate didn't modify anything.

            Assert.NotNull(txStore.ConfirmedStore);
            Assert.NotNull(txStore.MempoolStore);
            Assert.Empty(txStore.GetTransactions());
            Assert.Empty(txStore.GetTransactionHashes());
            Assert.Empty(txStore.MempoolStore.GetTransactions());
            Assert.Empty(txStore.MempoolStore.GetTransactionHashes());
            Assert.Empty(txStore.ConfirmedStore.GetTransactions());
            Assert.Empty(txStore.ConfirmedStore.GetTransactionHashes());

            uint256 txHash = Common.RandomSmartTransaction().GetHash();

            Assert.False(txStore.Contains(txHash));
            Assert.True(txStore.IsEmpty());
            Assert.False(txStore.TryGetTransaction(txHash, out _));
        }
예제 #2
0
        public async Task ReorgAsync()
        {
            PrepareTestEnv(
                out string dir,
                out Network network,
                out string mempoolFile,
                out string txFile,
                out SmartTransaction uTx1,
                out SmartTransaction uTx2,
                out SmartTransaction uTx3,
                out SmartTransaction _,
                out SmartTransaction cTx2,
                out SmartTransaction cTx3);

            // Duplication is resolved with labels merged.
            var mempoolFileContent = new[]
            {
                uTx1.ToLine(),
                uTx2.ToLine(),
                uTx3.ToLine(),
            };
            var txFileContent = new[]
            {
                cTx2.ToLine(),
                cTx3.ToLine()
            };
            await File.WriteAllLinesAsync(mempoolFile, mempoolFileContent);

            await File.WriteAllLinesAsync(txFile, txFileContent);

            await using var txStore = new AllTransactionStore(dir, network);
            await txStore.InitializeAsync(ensureBackwardsCompatibility : false);

            // Two transactions are in the mempool store and unconfirmed.
            Assert.True(txStore.MempoolStore.TryGetTransaction(uTx1.GetHash(), out SmartTransaction myUnconfirmedTx1));
            Assert.False(myUnconfirmedTx1.Confirmed);
            Assert.True(txStore.MempoolStore.TryGetTransaction(uTx2.GetHash(), out SmartTransaction myUnconfirmedTx2));
            Assert.False(myUnconfirmedTx2.Confirmed);

            // Create the same transaction but now with a Height to make it confirmed.
            const int ReorgedBlockHeight = 34532;
            uint256   reorgedBlockHash   = new uint256(5);

            var tx1Confirmed = new SmartTransaction(uTx1.Transaction, new Height(ReorgedBlockHeight), blockHash: reorgedBlockHash, label: "buz, qux");
            var tx2Confirmed = new SmartTransaction(uTx2.Transaction, new Height(ReorgedBlockHeight), blockHash: reorgedBlockHash, label: "buz, qux");

            Assert.True(txStore.TryUpdate(tx1Confirmed));
            Assert.True(txStore.TryUpdate(tx2Confirmed));

            // Two transactions are in the ConfirmedStore store and confirmed.
            Assert.True(txStore.ConfirmedStore.TryGetTransaction(uTx1.GetHash(), out SmartTransaction mytx1));
            Assert.False(txStore.MempoolStore.TryGetTransaction(uTx1.GetHash(), out _));
            Assert.True(mytx1.Confirmed);
            Assert.True(txStore.ConfirmedStore.TryGetTransaction(uTx2.GetHash(), out SmartTransaction mytx2));
            Assert.False(txStore.MempoolStore.TryGetTransaction(uTx2.GetHash(), out _));
            Assert.True(mytx2.Confirmed);

            // Now reorg.
            txStore.ReleaseToMempoolFromBlock(reorgedBlockHash);

            // Two transactions are in the mempool store and unconfirmed.
            Assert.True(txStore.MempoolStore.TryGetTransaction(uTx1.GetHash(), out SmartTransaction myReorgedTx1));
            Assert.False(txStore.ConfirmedStore.TryGetTransaction(uTx1.GetHash(), out _));
            Assert.False(myReorgedTx1.Confirmed);
            Assert.True(txStore.MempoolStore.TryGetTransaction(uTx2.GetHash(), out SmartTransaction myReorgedTx2));
            Assert.False(txStore.ConfirmedStore.TryGetTransaction(uTx2.GetHash(), out _));
            Assert.False(myReorgedTx2.Confirmed);
        }