Exemplo n.º 1
0
        // HACK: [vermorel] Constructor used as the setup of the unit tests, should be refactored.
        public LineageTests()
        {
            var store = new VolatileChainStore();

            //var chain = new SimpleBlockchain();
            store.TryOpenBlock(CommittedBlockId.GenesisParent, out var b0);
            var id = b0.Alias;

            // U(0)
            store.TryCommitBlock(id, CommittedBlockId.Genesis, out _);
            // C(0)
            store.TryOpenBlock(CommittedBlockId.Genesis, out var b1);
            Assert.Equal(_1, b1.Alias);
            // C(0) -> U(1)
            store.TryCommitBlock(_1, _id_1, out _);
            // C(0) -> C(1)
            store.TryOpenBlock(_id_1, out var b2);
            Assert.Equal(_2_0, b2.Alias);
            // C(0) -> C(1) -> U(2)
            store.TryCommitBlock(_2_0, _id_2_0, out _);
            // C(0) -> C(1) -> C(2)
            // Second child for second block
            store.TryOpenBlock(_id_1, out var b21);
            Assert.Equal(_2_1, b21.Alias);
            // C(0) -> C(1) -> C(2)
            //             \-> U(2-1)
            store.TryCommitBlock(_2_1, _id_2_1, out _);
            // C(0) -> C(1) -> C(2)
            //             \-> C(2-1)

            var lineage = (Lineage)store.GetLineage();

            lineage.CoinPruneHeight = _1.BlockHeight;

            _lineage = lineage;
        }
Exemplo n.º 2
0
        // HACK: [vermorel] Constructor used as the setup of the unit tests, should be refactored.
        public LineagePruneTests()
        {
            var store = new VolatileChainStore();

            UncommittedBlock freshBlock;

            store.TryOpenBlock(CommittedBlockId.GenesisParent, out var b0);
            var id = b0.Alias;

            // U(0)
            store.TryCommitBlock(id, CommittedBlockId.Genesis, out _);
            // C(0)

            store.TryOpenBlock(CommittedBlockId.Genesis, out freshBlock);
            Assert.Equal(_1, freshBlock.Alias);
            // C(0) -> U(1)
            store.TryCommitBlock(_1, _id_1, out _);
            // C(0) -> C(1)
            store.TryOpenBlock(_id_1, out freshBlock);
            Assert.Equal(_2, freshBlock.Alias);
            // C(0) -> C(1) -> U(2)
            store.TryCommitBlock(_2, _id_2, out _);
            // C(0) -> C(1) -> C(2)
            // Second child for second block
            store.TryOpenBlock(_id_1, out freshBlock);
            Assert.Equal(_2_1, freshBlock.Alias);
            // C(0) -> C(1) -> C(2)
            //             \-> U(2-1)
            store.TryCommitBlock(_2_1, _id_2_1, out _);
            // C(0) -> C(1) -> C(2)
            //             \-> C(2-1)
            store.TryOpenBlock(_id_2, out freshBlock);
            Assert.Equal(_3, freshBlock.Alias);
            store.TryCommitBlock(_3, _id_3, out _);

            store.TryOpenBlock(_id_2_1, out freshBlock);
            Assert.Equal(_3_1, freshBlock.Alias);
            store.TryCommitBlock(_3_1, _id_3_1, out _);
            // C(0) -> C(1) -> C(2)   -> C(3)
            //             \-> C(2-1) -> C(3-1)

            store.TryOpenBlock(_id_3_1, out freshBlock);
            Assert.Equal(_4, freshBlock.Alias);
            store.TryCommitBlock(_4, _id_4, out _);

            store.TryOpenBlock(_id_4, out freshBlock);
            Assert.Equal(_5, freshBlock.Alias);
            store.TryCommitBlock(_5, _id_5, out _);

            store.TryOpenBlock(_id_4, out freshBlock);
            Assert.Equal(_5_1, freshBlock.Alias);
            store.TryCommitBlock(_5_1, _id_5_1, out _);

            // C(0) -> C(1) -> C(2)   -> C(3)
            //             \-> C(2-1) -> C(3-1) -> C(4) -> C(5)
            //                                        \ -> C(5-1)

            // pruning limit is _3_1
            var lineage = (Lineage)store.GetLineage();

            lineage.CoinPruneHeight = _3_1.BlockHeight;

            _lineage = lineage;
        }