public async Task RunAsync_ZeroTransactions_ThrowsBadBlockLengthConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.Block = new Block(); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockSizeRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockLength, exception.ConsensusError); }
public async Task RunAsync_BadBlockWeight_ThrowsBadBlockWeightConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.Block = GenerateBlockWithWeight((this.options.MaxBlockWeight / this.options.WitnessScaleFactor) + 1, TransactionOptions.All); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockSizeRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockWeight, exception.ConsensusError); }
public async Task RunAsync_BlockWithoutTransactions_ThrowsBadCoinbaseMissingConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.BlockToValidate = this.network.CreateBlock(); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <EnsureCoinbaseRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadCoinbaseMissing, exception.ConsensusError); }
/// <summary> /// This helper creates a coin staking block containing a coin staking transaction built according to /// the parameters and with valid first input and output. The block signature is created correctly with the /// private key corresponding to the public key. /// </summary> /// <param name="useCompressedKey">Determines whether the second transaction output will include a compressed /// (versus uncompressed) public key.</param> /// <param name="includeSecondPush">Determines whether the second transaction output will include a small integer /// after the public key.</param> /// <param name="expectFailure">Determines whether we expect failure (versus success).</param> private void ProofOfStakeBlock_CoinStakeTestHelper(bool useCompressedKey, bool includeSecondPush, bool expectFailure) { Block block = KnownNetworks.StratisMain.Consensus.ConsensusFactory.CreateBlock(); // Add a dummy coinbase transaction. block.Transactions.Add(KnownNetworks.StratisMain.CreateTransaction()); // Build a coinstake transaction. Transaction coinStakeTransaction = KnownNetworks.StratisMain.CreateTransaction(); coinStakeTransaction.Inputs.Add(new TxIn() { PrevOut = new OutPoint(new uint256(15), 1), ScriptSig = new Script() }); // First output of coinstake transaction is a special marker. coinStakeTransaction.Outputs.Add(new TxOut(Money.Zero, (IDestination)null)); // Second (unspendable) output. // Depending on the test case use either a compressed public key or an uncompressed public key. var pubKey = useCompressedKey ? this.key.PubKey.Compress() : this.key.PubKey.Decompress(); var opCodes = new List <Op> { OpcodeType.OP_RETURN, Op.GetPushOp(pubKey.ToBytes(true)) }; // Depending on the test case add a second push of some small integer. if (includeSecondPush) { opCodes.Add(Op.GetPushOp(new byte[] { 123 })); } coinStakeTransaction.Outputs.Add(new TxOut(Money.Zero, new Script(opCodes))); // Add the coinstake transaction. block.Transactions.Add(coinStakeTransaction); // Add a signature to the block. ECDSASignature signature = this.key.Sign(block.GetHash()); (block as PosBlock).BlockSignature = new BlockSignature { Signature = signature.ToDER() }; // Execute the PosBlockSignatureRule. this.ruleContext.ValidationContext.BlockToValidate = block; Assert.True(BlockStake.IsProofOfStake(this.ruleContext.ValidationContext.BlockToValidate)); if (expectFailure) { ConsensusErrorException exception = Assert.Throws <ConsensusErrorException>(() => this.consensusRules.RegisterRule <PosBlockSignatureRule>().Run(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockSignature, exception.ConsensusError); return; } this.consensusRules.RegisterRule <PosBlockSignatureRule>().Run(this.ruleContext); }
public async Task RunAsync_ProofOfWorkTooHigh_ThrowsProofOfWorkTooHighConsensusErrorAsync() { this.ruleContext.ValidationContext.ChainedHeader = this.concurrentChain.GetBlock(3); this.SetBlockStake(); this.network.Consensus.LastPOWBlock = 2; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.rule.RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.ProofOfWorkTooHigh, exception.ConsensusError); }
public async Task RunAsync_HeaderVersionBelowMinimalHeaderVersion_ThrowsBadVersionConsensusErrorAsync() { int MinimalHeaderVersion = 7; this.ruleContext.ValidationContext.ChainedHeader = this.concurrentChain.GetBlock(1); this.ruleContext.ValidationContext.ChainedHeader.Header.Version = MinimalHeaderVersion - 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.rule.RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadVersion, exception.ConsensusError); }
public async Task RunAsync_RequiredProofOfWorkNotMetHigher_ThrowsBadDiffBitsConsensusErrorAsync() { this.ruleContext.ConsensusTipHeight = 5; this.ruleContext.NextWorkRequired = new Target(0x1f111115); this.ruleContext.ValidationContext.Block = this.network.CreateBlock(); this.ruleContext.ValidationContext.Block.Header.Bits = new Target(0x1f111116); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockHeaderPowContextualRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadDiffBits, exception.ConsensusError); }
public void RunAsync_HeaderTimestampTooNew_WithoutReducedDrift_ThrowsBlockTimestampTooFarConsensusErrorAsync() { long futureDriftTimestamp = (StratisBugFixPosFutureDriftRule.DriftingBugFixTimestamp - 100); this.dateTimeProvider.Setup(d => d.GetAdjustedTimeAsUnixTimestamp()) .Returns(futureDriftTimestamp); this.ruleContext.ValidationContext.ChainedHeaderToValidate.Header.Time = ((uint)futureDriftTimestamp) + MaxFutureDriftBeforeHardFork + 1; ConsensusErrorException exception = Assert.Throws <ConsensusErrorException>(() => this.consensusRules.RegisterRule <PosFutureDriftRule>().Run(this.ruleContext)); Assert.Equal(ConsensusErrors.BlockTimestampTooFar, exception.ConsensusError); }
public async Task RunAsync_CheckpointViolation_ThrowsCheckpointValidationConsensusErrorsExceptionAsync() { this.ruleContext.ConsensusTipHeight = 1; this.ruleContext.ValidationContext.Block = this.network.CreateBlock(); this.checkpoints.Setup(c => c.CheckHardened(2, this.ruleContext.ValidationContext.Block.GetHash())) .Returns(false); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CheckpointsRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.CheckpointViolation, exception.ConsensusError); }
public async Task RunAsync_BlockSizeAboveMaxBlockBaseSize_ThrowsBadBlockLengthConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.Block = GenerateBlockWithWeight(this.options.MaxBlockBaseSize + 1, TransactionOptions.All); int blockWeight = this.CalculateBlockWeight(this.ruleContext.ValidationContext.Block, TransactionOptions.All); // increase max block weight to be able to hit this if statement this.options.MaxBlockWeight = (blockWeight * 4) + 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockSizeRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockLength, exception.ConsensusError); }
public async Task RunAsync_HeaderTimestampTooNew_WithReducedDrift_ThrowsBlockTimestampTooFarConsensusErrorAsync() { long futureDriftTimestamp = (PosFutureDriftRule.DriftingBugFixTimestamp + 100); this.dateTimeProvider.Setup(d => d.GetAdjustedTimeAsUnixTimestamp()) .Returns(futureDriftTimestamp); this.ruleContext.ValidationContext.Block.Header.Time = (uint)futureDriftTimestamp + MaxFutureDriftAfterHardFork + 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <PosFutureDriftRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BlockTimestampTooFar.Message, exception.ConsensusError.Message); }
public async Task BlockReceived_NotNextBlock_ValidationFailAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); var blockHeaderRule = testContext.CreateRule <BlockHeaderRule>(); var context = new PowRuleContext(new ValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip, testContext.DateTimeProvider.GetTimeOffset()); context.ValidationContext.Block = Network.RegTest.Consensus.ConsensusFactory.CreateBlock(); context.ValidationContext.Block.Header.HashPrevBlock = uint256.Zero; ConsensusErrorException error = await Assert.ThrowsAsync <ConsensusErrorException>(async() => await blockHeaderRule.RunAsync(context)); Assert.Equal(ConsensusErrors.InvalidPrevTip, error.ConsensusError); }
public async Task RunAsync_BestBlockUnAvailable_BadCoinBaseHeight_ThrowsBadCoinbaseHeightConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.Block = new Block(); var transaction = new Transaction(); transaction.Inputs.Add(new TxIn(new Script(Op.GetPushOp(3)))); this.ruleContext.ValidationContext.Block.Transactions.Add(transaction); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CoinbaseHeightRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadCoinbaseHeight, exception.ConsensusError); }
public async Task RunAsync_FirstTransactionIsNotCoinbase_ThrowsBadCoinbaseMissingConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.BlockToValidate = this.network.CreateBlock(); var transaction = this.network.CreateTransaction(); Assert.False(transaction.IsCoinBase); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(transaction); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <EnsureCoinbaseRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadCoinbaseMissing, exception.ConsensusError); }
public async Task RunAsync_TimeTooNew_ThrowsTimeTooNewConsensusErrorAsync() { this.ruleContext.ConsensusTipHeight = 5; this.ruleContext.Time = new DateTime(2016, 12, 31, 10, 0, 0); this.ruleContext.NextWorkRequired = new Target(0x1f111115); this.ruleContext.ValidationContext.Block = this.network.CreateBlock(); this.ruleContext.ValidationContext.Block.Header.Bits = new Target(0x1f111115); this.ruleContext.ValidationContext.Block.Header.BlockTime = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 1)); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockHeaderPowContextualRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.TimeTooNew, exception.ConsensusError); }
public async Task RunAsync_HeaderVersionBelowMinimalHeaderVersion_ThrowsBadVersionConsensusErrorAsync() { var rule = this.CreateRule <StratisHeaderVersionRule>(); int MinimalHeaderVersion = 7; this.ruleContext.ValidationContext.ChainedHeaderToValidate = this.concurrentChain.GetBlock(1); this.ruleContext.ValidationContext.ChainedHeaderToValidate.Header.Version = MinimalHeaderVersion - 1; ConsensusErrorException exception = Assert.Throws <ConsensusErrorException>(() => rule.Run(this.ruleContext)); Assert.Equal(ConsensusErrors.BadVersion, exception.ConsensusError); }
public async Task RunAsync_BadVersionLowerThan2_HeightSameAsBip65_ThrowsBadVersionConsensusErrorAsync() { this.ruleContext.ConsensusTipHeight = this.consensusRules.ConsensusParams.BuriedDeployments[BuriedDeployments.BIP66] - 1; this.ruleContext.Time = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 0)); this.ruleContext.NextWorkRequired = new Target(0x1f111115); this.ruleContext.ValidationContext.Block = this.network.CreateBlock(); this.ruleContext.ValidationContext.Block.Header.Bits = new Target(0x1f111115); this.ruleContext.ValidationContext.Block.Header.BlockTime = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 1)); this.ruleContext.ValidationContext.Block.Header.Version = 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BlockHeaderPowContextualRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadVersion, exception.ConsensusError); }
public async Task RunAsync_SingleTransactionOutputSigOpsCountAboveThresHold_ThrowsBadBlockSigOpsConsensusErrorExceptionAsync() { this.options.MaxBlockSigopsCost = 7; this.options.WitnessScaleFactor = 2; var transaction = new Transaction(); var op = new Op() { Code = OpcodeType.OP_CHECKSIG }; transaction.Outputs.Add(new TxOut(new Money(1), new Script(op, op, op, op))); this.ruleContext.ValidationContext.Block.Transactions.Add(transaction); ConsensusErrorException exception = await Assert.ThrowsAsync<ConsensusErrorException>(() => this.consensusRules.RegisterRule<CheckSigOpsRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockSigOps, exception.ConsensusError); }
public void Run_BadVersionLowerThan2_HeightHigherThanBip34_ThrowsBadVersionConsensusError() { // set height above bip34 this.ruleContext.Time = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 0)); var header = this.network.Consensus.ConsensusFactory.CreateBlockHeader(); header.Bits = new Target(0x1f111115); header.BlockTime = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 1)); header.Version = 1; this.ruleContext.ValidationContext.ChainedHeaderToValidate = new ChainedHeader(header, header.GetHash(), this.consensusRules.ConsensusParams.BuriedDeployments[BuriedDeployments.BIP34]); ConsensusErrorException exception = Assert.Throws <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BitcoinActivationRule>().Run(this.ruleContext)); Assert.Equal(ConsensusErrors.BadVersion, exception.ConsensusError); }
public async Task RunAsync_ProofOfWorkBlock_CheckPow_InValidPow_ThrowsHighHashConsensusErrorExceptionAsync() { Block block = this.network.CreateBlock(); this.ruleContext.ValidationContext = new ValidationContext() { Block = block, ChainedHeader = this.concurrentChain.GetBlock(4) }; this.ruleContext.MinedBlock = false; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CheckDifficultyPowRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.HighHash, exception.ConsensusError); }
public void RunAsync_ProofOfWorkBlockSignatureNotEmpty_ThrowsBadBlockSignatureConsensusErrorException() { this.ruleContext.ValidationContext.BlockToValidate = KnownNetworks.StratisMain.Consensus.ConsensusFactory.CreateBlock(); (this.ruleContext.ValidationContext.BlockToValidate as PosBlock).BlockSignature = new BlockSignature() { Signature = new byte[] { 0x2, 0x3 } }; Assert.True(BlockStake.IsProofOfWork(this.ruleContext.ValidationContext.BlockToValidate)); ConsensusErrorException exception = Assert.Throws <ConsensusErrorException>(() => this.consensusRules.RegisterRule <PosBlockSignatureRule>().Run(this.ruleContext)); Assert.Equal(ConsensusErrors.BadBlockSignature, exception.ConsensusError); }
public async Task RunAsync_ProofOfWorkTooHigh_ThrowsProofOfWorkTooHighConsensusErrorAsync() { var rule = this.CreateRule <PosTimeMaskRule>(); this.SetBlockStake(); this.network.Consensus.LastPOWBlock = 2; this.ruleContext.ValidationContext = new ValidationContext(); this.ruleContext.ValidationContext.BlockToValidate = this.network.Consensus.ConsensusFactory.CreateBlock(); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(this.network.CreateTransaction()); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(this.network.CreateTransaction()); this.ruleContext.ValidationContext.ChainedHeaderToValidate = this.ChainIndexer.GetHeader(3); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => rule.RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.ProofOfWorkTooHigh, exception.ConsensusError); }
public async Task RunAsync_BestBlockUnAvailable_BadCoinBaseHeight_ThrowsBadCoinbaseHeightConsensusErrorExceptionAsync() { Block blockToValidate = this.network.CreateBlock(); this.ruleContext.ValidationContext.BlockToValidate = blockToValidate; this.ruleContext.ValidationContext.ChainedHeaderToValidate = new ChainedHeader(blockToValidate.Header, blockToValidate.Header.GetHash(), 0); var transaction = new Transaction(); transaction.Inputs.Add(new TxIn(new Script(Op.GetPushOp(3)))); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(transaction); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CoinbaseHeightRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadCoinbaseHeight, exception.ConsensusError); }
public async Task RunAsync_TimestampTooNew_WithReducedDrift_ThrowsTimeTooNewConsensusErrorAsync() { this.SetBlockStake(BlockFlag.BLOCK_PROOF_OF_STAKE); this.ruleContext.ValidationContext = new ValidationContext(); this.ruleContext.ValidationContext.Block = this.network.Consensus.ConsensusFactory.CreateBlock(); this.ruleContext.ValidationContext.Block.Transactions.Add(this.network.CreateTransaction()); this.ruleContext.ValidationContext.Block.Transactions[0].Time = (uint)(PosFutureDriftRule.DriftingBugFixTimestamp + 100); this.ruleContext.ValidationContext.ChainedHeader = this.concurrentChain.GetBlock(3); this.network.Consensus.LastPOWBlock = 12500; this.ruleContext.ValidationContext.ChainedHeader.Header.Time = this.ruleContext.ValidationContext.Block.Transactions[0].Time + MaxFutureDriftAfterHardFork + 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.rule.RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.TimeTooNew, exception.ConsensusError); }
public async Task ChecBlockFutureTimestamp_ValidationFailAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); var rule = testContext.CreateRule<HeaderTimeChecksRule>(); RuleContext context = new PowRuleContext(new ValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip, testContext.DateTimeProvider.GetTimeOffset()); context.ValidationContext.Block = TestRulesContextFactory.MineBlock(Network.RegTest, testContext.Chain); context.ValidationContext.ChainedHeader = new ChainedHeader(context.ValidationContext.Block.Header, context.ValidationContext.Block.Header.GetHash(), context.ConsensusTip); context.Time = DateTimeProvider.Default.GetTimeOffset(); // increment the bits. context.ValidationContext.Block.Header.BlockTime = context.Time.AddHours(3); ConsensusErrorException error = await Assert.ThrowsAsync<ConsensusErrorException>(async () => await rule.RunAsync(context)); Assert.Equal(ConsensusErrors.TimeTooNew, error.ConsensusError); }
public async Task RunAsync_ProofOfWorkBlock_TransactionTimestampAfterBlockTimeStamp_ThrowsBlockTimeBeforeTrxConsensusErrorExceptionAsync() { var transaction = this.network.CreateTransaction(); transaction.Outputs.Add(new TxOut(Money.Zero, (IDestination)null)); this.ruleContext.ValidationContext.Block.Transactions.Add(transaction); this.ruleContext.ValidationContext.Block.Header.Time = (uint)1483747200; this.ruleContext.ValidationContext.Block.Transactions[0].Time = (uint)1483747201; Assert.True(BlockStake.IsProofOfWork(this.ruleContext.ValidationContext.Block)); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <PosCoinstakeRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BlockTimeBeforeTrx, exception.ConsensusError); }
public async Task RunAsync_ProofOfWorkBlock_CheckPow_InValidPow_ThrowsHighHashConsensusErrorExceptionAsync() { Block block = this.network.CreateBlock(); Transaction transaction = this.network.CreateTransaction(); block.AddTransaction(transaction); this.ruleContext.ValidationContext = new ValidationContext() { BlockToValidate = block, ChainedHeaderToValidate = this.ChainIndexer.GetHeader(4) }; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CheckDifficultyHybridRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.HighHash, exception.ConsensusError); }
public async Task RunAsync_BadVersionLowerThan2_HeightHigherThanBip66_ThrowsBadVersionConsensusErrorAsync() { this.ruleContext.ConsensusTipHeight = this.consensusRules.ConsensusParams.BuriedDeployments[BuriedDeployments.BIP66]; this.ruleContext.Time = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 0)); var header = this.network.Consensus.ConsensusFactory.CreateBlockHeader(); this.ruleContext.ValidationContext.Block = this.network.CreateBlock(); header.Bits = new Target(0x1f111115); header.BlockTime = new DateTimeOffset(new DateTime(2017, 1, 1, 0, 1, 1)); header.Version = 1; this.ruleContext.ValidationContext.ChainedHeader = new ChainedHeader(header, header.GetHash(), 1); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <BitcoinActivationRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadVersion, exception.ConsensusError); }
public async Task RunAsync_ProofOfWorkBlock_CheckPow_InValidPow_ThrowsBadDiffBitsConsensusErrorExceptionAsync() { Block block = this.network.CreateBlock(); this.ruleContext.ValidationContext = new ValidationContext() { Block = block, ChainedHeader = this.concurrentChain.GetBlock(0) }; this.ruleContext.MinedBlock = true; block.Header.Bits = this.ruleContext.ValidationContext.ChainedHeader.GetWorkRequired(this.network.Consensus) + 1; ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <CheckDifficultyPowRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadDiffBits, exception.ConsensusError); }
public async Task RunAsync_MultipleCoinsBaseTransactions_ThrowsBadMultipleCoinbaseConsensusErrorExceptionAsync() { this.ruleContext.ValidationContext.BlockToValidate = this.network.CreateBlock(); var transaction = this.network.CreateTransaction(); transaction.Inputs.Add(new TxIn(new OutPoint(), new Script())); transaction.Outputs.Add(new TxOut(new Money(3), (IDestination)null)); Assert.True(transaction.IsCoinBase); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(transaction); this.ruleContext.ValidationContext.BlockToValidate.Transactions.Add(transaction); ConsensusErrorException exception = await Assert.ThrowsAsync <ConsensusErrorException>(() => this.consensusRules.RegisterRule <EnsureCoinbaseRule>().RunAsync(this.ruleContext)); Assert.Equal(ConsensusErrors.BadMultipleCoinbase, exception.ConsensusError); }