public void CheckVerificationMalformedSignature() { var randomKey = KeyWallet.Create(); var from = wallet.GetAddress(); var to = new Address("hx5bfdb090f43a808005ffc27c25b213145e80b7cd"); var transaction = TransactionBuilder.CreateBuilder() .Nid(NetworkId.Main) .From(from) .To(to) .Value(BigInteger.Parse("0de0b6b3a7640000", NumberStyles.AllowHexSpecifier)) .StepLimit(BigInteger.Parse("12345", NumberStyles.AllowHexSpecifier)) .Timestamp(BigInteger.Parse("563a6cf330136", NumberStyles.AllowHexSpecifier)) .Nonce(BigInteger.Parse("1")) .Build(); var signedTransaction = new SignedTransaction(transaction, wallet); var transactionProps = signedTransaction.GetTransactionProperties(); var allProps = signedTransaction.GetProperties(); var hash = SignedTransaction.GetTransactionHash(transactionProps); var signature = Base64.Decode(allProps.GetItem("signature").ToString()); signature[64] = 212; var result = EcdsaSignature.VerifySignature(randomKey.GetAddress(), signature, hash); Assert.False(result); }
public async Task BroadcastTransactionAsync__Transaction_Is_Broadcasted__Transaction_Is_Sent() { var blockchainService = _container.Resolve <IBlockchainService>(); string from = _secretWallet.GetAddress().ToString(); string to = _toWallet.GetAddress().ToString(); BigInteger amount = BigInteger.Parse("100000000000000"); BigInteger gasAmount = BigInteger.Parse("1000000"); BigInteger gasPrice = 1; var transaction = blockchainService.BuildTransaction(from, to, amount, gasAmount, gasPrice, 0); string txDataStr = System.Text.Encoding.UTF8.DecodeBase64(transaction); var iconTransaction = TransactionDeserializer.Deserialize(txDataStr); var signedTransaction = new SignedTransaction(iconTransaction, _secretWallet); var properties = signedTransaction.GetProperties(); var transactionProperties = signedTransaction.GetTransactionProperties(); var transactionHash = SignedTransaction.GetTransactionHash(transactionProperties); var serializedSignedTransaction = SignedTransaction.Serialize(properties); string serializedSignedTransactionBase64 = System.Text.Encoding.UTF8.EncodeBase64(serializedSignedTransaction); var expectedTxHash = (new Bytes(transactionHash)).ToHexString(true); var txHash = await blockchainService.BroadcastTransactionAsync(serializedSignedTransactionBase64); Assert.Equal(expectedTxHash, txHash); }