public void CreateCoinbase_CreatesCoinbaseTemplateTransaction_AddsToBlockTemplate() { this.ExecuteWithConsensusOptions(new PosConsensusOptions(), () => { var chain = GenerateChainWithHeight(5, this.network, this.key); var posBlockAssembler = new PosTestBlockAssembler(this.consensusLoop.Object, this.network, new MempoolSchedulerLock(), this.txMempool.Object, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, chain.Tip, this.LoggerFactory.Object); var result = posBlockAssembler.CreateCoinBase(chain.Tip, this.key.ScriptPubKey); Assert.NotEmpty(result.Block.Transactions); Assert.Equal(-1, result.TxSigOpsCost[0]); Assert.Equal(new Money(-1), result.VTxFees[0]); var resultingTransaction = result.Block.Transactions[0]; Assert.True(resultingTransaction.IsCoinBase); Assert.False(resultingTransaction.IsCoinStake); Assert.Equal(Money.Zero, resultingTransaction.TotalOut); Assert.NotEmpty(resultingTransaction.Inputs); Assert.Equal(TxIn.CreateCoinbase(6).ScriptSig, resultingTransaction.Inputs[0].ScriptSig); Assert.NotEmpty(resultingTransaction.Outputs); Assert.Equal(this.key.ScriptPubKey, resultingTransaction.Outputs[0].ScriptPubKey); Assert.Equal(Money.Zero, resultingTransaction.Outputs[0].Value); }); }
public void CreateCoinbase_CreatesCoinbaseTemplateTransaction_AddsToBlockTemplate() { this.ExecuteWithConsensusOptions(new PosConsensusOptions(), () => { ConcurrentChain chain = GenerateChainWithHeight(5, this.stratisTest, this.key); this.dateTimeProvider.Setup(d => d.GetAdjustedTimeAsUnixTimestamp()) .Returns(new DateTime(2017, 1, 7, 0, 0, 1, DateTimeKind.Utc).ToUnixTimestamp()); var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.stratisTest, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object); BlockTemplate result = posBlockAssembler.CreateCoinBase(chain.Tip, this.key.ScriptPubKey); Assert.NotEmpty(result.Block.Transactions); Transaction resultingTransaction = result.Block.Transactions[0]; Assert.Equal((uint)new DateTime(2017, 1, 7, 0, 0, 1, DateTimeKind.Utc).ToUnixTimestamp(), resultingTransaction.Time); Assert.True(resultingTransaction.IsCoinBase); Assert.False(resultingTransaction.IsCoinStake); Assert.Equal(Money.Zero, resultingTransaction.TotalOut); Assert.NotEmpty(resultingTransaction.Inputs); Assert.Equal(TxIn.CreateCoinbase(6).ScriptSig, resultingTransaction.Inputs[0].ScriptSig); Assert.NotEmpty(resultingTransaction.Outputs); Assert.Equal(this.key.ScriptPubKey, resultingTransaction.Outputs[0].ScriptPubKey); Assert.Equal(Money.Zero, resultingTransaction.Outputs[0].Value); }); }
public void CreateCoinbase_CreatesCoinbaseTemplateTransaction_AddsToBlockTemplate() { this.ExecuteWithConsensusOptions(new PosConsensusOptions(), () => { ChainIndexer chainIndexer = GenerateChainWithHeight(5, this.Network, this.key); this.dateTimeProvider.Setup(d => d.GetAdjustedTimeAsUnixTimestamp()) .Returns(new DateTime(2017, 1, 7, 0, 0, 1, DateTimeKind.Utc).ToUnixTimestamp()); var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.Network, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object, new NodeDeployments(this.Network, chainIndexer)); BlockTemplate result = posBlockAssembler.CreateCoinBase(chainIndexer.Tip, this.key.ScriptPubKey); Assert.NotEmpty(result.Block.Transactions); Transaction resultingTransaction = result.Block.Transactions[0]; // Creating a coinbase will not by itself update the header timestamp. So we don't check that here. Assert.True(resultingTransaction.IsCoinBase); Assert.False(resultingTransaction.IsCoinStake); Assert.Equal(Money.Zero, resultingTransaction.TotalOut); Assert.NotEmpty(resultingTransaction.Inputs); Assert.Equal(TxIn.CreateCoinbase(6).ScriptSig, resultingTransaction.Inputs[0].ScriptSig); Assert.NotEmpty(resultingTransaction.Outputs); Assert.Equal(this.key.ScriptPubKey, resultingTransaction.Outputs[0].ScriptPubKey); Assert.Equal(Money.Zero, resultingTransaction.Outputs[0].Value); }); }
public void AddTransactions_TransactionNotInblock_AddsTransactionToBlock() { var newOptions = new PosConsensusOptions(); this.ExecuteWithConsensusOptions(newOptions, () => { ConcurrentChain chain = GenerateChainWithHeight(5, this.stratisTest, this.key); this.consensusManager.Setup(c => c.Tip) .Returns(chain.GetBlock(5)); Mock <IConsensusRuleEngine> consensusRuleEngine = new Mock <IConsensusRuleEngine>(); consensusRuleEngine.Setup(s => s.GetRule <PosFutureDriftRule>()).Returns(new PosFutureDriftRule()); this.consensusManager.Setup(c => c.ConsensusRules) .Returns(consensusRuleEngine.Object); Transaction transaction = CreateTransaction(this.stratisTest, this.key, 5, new Money(400 * 1000 * 1000), new Key(), new uint256(124124)); this.dateTimeProvider.Setup(s => s.GetAdjustedTimeAsUnixTimestamp()).Returns(transaction.Time); var txFee = new Money(1000); SetupTxMempool(chain, newOptions, txFee, transaction); var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.stratisTest, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object); posBlockAssembler.CreateCoinBase(new ChainedHeader(this.stratisTest.GetGenesis().Header, this.stratisTest.GetGenesis().Header.GetHash(), 0), new KeyId().ScriptPubKey); (Block Block, int Selected, int Updated)result = posBlockAssembler.AddTransactions(); Assert.NotEmpty(result.Block.Transactions); Assert.Equal(transaction.ToHex(), result.Block.Transactions[1].ToHex()); Assert.Equal(1, result.Selected); Assert.Equal(0, result.Updated); }); }