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); }
protected override void BeforeReturn() { base.BeforeReturn(); if (TestObjectInternal.IsSigned) { TestObjectInternal.Hash = TestObjectInternal.CalculateHash(); } }
protected override void BeforeReturn() { if (!_doNotCalculateHash) { TestObjectInternal.Hash = TestObjectInternal.CalculateHash(); } base.BeforeReturn(); }
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); }
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); }
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); }
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); }
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); }
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); }
public AccountBuilder WithNonce(UInt256 nonce) { TestObjectInternal = TestObjectInternal.WithChangedNonce(nonce); return(this); }
public BlockBuilder WithOmmers(params Block[] ommers) { TestObjectInternal = TestObjectInternal.WithReplacedBody( TestObjectInternal.Body.WithChangedOmmers(ommers.Select(o => o.Header).ToArray())); return(this); }
protected override void BeforeReturn() { TestObjectInternal.ValidateSuggestedBlock(Arg.Any <Block>()).Returns(_alwaysTrue); TestObjectInternal.ValidateProcessedBlock(Arg.Any <Block>(), Arg.Any <Block>()).Returns(_alwaysTrue); base.BeforeReturn(); }
public BlockBuilder WithHeader(BlockHeader header) { TestObjectInternal = TestObjectInternal.WithReplacedHeader(header); return(this); }
public BlockBuilder WithOmmers(params BlockHeader[] ommers) { TestObjectInternal = TestObjectInternal.WithReplacedBody( TestObjectInternal.Body.WithChangedOmmers(ommers)); return(this); }
public BlockBuilder WithUncles(params Block[] uncles) { TestObjectInternal = TestObjectInternal.WithReplacedBody( TestObjectInternal.Body.WithChangedUncles(uncles.Select(o => o.Header).ToArray())); return(this); }
public BlockBuilder WithUncles(params BlockHeader[] uncles) { TestObjectInternal = TestObjectInternal.WithReplacedBody( TestObjectInternal.Body.WithChangedUncles(uncles)); return(this); }
protected override void BeforeReturn() { TestObjectInternal.Validate(Arg.Any <BlockHeader>()).Returns(_alwaysTrue); base.BeforeReturn(); }
public AccountBuilder WithStorageRoot(Keccak storageRoot) { TestObjectInternal = TestObjectInternal.WithChangedStorageRoot(storageRoot); return(this); }
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(); }
public AccountBuilder WithBalance(UInt256 balance) { TestObjectInternal = TestObjectInternal.WithChangedBalance(balance); return(this); }