public void SendTo_NotAContract_Success()
        {
            uint160 walletAddress = new uint160(321);

            var state = new Mock <IStateRepositoryRoot>();

            state.Setup(x => x.GetAccountState(walletAddress)).Returns <AccountState>(null);
            this.rulesEngine.OriginalStateRoot = state.Object;

            var rule = new P2PKHNotContractRule();

            rule.Parent = this.rulesEngine;
            rule.Initialize();

            Transaction transaction = this.network.CreateTransaction();

            transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(walletAddress))));
            rule.CheckTransaction(new MempoolValidationContext(transaction, null));
        }
        public void SendTo_Contract_Fails()
        {
            uint160 contractAddress = new uint160(123);

            var state = new Mock <IStateRepositoryRoot>();

            state.Setup(x => x.GetAccountState(contractAddress)).Returns(new AccountState()); // not null
            this.rulesEngine.OriginalStateRoot = state.Object;

            var rule = new P2PKHNotContractRule();

            rule.Parent = this.rulesEngine;
            rule.Initialize();

            Transaction transaction = this.network.CreateTransaction();

            transaction.Outputs.Add(new TxOut(100, PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(new KeyId(contractAddress))));
            Assert.Throws <ConsensusErrorException>(() => rule.CheckTransaction(new MempoolValidationContext(transaction, null)));
        }
        public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules)
            : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
        {
            var p2pkhRule = new P2PKHNotContractRule();

            p2pkhRule.Parent = (ConsensusRuleEngine)consensusRules;
            p2pkhRule.Initialize();

            this.preTxRules = new List <ISmartContractMempoolRule>
            {
                new MempoolOpSpendRule(),
                new TxOutSmartContractExecRule(),
                p2pkhRule
            };

            this.feeTxRules = new List <ISmartContractMempoolRule>()
            {
                new SmartContractFormatRule(),
            };
        }