Пример #1
0
        public BlockTreeBuilder WithBlocks(params Block[] blocks)
        {
            int counter = 0;

            if (blocks.Length == 0)
            {
                return(this);
            }

            if (blocks[0].Number != 0)
            {
                throw new ArgumentException("First block does not have block number 0.");
            }

            foreach (Block block in blocks)
            {
                if (block.Number != counter++)
                {
                    throw new ArgumentException("Block numbers are not consecutively increasing.");
                }

                TestObjectInternal.SuggestBlock(block);
                TestObjectInternal.UpdateMainChain(new[] { block }, true);
            }

            return(this);
        }
Пример #2
0
 protected override void BeforeReturn()
 {
     base.BeforeReturn();
     if (TestObjectInternal.IsSigned)
     {
         TestObjectInternal.Hash = TestObjectInternal.CalculateHash();
     }
 }
Пример #3
0
        protected override void BeforeReturn()
        {
            if (!_doNotCalculateHash)
            {
                TestObjectInternal.Hash = TestObjectInternal.CalculateHash();
            }

            base.BeforeReturn();
        }
Пример #4
0
        public BlockBuilder WithTransactions(params Transaction[] transactions)
        {
            TestObjectInternal = TestObjectInternal.WithReplacedBody(
                TestObjectInternal.Body.WithChangedTransactions(transactions));
            TxTrie trie = new(transactions);

            trie.UpdateRootHash();

            TestObjectInternal.Header.TxRoot = trie.RootHash;
            return(this);
        }
Пример #5
0
        public BlockTreeBuilder OfChainLength(int chainLength, int splitVariant = 0)
        {
            Block current = _genesisBlock;

            for (int i = 0; i < chainLength; i++)
            {
                TestObjectInternal.SuggestBlock(current);
                TestObjectInternal.UpdateMainChain(current);
                current = Build.A.Block.WithNumber((ulong)i + 1).WithParent(current).WithDifficulty(BlockHeaderBuilder.DefaultDifficulty - (ulong)splitVariant).TestObject;
            }

            return(this);
        }
Пример #6
0
        public BlockTreeBuilder OfChainLength(int chainLength, int splitBlockNumber = 0, int splitVariant = 0)
        {
            Block previous = _genesisBlock;

            for (int i = 0; i < chainLength; i++)
            {
                TestObjectInternal.SuggestBlock(previous);
                TestObjectInternal.MarkAsProcessed(previous.Hash);
                TestObjectInternal.MoveToMain(previous.Hash);
                previous = Build.A.Block.WithNumber(i + 1).WithParent(previous).WithDifficulty(BlockHeaderBuilder.DefaultDifficulty - splitVariant).TestObject;
            }

            return(this);
        }
Пример #7
0
        public BlockTreeBuilder WithOnlySomeBlocksProcessed(int chainLength, int processedChainLength)
        {
            Block current = _genesisBlock;

            for (int i = 0; i < chainLength; i++)
            {
                TestObjectInternal.SuggestBlock(current);
                if (current.Number < processedChainLength)
                {
                    TestObjectInternal.UpdateMainChain(current);
                }

                current = Build.A.Block.WithNumber(i + 1).WithParent(current).WithDifficulty(BlockHeaderBuilder.DefaultDifficulty).TestObject;
            }

            return(this);
        }
Пример #8
0
        public BlockTreeBuilder OfChainLength(out Block headBlock, int chainLength, int splitVariant = 0, int splitFrom = 0, params Address[] blockBeneficiaries)
        {
            Block current = _genesisBlock;

            headBlock = _genesisBlock;

            bool skipGenesis = TestObjectInternal.Genesis != null;

            for (int i = 0; i < chainLength; i++)
            {
                Address beneficiary = blockBeneficiaries.Length == 0 ? Address.Zero : blockBeneficiaries[i % blockBeneficiaries.Length];
                headBlock = current;
                if (_onlyHeaders)
                {
                    if (!(current.IsGenesis && skipGenesis))
                    {
                        TestObjectInternal.SuggestHeader(current.Header);
                    }

                    Block parent = current;
                    current = CreateBlock(splitVariant, splitFrom, i, parent, beneficiary);
                }
                else
                {
                    if (!(current.IsGenesis && skipGenesis))
                    {
                        AddBlockResult result = TestObjectInternal.SuggestBlock(current);
                        Assert.AreEqual(AddBlockResult.Added, result, $"Adding {current.ToString(Block.Format.Short)} at split variant {splitVariant}");

                        TestObjectInternal.UpdateMainChain(current);
                    }

                    Block parent = current;

                    current = CreateBlock(splitVariant, splitFrom, i, parent, beneficiary);
                }
            }

            return(this);
        }
