public ContractTransactionValidationRule CreateContractValidationRule() { var rule = new ContractTransactionValidationRule(this.CallDataSerializer, new List <IContractTransactionValidationLogic> { new SmartContractFormatLogic() }); rule.Parent = this.Consensus; rule.Logger = this.LoggerFactory.CreateLogger(rule.GetType().FullName); rule.Initialize(); return(rule); }
public async Task SmartContractFormatRule_MultipleOutputs_SuccessAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(this.network); ContractTransactionValidationRule rule = testContext.CreateContractValidationRule(); var context = new PowRuleContext(new ValidationContext(), testContext.DateTimeProvider.GetTimeOffset()) { UnspentOutputSet = GetMockOutputSet() }; context.ValidationContext.BlockToValidate = testContext.Network.Consensus.ConsensusFactory.CreateBlock(); var gasPriceSatoshis = 20; var gasLimit = 4000000; var gasBudgetSatoshis = gasPriceSatoshis * gasLimit; var relayFeeSatoshis = 10000; var change = 200000; var totalSuppliedSatoshis = gasBudgetSatoshis + relayFeeSatoshis; var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Stratis.SmartContracts.RuntimeObserver.Gas)gasLimit, 0, "TestMethod"); var serialized = this.callDataSerializer.Serialize(contractTxData); Transaction funding = new Transaction { Outputs = { new TxOut(totalSuppliedSatoshis + change, new Script()) } }; var transactionBuilder = new TransactionBuilder(testContext.Network); transactionBuilder.AddCoins(funding); transactionBuilder.SendFees(totalSuppliedSatoshis); transactionBuilder.Send(new Script(serialized), 0); // Add a change output to the transaction transactionBuilder.SetChange(new Script()); Transaction transaction = transactionBuilder.BuildTransaction(false); context.ValidationContext.BlockToValidate.Transactions = new List <Transaction> { transaction }; await rule.RunAsync(context); }
public async Task SmartContractFormatRule_FailureAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(this.network); ContractTransactionValidationRule rule = testContext.CreateContractValidationRule(); var context = new PowRuleContext(new ValidationContext(), testContext.DateTimeProvider.GetTimeOffset()); context.ValidationContext.BlockToValidate = testContext.Network.Consensus.ConsensusFactory.CreateBlock(); var gasPriceSatoshis = 20; var gasLimit = 4000000; var gasBudgetSatoshis = gasPriceSatoshis * gasLimit; var relayFeeSatoshis = 10000; var totalSuppliedSatoshis = gasBudgetSatoshis + relayFeeSatoshis; var higherGasLimit = gasLimit + 10000; var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Stratis.SmartContracts.RuntimeObserver.Gas)higherGasLimit, 0, "TestMethod"); var serialized = this.callDataSerializer.Serialize(contractTxData); Transaction funding = new Transaction { Outputs = { new TxOut(totalSuppliedSatoshis, new Script()) } }; var transactionBuilder = new TransactionBuilder(testContext.Network); transactionBuilder.AddCoins(funding); transactionBuilder.SendFees(relayFeeSatoshis); transactionBuilder.Send(new Script(serialized), gasBudgetSatoshis); Transaction transaction = transactionBuilder.BuildTransaction(false); context.ValidationContext.BlockToValidate.Transactions = new List <Transaction> { new Transaction(), // Include an empty transaction to ensure we're checking multiple. transaction }; await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); }