Beispiel #1
0
        public void TryAddConsumptionInPastTest()
        {
            var volatileStore = new VolatilePackStore(1, new[] { 4096 });
            var hash          = GetMockHash().Object;
            var rand          = new Random(2);

            // Create a real lineage
            var cBlocks = new List <CommittedBlock>();

            cBlocks.Add(new CommittedBlock(CommittedBlockId.Genesis, BlockAlias.Genesis, BlockAlias.GenesisParent));
            var firstBlockAlias = new BlockAlias(1, 0);

            cBlocks.Add(new CommittedBlock(
                            CommittedBlockId.ReadFromHex("AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD"),
                            firstBlockAlias, BlockAlias.Genesis));
            var futureBlockAlias = new BlockAlias(2, 0);

            cBlocks.Add(new CommittedBlock(
                            CommittedBlockId.ReadFromHex("AAAABBBBBBBBCCCCCCCCDDDDDDDDAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDAAAA"),
                            futureBlockAlias, firstBlockAlias));

            var realLineage = new Lineage(cBlocks, new List <UncommittedBlock>(), 100);

            var sozu = GetSozuTable(volatileStore, hash);

            var coin1 = GetCoin(rand);

            // The next two commands will work because the fact that a block is uncommitted is not verified anymore.
            // If this test is moved into the ICoinStore at any point, adding a previous consumption should fail
            // already because a 'previous' block always has to be committed.
            var ret = sozu.AddProduction(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, false, coin1.Payload,
                                         futureBlockAlias,
                                         realLineage);

            Assert.Equal(CoinChangeStatus.Success, ret);

            var cons = sozu.AddConsumption(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, firstBlockAlias,
                                           realLineage);

            Assert.Equal(CoinChangeStatus.InvalidContext, cons);
        }
Beispiel #2
0
        public void TryGetCoinInFutureTest()
        {
            var volatileStore = new VolatilePackStore(1, new[] { 4096 });
            var hash          = GetMockHash().Object;
            var rand          = new Random(2);

            // Create a real lineage. It doesn't matter if all blocks are committed because we are just reading.
            var cBlocks = new List <CommittedBlock>();

            cBlocks.Add(new CommittedBlock(CommittedBlockId.Genesis, BlockAlias.Genesis, BlockAlias.GenesisParent));
            var firstBlockAlias = new BlockAlias(1, 0);

            cBlocks.Add(new CommittedBlock(
                            CommittedBlockId.ReadFromHex("AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD"),
                            firstBlockAlias, BlockAlias.Genesis));
            var futureBlockAlias = new BlockAlias(2, 0);

            cBlocks.Add(new CommittedBlock(
                            CommittedBlockId.ReadFromHex("AAAABBBBBBBBCCCCCCCCDDDDDDDDAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDAAAA"),
                            futureBlockAlias, firstBlockAlias));

            var realLineage = new Lineage(cBlocks, new List <UncommittedBlock>(), 100);

            var sozu = GetSozuTable(volatileStore, hash);

            var coin1 = GetCoin(rand);

            var ret = sozu.AddProduction(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, false, coin1.Payload,
                                         futureBlockAlias,
                                         realLineage);

            Assert.Equal(CoinChangeStatus.Success, ret);

            var read = sozu.TryGet(hash.Hash(ref coin1.Outpoint), ref coin1.Outpoint, firstBlockAlias,
                                   realLineage, out var coin, out var prod, out var cons);

            Assert.False(read);
        }
Beispiel #3
0
        private ILineage MakeLineage()
        {
            var blockId1   = CommittedBlockId.ReadFromHex("0000000000000000000000000000000000000000000000000000000000AAA333");
            var commBlock1 = new CommittedBlock(blockId1, BlockAlias.Genesis, BlockAlias.GenesisParent);
            var blockId2   = CommittedBlockId.ReadFromHex("0000000000000000000000000000000000000000000000000000000000BBB444");
            var commBlock2 = new CommittedBlock(blockId2, new BlockAlias(2), BlockAlias.Genesis);
            var blockId3   = CommittedBlockId.ReadFromHex("0000000000000000000000000000000000000000000000000000000000CCC555");
            var commBlock3 = new CommittedBlock(blockId3, new BlockAlias(3), new BlockAlias(2));

            var uncommBlock = new UncommittedBlock(UncommittedBlockId.Create(), new BlockAlias(4), new BlockAlias(3));

            var committedBlocks = new List <CommittedBlock>();

            committedBlocks.Add(commBlock1);
            committedBlocks.Add(commBlock2);
            committedBlocks.Add(commBlock3);

            var uncommittedBlocks = new List <UncommittedBlock>();

            uncommittedBlocks.Add(uncommBlock);

            return(new Lineage(committedBlocks, uncommittedBlocks, 100));
        }