public async Task TxOutSmartContractExec_AllTransactions_ValidationFailAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(this.network); TxOutSmartContractExecRule rule = testContext.CreateRule <TxOutSmartContractExecRule>(); var context = new RuleContext(new ValidationContext(), testContext.DateTimeProvider.GetTimeOffset()); context.ValidationContext.BlockToValidate = testContext.Network.Consensus.ConsensusFactory.CreateBlock(); context.ValidationContext.BlockToValidate.Header.HashPrevBlock = testContext.Chain.Tip.HashBlock; var transactions = new List <Transaction> { new Transaction() { Outputs = { new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CALLCONTRACT })), new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CREATECONTRACT })) } } }; context.ValidationContext.BlockToValidate.Transactions = transactions; await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); transactions = new List <Transaction> { new Transaction() { Outputs = { new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CALLCONTRACT })), new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CALLCONTRACT })) } } }; context.ValidationContext.BlockToValidate.Transactions = transactions; await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); transactions = new List <Transaction> { new Transaction() { Outputs = { new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CREATECONTRACT })), new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CREATECONTRACT })) } } }; context.ValidationContext.BlockToValidate.Transactions = transactions; await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); }
public async Task TxOutSmartContractExec_AllTransactions_ValidationSuccessAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(this.network); TxOutSmartContractExecRule rule = testContext.CreateRule <TxOutSmartContractExecRule>(); var context = new RuleContext(new ValidationContext(), testContext.Network.Consensus, testContext.Chain.Tip, testContext.DateTimeProvider.GetTimeOffset()); context.ValidationContext.Block = testContext.Network.Consensus.ConsensusFactory.CreateBlock(); context.ValidationContext.Block.Header.HashPrevBlock = testContext.Chain.Tip.HashBlock; context.ValidationContext.Block.Transactions = new List <Transaction> { new Transaction { Outputs = { new TxOut(Money.Zero, new Script(new [] { (byte)ScOpcodeType.OP_CREATECONTRACT })) } } }; await rule.RunAsync(context); }
public override void CheckTransaction(MempoolValidationContext context) { TxOutSmartContractExecRule.CheckTransaction(context.Transaction); }