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); }
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))); }
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))); }
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))); }
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)); }
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); }