public void CreateTransactionInput_IncorrectGasPriceGwei_ThrowsArgumentOutOfRangeException(decimal gasPriceGwei)
        {
            string expectedMessage = "Specified argument was out of the range of valid values.\r\nParameter name: gasPriceGwei";

            Exception ex = Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                       EtherTransferTransactionInputBuilder.CreateTransactionInput(null, ToAddress, EthAmount, gasPriceGwei));

            Assert.Equal(expectedMessage, ex.Message);
        }
        public void CreateTransactionInput_IncorrectToAddress_ThrowsArgumentNullException(string toAddress)
        {
            string expectedMessage = "Value cannot be null.\r\nParameter name: toAddress";

            Exception ex = Assert.Throws <ArgumentNullException>(() =>
                                                                 EtherTransferTransactionInputBuilder.CreateTransactionInput(null, toAddress, 0));

            Assert.Equal(expectedMessage, ex.Message);
        }
Exemple #3
0
        public void CreateTransactionInput_IncorrectEtherAmount_ThrowsArgumentOutOfRangeException(decimal etherAmount)
        {
            string expectedMessage = "Specified argument was out of the range of valid values";

            Exception ex = Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                       EtherTransferTransactionInputBuilder.CreateTransactionInput(null, ToAddress, etherAmount));

            Assert.StartsWith(expectedMessage, ex.Message);
        }
        public void CreateTransactionInput_ReturnsTransactionInput2()
        {
            var expectedGasPrice = new HexBigInteger(UnitConversion.Convert.ToWei(GasPriceGwei, UnitConversion.EthUnit.Gwei));
            var expectedValue    = new HexBigInteger(UnitConversion.Convert.ToWei(EthAmount));

            var actualTransactionInput = EtherTransferTransactionInputBuilder.CreateTransactionInput(FromAddress, ToAddress, EthAmount, GasPriceGwei, null, null);

            Assert.IsType <TransactionInput>(actualTransactionInput);
            Assert.Equal(ToAddress, actualTransactionInput.To);
            Assert.Equal(FromAddress, actualTransactionInput.From);
            Assert.Equal(expectedGasPrice, actualTransactionInput.GasPrice);
            Assert.Equal(expectedValue, actualTransactionInput.Value);
            Assert.Null(actualTransactionInput.Gas);
            Assert.Null(actualTransactionInput.Nonce);
        }
        public IEnumerator TransferEther(string toAddress, decimal etherAmount, decimal?gasPriceGwei = null, BigInteger?gas = null)
        {
            var transactionInput =
                EtherTransferTransactionInputBuilder.CreateTransactionInput(null, toAddress, etherAmount,
                                                                            gasPriceGwei, gas);

            yield return(_transactionSignedUnityRequest.SignAndSendTransaction(transactionInput));

            if (_transactionSignedUnityRequest.Exception == null)
            {
                this.Result = _transactionSignedUnityRequest.Result;
            }
            else
            {
                this.Exception = _transactionSignedUnityRequest.Exception;
            }
        }
Exemple #6
0
        public async void ShouldRecoverRawTransactionFromRPCTransactionAndAccountSender()
        {
            var web3 = _ethereumClientIntegrationFixture.GetWeb3();

            var toAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";

            var transactionManager = web3.TransactionManager;
            var fromAddress        = transactionManager?.Account?.Address;

            //Sending transaction
            var transactionInput = EtherTransferTransactionInputBuilder.CreateTransactionInput(fromAddress, toAddress, 1.11m, 2);
            //Raw transaction signed
            var rawTransaction = await transactionManager.SignTransactionAsync(transactionInput).ConfigureAwait(false);

            var txnHash = await web3.Eth.Transactions.SendRawTransaction.SendRequestAsync(rawTransaction).ConfigureAwait(false);

            //Getting the transaction from the chain
            var transactionRpc = await web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync(txnHash).ConfigureAwait(false);

            //Using the transanction from RPC to build a txn for signing / signed
            var transaction = TransactionFactory.CreateLegacyTransaction(transactionRpc.To, transactionRpc.Gas, transactionRpc.GasPrice, transactionRpc.Value, transactionRpc.Input, transactionRpc.Nonce,
                                                                         transactionRpc.R, transactionRpc.S, transactionRpc.V);

            //Get the raw signed rlp recovered
            var rawTransactionRecovered = transaction.GetRLPEncoded().ToHex();

            //Get the account sender recovered
            var accountSenderRecovered = string.Empty;

            if (transaction is LegacyTransactionChainId)
            {
                var txnChainId = transaction as LegacyTransactionChainId;
                accountSenderRecovered = EthECKey.RecoverFromSignature(transaction.Signature, transaction.RawHash, txnChainId.GetChainIdAsBigInteger()).GetPublicAddress();
            }
            else
            {
                accountSenderRecovered = EthECKey.RecoverFromSignature(transaction.Signature, transaction.RawHash).GetPublicAddress();
            }

            Assert.Equal(rawTransaction, rawTransactionRecovered);
            Assert.Equal(web3.TransactionManager.Account.Address, accountSenderRecovered);
        }