Example #1
0
        public void ValidateNextBlockTx()
        {
            var validKey = new PrivateKey();

            TxPolicyViolationException IsSignerValid(
                BlockChain <DumbAction> chain, Transaction <DumbAction> tx)
            {
                var validAddress = validKey.PublicKey.ToAddress();

                return(tx.Signer.Equals(validAddress)
                    ? null
                    : new TxPolicyViolationException(tx.Id, "invalid signer"));
            }

            var policy = new BlockPolicy <DumbAction>(validateNextBlockTx: IsSignerValid);

            // Valid Transaction
            var validTx  = _chain.MakeTransaction(validKey, new DumbAction[] { });
            var expected = policy.ValidateNextBlockTx(_chain, validTx);

            Assert.Null(expected);

            // Invalid Transaction
            var invalidKey = new PrivateKey();
            var invalidTx  = _chain.MakeTransaction(invalidKey, new DumbAction[] { });

            expected = policy.ValidateNextBlockTx(_chain, invalidTx);
            Assert.NotNull(expected);
        }