public async Task ShouldRetrieveByPartitionKey()
        {
            var tableName = "integrationhistory";
            await _sut.DeleteTableAsync(tableName);

            await _sut.CreateTableAsync(tableName);

            var partitionKey = "partition-key-1";
            var rowKey       = 123;
            var walletUser   = new WalletUser(partitionKey, rowKey);
            await _sut.InsertOrMergeEntity(tableName, walletUser);

            var partitionKey2 = "partition-key-2";
            var rowKey2       = 456;
            var walletUser2   = new WalletUser(partitionKey2, rowKey2);
            await _sut.InsertOrMergeEntity(tableName, walletUser2);

            var firstRecord = _sut.RetrieveByPartitionKey <WalletUser>(tableName, partitionKey).ToList();

            Assert.NotNull(firstRecord);
            Assert.AreEqual(1, firstRecord.Count);
            Assert.AreEqual(partitionKey, firstRecord.First().PartitionKey);
            Assert.AreEqual(rowKey.ToString(), firstRecord.First().RowKey);

            var secondRecord = _sut.RetrieveByPartitionKey <WalletUser>(tableName, partitionKey2).ToList();

            Assert.NotNull(secondRecord);
            Assert.AreEqual(1, secondRecord.Count);
            Assert.AreEqual(partitionKey2, secondRecord.First().PartitionKey);
            Assert.AreEqual(rowKey2.ToString(), secondRecord.First().RowKey);
        }
        public async Task ShouldNotBeAbleToWithdrawMoreThanBalance()
        {
            var walletAddress = "1234";
            var userId        = 1111;

            double withdrawAmount = 6;

            var walletUser  = new WalletUser(walletAddress, userId);
            var userBalance = new UserBalance {
                Balance = 5
            };

            var chat = new Chat {
                Id = 123456789
            };

            _walletUserRepositoryMock.Setup(x => x.GetByUserId(userId)).Returns(walletUser);
            _userBalanceRepositoryMock.Setup(x => x.Get(userId)).ReturnsAsync(userBalance);

            await _sut.Handle(chat, userId, withdrawAmount);

            _botServiceMock.Verify(x => x.SendTextMessage(chat.Id,
                                                          string.Format(ReplyConstants.InsufficientBalance, userBalance.Balance.RoundMetahashHash(), withdrawAmount.RoundMetahashHash())
                                                          , It.IsAny <IReplyMarkup>()));
            _botServiceMock.VerifyNoOtherCalls();
            _withdrawalRepositoryMock.VerifyNoOtherCalls();
            _mhcHttpClientMock.VerifyNoOtherCalls();
        }
        public object CreateVirtualWallet(WalletUser AccountHolderInformation, int
                                          MerchantAccountID, string APIKey)
        {
            //Check if API key matches
            if (CheckAPIKey(MerchantAccountID, APIKey))
            {
                //Gets a new SQL Command object
                objCommand = new SqlCommand();

                //Sets which stored procedure the command object will use
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "TP_CreateWalletUser";

                //Inputs parameters to the command object

                objCommand.Parameters.AddWithValue("@email", AccountHolderInformation.email);
                objCommand.Parameters.AddWithValue("@password", AccountHolderInformation.password);
                objCommand.Parameters.AddWithValue("@bankRouting", AccountHolderInformation.bankRouting);
                objCommand.Parameters.AddWithValue("@bankAccount", AccountHolderInformation.bankAccount);
                objCommand.Parameters.AddWithValue("@amount", 0);

                objDB.DoUpdateUsingCmdObj(objCommand);

                //get virtual wallet ID
                //Gets a new SQL Command object
                objCommand = new SqlCommand();

                //Sets which stored procedure the command object will use
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "TP_GetWalletID";
                DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand);
                return(ds.Tables[0].Rows[0]["WalletID"].ToString());
            }
            return("false");
        }
        public async Task ShouldImport1Transaction()
        {
            var walletAddress = "0x0070ea89e1d6e36847675511b03951f970763f57c554030171";

            _botConfiguration.TipWalletAddress = "0x002d0dd81812c0e4072a284e0b03dbf7d5d242ac70de0a916a";
            var responseJson         = ReadSampleFile("Transactions1.json");
            var fetchHistoryResponse = JsonConvert.DeserializeObject <FetchHistoryFilterResponse>(responseJson);
            var userId      = 1234;
            var userBalance = 10.5;
            var walletUser  = new WalletUser {
                PartitionKey = walletAddress, RowKey = userId.ToString()
            };

            _mhcHttpClientMock.Setup(x => x.FetchHistory(_botConfiguration.TipWalletAddress)).ReturnsAsync(fetchHistoryResponse);
            _walletUserRepositoryMock.Setup(x => x.GetByWalletId(walletAddress)).Returns(walletUser);
            _userBalanceRepositoryMock.Setup(x => x.Get(userId)).ReturnsAsync(new UserBalance(userId)
            {
                Balance = userBalance
            });

            DateTimeOffset dateJustBeforeLastTransaction = DateTimeOffset.FromUnixTimeSeconds(1621080798 - 1);

            await _sut.ImportTransactions(dateJustBeforeLastTransaction.DateTime);

            _userBalanceRepositoryMock.Verify(x => x.Update(It.Is <UserBalance>(ub => ub.Balance.CompareTo(35.5) == 0)), Times.Once);
            _transactionHistoryRepositoryMock.Verify(x => x.AddOrUpdate(It.IsAny <TransactionHistory>()), Times.Exactly(2));
        }
 public int UpdatePaymentAccount(int vwID, WalletUser accountInfo, int maID, string apiKey)
 {
     if (CheckAPIKey(maID, apiKey))
     {
         //return UpdateWalletAccount(vwID, accountInfo);
     }
     return(-1);
 }
