BitSharp.Core.Test.Storage.IChainStateCursorTest.TestTryAddGetRemoveBlockUnmintedTxes C# (CSharp) Method

TestTryAddGetRemoveBlockUnmintedTxes() public method

public TestTryAddGetRemoveBlockUnmintedTxes ( ITestStorageProvider provider ) : void
provider ITestStorageProvider
return void
        public void TestTryAddGetRemoveBlockUnmintedTxes(ITestStorageProvider provider)
        {
            var unmintedTxes0 = ImmutableList.Create(
                new UnmintedTx(txHash: (UInt256)0,
                    prevTxOutputs: ImmutableArray.Create(
                        new PrevTxOutput(0, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(1, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(2, ImmutableArray<byte>.Empty, 0, 0, 0, false))),
                new UnmintedTx(txHash: (UInt256)1,
                    prevTxOutputs: ImmutableArray.Create(
                        new PrevTxOutput(3, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(4, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(5, ImmutableArray<byte>.Empty, 0, 0, 0, false))));

            var unmintedTxes1 = ImmutableList.Create(
                new UnmintedTx(txHash: (UInt256)2,
                    prevTxOutputs: ImmutableArray.Create(
                        new PrevTxOutput(6, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(7, ImmutableArray<byte>.Empty, 0, 0, 0, false))),
                new UnmintedTx(txHash: (UInt256)3,
                    prevTxOutputs: ImmutableArray.Create(
                        new PrevTxOutput(8, ImmutableArray<byte>.Empty, 0, 0, 0, false),
                        new PrevTxOutput(9, ImmutableArray<byte>.Empty, 0, 0, 0, false))));

            using (var storageManager = provider.OpenStorageManager())
            using (var handle = storageManager.OpenChainStateCursor())
            {
                var chainStateCursor = handle.Item;

                // begin transaction
                chainStateCursor.BeginTransaction();

                // verify initial empty state
                IImmutableList<UnmintedTx> actualUnmintedTxes0, actualUnmintedTxes1;
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)0, out actualUnmintedTxes0));
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)1, out actualUnmintedTxes1));

                // add unminted txes 0
                Assert.IsTrue(chainStateCursor.TryAddBlockUnmintedTxes((UInt256)0, unmintedTxes0));

                // verify unminted txes
                Assert.IsTrue(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)0, out actualUnmintedTxes0));
                CollectionAssert.AreEqual(unmintedTxes0.ToList(), actualUnmintedTxes0.ToList());
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)1, out actualUnmintedTxes1));

                // add unminted txes 1
                Assert.IsTrue(chainStateCursor.TryAddBlockUnmintedTxes((UInt256)1, unmintedTxes1));

                // verify unminted txes
                Assert.IsTrue(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)0, out actualUnmintedTxes0));
                CollectionAssert.AreEqual(unmintedTxes0.ToList(), actualUnmintedTxes0.ToList());
                Assert.IsTrue(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)1, out actualUnmintedTxes1));
                CollectionAssert.AreEqual(unmintedTxes1.ToList(), actualUnmintedTxes1.ToList());

                // remove unminted txes 1
                Assert.IsTrue(chainStateCursor.TryRemoveBlockUnmintedTxes((UInt256)1));

                // verify unminted txes
                Assert.IsTrue(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)0, out actualUnmintedTxes0));
                CollectionAssert.AreEqual(unmintedTxes0.ToList(), actualUnmintedTxes0.ToList());
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)1, out actualUnmintedTxes1));

                // remove unminted txes 0
                Assert.IsTrue(chainStateCursor.TryRemoveBlockUnmintedTxes((UInt256)0));

                // verify unminted txes
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)0, out actualUnmintedTxes0));
                Assert.IsFalse(chainStateCursor.TryGetBlockUnmintedTxes((UInt256)1, out actualUnmintedTxes1));
            }
        }

Same methods

IChainStateCursorTest::TestTryAddGetRemoveBlockUnmintedTxes ( ) : void