Ejemplo n.º 1
0
        public void AddTwoTxesToNewBlock()
        {
            var key = new Key();

            var tx1 = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };

            var tx2 = new BlockTx()
            {
                Amount     = 5,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test2").Public
            };

            tx1.Sign(key);
            tx2.Sign(key);

            var block = new Block(0);

            block.AddTx(tx1);
            block.AddTx(tx2);
            Assert.NotNull(block);
            Assert.NotNull(block.Txes);
            Assert.AreEqual(2, block.Txes.Length);
        }
Ejemplo n.º 2
0
        public void SingTxWithPublicKey()
        {
            var key = new Key();
            var tx  = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };
            var serializedTx = tx.Serialize();

            tx.Sign(key);
            Assert.NotNull(tx.Fingerprint);
            Assert.NotZero(tx.Fingerprint.Length);
            Assert.IsTrue(key.Verify(serializedTx, ByteArray.HexToByte(tx.Fingerprint)));
        }
Ejemplo n.º 3
0
        public void ValidateTxFailFromAlteredTransactionAmount()
        {
            var key = new Key();
            var tx  = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };

            tx.Sign(key);
            var signKey = new Key(ByteArray.HexToByte(tx.PubKeyFrom));

            tx.Amount = 2;
            Assert.IsFalse(signKey.Verify(tx.Serialize(), ByteArray.HexToByte(tx.Fingerprint)));
        }
Ejemplo n.º 4
0
        public void ValidateTxFromPublicKey()
        {
            var key = new Key();
            var tx  = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };
            var serializedTx = tx.Serialize();

            tx.Sign(key);
            var signKey = new Key(ByteArray.HexToByte(tx.PubKeyFrom));

            Assert.IsTrue(signKey.Verify(serializedTx, ByteArray.HexToByte(tx.Fingerprint)));
        }
Ejemplo n.º 5
0
        public void ValidateTxFailFromAlteredPublicKey()
        {
            var key = new Key();
            var tx  = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };
            var serializedTx = tx.Serialize();

            tx.Sign(key);
            var signKey       = new Key(ByteArray.HexToByte(tx.PubKeyFrom));
            var alteredPubKey = ByteArray.HexToByte(tx.Fingerprint.Replace("B", "C"));

            Assert.IsFalse(signKey.Verify(serializedTx, alteredPubKey));
        }
Ejemplo n.º 6
0
        public void AddTxToNewBlock()
        {
            var key = new Key();
            var tx  = new BlockTx()
            {
                Amount     = 1,
                PubKeyFrom = key.Public,
                PubKeyTo   = new Key("test").Public
            };

            tx.Sign(key);
            var block = new Block(0);

            block.AddTx(tx);
            Assert.NotNull(block);
            Assert.NotNull(block.Txes);
            Assert.AreEqual(1, block.Txes.Length);
        }