예제 #6
0
 public void SetUser(WalletUser user)
 {
     _userField = new LoggedUser
     {
         WalletUserId = user.WalletUserId,
         Name         = user.Name,
         Email        = user.Email,
         Role         = user.Role
     };
 }
예제 #7
0
        public async Task <WalletUser> GetPublicKeyUser(string privateKey)
        {
            Wallet wallet = new Wallet(privateKey);

            WalletUser result = new WalletUser
            {
                PublicKey = wallet.PublicKey
            };
            var user = await _commonContext.Users.Where(u => u.PublicKey == result.PublicKey).FirstOrDefaultAsync();

            if (user == null)
            {
                throw new ValidationException("The ID you entered is not valid");
            }

            result.Name = user.Name;
            return(result);
        }
        internal int UpdateWalletAccount(int vwID, WalletUser accountInfo)
        {
            //Gets a new SQL Command object
            objCommand = new SqlCommand();

            //Sets which stored procedure the command object will use
            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "TP_UpdateVirtualWallet";

            //Inputs parameters to the command object
            fp.AddParameter(ref objCommand, "@virtualWallet", vwID);

            fp.AddParameter(ref objCommand, "@email", accountInfo.email);
            fp.AddParameter(ref objCommand, "@password", accountInfo.password);
            fp.AddParameter(ref objCommand, "@bankRouting", accountInfo.bankRouting);
            fp.AddParameter(ref objCommand, "@bankAccount", accountInfo.bankAccount);

            return(objDB.DoUpdateUsingCmdObj(objCommand));
        }
        public async Task ShouldBeAbleToWithdrawExactBalance()
        {
            var walletAddress = "1234";
            var userId        = 1111;

            double withdrawAmount = 6;

            var walletUser  = new WalletUser(walletAddress, userId);
            var userBalance = new UserBalance {
                Balance = 6
            };

            var chat = new Chat {
                Id = 123456789
            };

            var txId = "76c93d17bed19ab03354c37668d54f29ef46bbeee3cbc4b0de52ec8f2f53171f";

            _walletUserRepositoryMock.Setup(x => x.GetByUserId(userId)).Returns(walletUser);
            _userBalanceRepositoryMock.Setup(x => x.Get(userId)).ReturnsAsync(userBalance);
            _nodeExecutionServiceMock.Setup(x => x.Withdraw(walletAddress, withdrawAmount)).ReturnsAsync(txId);
            _mhcHttpClientMock.Setup(x => x.GetTx(txId)).ReturnsAsync(new GetTxResponse
            {
                Id = 86448648653, TxResult = new TxResult {
                    Transaction = new Transaction {
                        Status = "ok"
                    }
                }
            });

            await _sut.Handle(chat, userId, withdrawAmount);

            // todo could use some extra verify
            _userBalanceRepositoryMock.Verify(x => x.Update(It.Is <UserBalance>(x => x.Balance == 0)), Times.Once);
            _botServiceMock.Verify(x => x.SendTextMessage(chat.Id, ReplyConstants.WithdrawVerification, It.IsAny <IReplyMarkup>()));
            _botServiceMock.Verify(x => x.SendTextMessage(chat.Id, ReplyConstants.WithdrawalSuccess, It.IsAny <IReplyMarkup>()));
            _botServiceMock.VerifyNoOtherCalls();
            _mhcHttpClientMock.Verify(x => x.GetTx(txId), Times.Once);
            _mhcHttpClientMock.VerifyNoOtherCalls();
        }
        public WalletUser GetWalletUser(string email)
        {
            //Gets a new SQL Command object
            objCommand = new SqlCommand();

            //Sets which stored procedure the command object will use
            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "TP_GetWalletUser";

            //Inputs parameters to the command object
            fp.AddParameter(ref objCommand, "@email", email);

            DataSet walletUser = objDB.GetDataSetUsingCmdObj(objCommand);

            WalletUser wu = new WalletUser();

            wu.walletID    = int.Parse(walletUser.Tables[0].Rows[0]["walletUserID"].ToString());
            wu.bankRouting = walletUser.Tables[0].Rows[0]["bankRoutingNumber"].ToString();
            wu.bankAccount = walletUser.Tables[0].Rows[0]["bankAccountNumber"].ToString();
            wu.amount      = float.Parse(walletUser.Tables[0].Rows[0]["amount"].ToString());
            return(wu);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            WalletUser wu = new WalletUser();
            Customer   c  = (Customer)Session["User"];

            try
            {
                wu                 = apic.GetWalletUser(c.Email);
                wu.email           = c.Email;
                wu.password        = c.Password;
                txtSUCRouting.Text = wu.bankRouting;
                txtSUCAccount.Text = wu.bankAccount;
            }
            catch
            {
                ErrorLabel.FillError("A problem has occured with the API. Please try again later.");
            }


            txtAccountBalance.Text = "$" + wu.amount.ToString();

            txtSUCBillingAddress.Text  = c.BillingAddress;
            txtSUCDeliveryAddress.Text = c.DeliveryAddress;
            txtSUCEmail.Text           = c.Email;
            txtSUCFirstName.Text       = c.FirstName;
            txtSUCLastName.Text        = c.LastName;
            txtSUCPassword.Text        = c.Password;
            txtSUCPhoneNumber.Text     = c.PhoneNumber;


            if (!IsPostBack)
            {
                DataSet ds = gd.GetOrders(int.Parse(c.UserID));

                gvPreviousOrders.DataSource = ds;
                gvPreviousOrders.DataBind();
            }
        }
 public async Task Delete(WalletUser transaction)
 {
     await _tableStorageService.Delete(TableName, transaction);
 }
 public async Task AddOrUpdate(WalletUser transaction)
 {
     await _tableStorageService.InsertOrMergeEntity(TableName, transaction);
 }
예제 #14
0
 protected void btnFund_Click(object sender, EventArgs e)
 {
     //I jerry rigged it to give out a walletuser to fix the problem here. Not sure if it works to well though. -Ieuan
     WalletUser funded = apc.FundAccount("vwID", txtFundAmount.Text);
 }