Пример #9
0
        public BlockTreeBuilder OfChainLength(out Block headBlock, int chainLength, int splitVariant = 0)
        {
            Block current = _genesisBlock;

            headBlock = _genesisBlock;

            bool skipGenesis = TestObjectInternal.Head != null;

            for (int i = 0; i < chainLength; i++)
            {
                headBlock = current;
                if (_onlyHeaders)
                {
                    if (!(current.IsGenesis && skipGenesis))
                    {
                        TestObjectInternal.SuggestHeader(current.Header);
                    }

                    current = Build.A.Block.WithNumber(i + 1).WithParent(current).WithDifficulty(BlockHeaderBuilder.DefaultDifficulty - (ulong)splitVariant).TestObject;
                }
                else
                {
                    if (!(current.IsGenesis && skipGenesis))
                    {
                        AddBlockResult result = TestObjectInternal.SuggestBlock(current);
                        Assert.AreEqual(AddBlockResult.Added, result, $"Adding {current.ToString(Block.Format.Short)} at split variant {splitVariant}");

                        TestObjectInternal.UpdateMainChain(current);
                    }

                    current = Build.A.Block.WithNumber(i + 1).WithParent(current).WithDifficulty(BlockHeaderBuilder.DefaultDifficulty - (ulong)splitVariant).TestObject;
                }
            }

            return(this);
        }
Пример #10
0
 public AccountBuilder WithNonce(UInt256 nonce)
 {
     TestObjectInternal = TestObjectInternal.WithChangedNonce(nonce);
     return(this);
 }
Пример #11
0
 public BlockBuilder WithOmmers(params Block[] ommers)
 {
     TestObjectInternal = TestObjectInternal.WithReplacedBody(
         TestObjectInternal.Body.WithChangedOmmers(ommers.Select(o => o.Header).ToArray()));
     return(this);
 }
Пример #12
0
 protected override void BeforeReturn()
 {
     TestObjectInternal.ValidateSuggestedBlock(Arg.Any <Block>()).Returns(_alwaysTrue);
     TestObjectInternal.ValidateProcessedBlock(Arg.Any <Block>(), Arg.Any <Block>()).Returns(_alwaysTrue);
     base.BeforeReturn();
 }
Пример #13
0
 public BlockBuilder WithHeader(BlockHeader header)
 {
     TestObjectInternal = TestObjectInternal.WithReplacedHeader(header);
     return(this);
 }
Пример #14
0
 public BlockBuilder WithOmmers(params BlockHeader[] ommers)
 {
     TestObjectInternal = TestObjectInternal.WithReplacedBody(
         TestObjectInternal.Body.WithChangedOmmers(ommers));
     return(this);
 }
Пример #15
0
 public BlockBuilder WithUncles(params Block[] uncles)
 {
     TestObjectInternal = TestObjectInternal.WithReplacedBody(
         TestObjectInternal.Body.WithChangedUncles(uncles.Select(o => o.Header).ToArray()));
     return(this);
 }
Пример #16
0
 public BlockBuilder WithUncles(params BlockHeader[] uncles)
 {
     TestObjectInternal = TestObjectInternal.WithReplacedBody(
         TestObjectInternal.Body.WithChangedUncles(uncles));
     return(this);
 }
Пример #17
0
 protected override void BeforeReturn()
 {
     TestObjectInternal.Validate(Arg.Any <BlockHeader>()).Returns(_alwaysTrue);
     base.BeforeReturn();
 }
Пример #18
0
 public AccountBuilder WithStorageRoot(Keccak storageRoot)
 {
     TestObjectInternal = TestObjectInternal.WithChangedStorageRoot(storageRoot);
     return(this);
 }
Пример #19
0
 public AccountBuilder WithCode(byte[] code)
 {
     TestObjectInternal = TestObjectInternal.WithChangedCodeHash(Keccak.Compute(code));
     return(this);
 }
 protected override void BeforeReturn()
 {
     TestObjectInternal.IsWellFormed(Arg.Any <Transaction>(), Arg.Any <IReleaseSpec>()).Returns(_alwaysTrue);
     TestObjectInternal.IsWellFormed(Arg.Any <Transaction>(), Arg.Any <IReleaseSpec>()).Returns(_alwaysTrue);
     base.BeforeReturn();
 }
Пример #21
0
 public AccountBuilder WithBalance(UInt256 balance)
 {
     TestObjectInternal = TestObjectInternal.WithChangedBalance(balance);
     return(this);
 }