public void Login()
        {
            steps = new MobileSteps(walletApi);

            Step($"Login as {email} user", () =>
            {
                var loginStep = steps.Login(email, password, pin);
                token         = loginStep.token;
                key           = loginStep.privateKey;
            });
        }
            //  [Category("BlockchainIntegration")]
            public void ProhibotCashOutsToHWTest()
            {
                string phonePrefix = null;
                string phoneNumber = TestData.GenerateNumbers(9);

                var currentAssetId = lykkePrivateApi.Assets.GetAssets().GetResponseObject().FirstOrDefault(a =>
                {
                    if (a.BlockchainIntegrationLayerId != null)
                    {
                        return(a.BlockchainIntegrationLayerId.ToString().ToLower() == BlockChainName.ToLower());
                    }

                    return(false);
                })?.Id;

                var blockchainSettings = cfg["BlockchainsIntegration"];

                var currentBlockchainSettings = JsonConvert.DeserializeObject <BlockchainSettings[]>(cfg["BlockchainsIntegration"]["Blockchains"].ToString()).FirstOrDefault(b => b.Type.ToLower().Contains(BlockChainName.ToLower()));

                if (currentBlockchainSettings == null)
                {
                    Assert.Ignore($"Blockchain {BlockChainName} does not present in blockchain settings {blockchainSettings}");
                }

                #region register client

                var bitcoinPrivateKey = new NBitcoin.Key().GetWif(NBitcoin.Network.TestNet);

                //STEP 0
                var getApplicationInfo = walletApi.ApplicationInfo
                                         .GetApplicationInfo()
                                         .Validate.StatusCode(HttpStatusCode.OK)
                                         .Validate.NoApiError();

                //STEP 2
                var postEmailVerification = walletApi.EmailVerification
                                            .PostEmailVerification(new PostEmailModel()
                {
                    Email = email
                })
                                            .Validate.StatusCode(HttpStatusCode.OK)
                                            .Validate.NoApiError();
                Assert.That(postEmailVerification.GetResponseObject().Error, Is.Null);

                //STEP 3
                var getEmailVerification = walletApi.EmailVerification
                                           .GetEmailVerification(email, code, null)
                                           .Validate.StatusCode(HttpStatusCode.OK)
                                           .Validate.NoApiError();
                Assert.That(getEmailVerification.GetResponseObject().Result.Passed, Is.True);

                //STEP 4
                var postRegistration = walletApi.Registration.PostRegistrationResponse(new AccountRegistrationModel()
                {
                    ClientInfo = clientInfo,
                    Email      = email,
                    Hint       = hint,
                    Password   = Sha256.GenerateHash(password)
                })
                                       .Validate.StatusCode(HttpStatusCode.OK)
                                       .Validate.NoApiError();
                Assert.Multiple(() =>
                {
                    var postRegistrationData = postRegistration.GetResponseObject();
                    Assert.That(postRegistrationData.Result.PersonalData?.Email, Is.EqualTo(email));
                    Assert.That(postRegistrationData.Result.Token, Is.Not.Null.And.Not.Empty);
                });
                token = postRegistration.GetResponseObject().Result.Token;

                //STEP 6
                var getPersonalData = walletApi.PersonalData
                                      .GetPersonalDataResponse(token)
                                      .Validate.StatusCode(HttpStatusCode.OK)
                                      .Validate.NoApiError();
                Assert.That(getPersonalData.GetResponseObject().Result
                            .Email, Is.EqualTo(email));

                //STEP 7
                var postClientFullName = walletApi.ClientFullName
                                         .PostClientFullName(new PostClientFullNameModel()
                {
                    FullName = $"{firstName} {lastName}"
                }, token)
                                         .Validate.StatusCode(HttpStatusCode.OK)
                                         .Validate.NoApiError();

                //STEP 8
                getPersonalData = walletApi.PersonalData
                                  .GetPersonalDataResponse(token)
                                  .Validate.StatusCode(HttpStatusCode.OK)
                                  .Validate.NoApiError();
                var getPersonalDataResult = getPersonalData.GetResponseObject().Result;
                Assert.That(getPersonalDataResult.FullName, Is.EqualTo($"{firstName} {lastName}"));
                Assert.That(getPersonalDataResult.FirstName, Is.EqualTo(firstName));
                Assert.That(getPersonalDataResult.LastName, Is.EqualTo(lastName));
                Assert.That(getPersonalDataResult.Country, Is.Not.Null.And.Not.Empty);
                country = getPersonalData.GetResponseObject().Result.Country;

                //STEP 9
                var getCountryPhoneCodes = walletApi.CountryPhoneCodes
                                           .GetCountryPhoneCodes(token)
                                           .Validate.StatusCode(HttpStatusCode.OK)
                                           .Validate.NoApiError();
                var getCountryPhoneCodesResult = getCountryPhoneCodes.GetResponseObject().Result;
                Assert.That(getCountryPhoneCodesResult.Current, Is.EqualTo(country));
                phonePrefix = getCountryPhoneCodesResult.CountriesList
                              .FirstOrDefault(c => c.Id == country)?.Prefix;
                Assert.That(phonePrefix, Is.Not.Null);

                //STEP 10
                var postCheckMobilePhone = walletApi.CheckMobilePhone
                                           .PostCheckMobilePhone(new PostClientPhoneModel()
                {
                    PhoneNumber = phonePrefix + phoneNumber
                }, token)
                                           .Validate.StatusCode(HttpStatusCode.OK)
                                           .Validate.NoApiError();

                //STEP 11
                var getCheckMobilePhone = walletApi.CheckMobilePhone
                                          .GetCheckMobilePhone(phonePrefix + phoneNumber, code, token)
                                          .Validate.StatusCode(HttpStatusCode.OK)
                                          .Validate.NoApiError();
                Assert.That(getCheckMobilePhone.GetResponseObject().Result
                            .Passed, Is.True);

                //STEP 12
                var getCheckDocumentsToUpload = walletApi.CheckDocumentsToUpload
                                                .GetCheckDocumentsToUpload(token)
                                                .Validate.StatusCode(HttpStatusCode.OK)
                                                .Validate.NoApiError();
                var getCheckDocumentsToUploadResult = getCheckDocumentsToUpload.GetResponseObject().Result;
                Assert.That(getCheckDocumentsToUploadResult.IdCard, Is.True);
                Assert.That(getCheckDocumentsToUploadResult.ProofOfAddress, Is.True);
                Assert.That(getCheckDocumentsToUploadResult.Selfie, Is.True);

                //STEP 13
                var postPinSecurity = walletApi.PinSecurity
                                      .PostPinSecurity(new PinSecurityChangeModel()
                {
                    Pin = pin
                }, token)
                                      .Validate.StatusCode(HttpStatusCode.OK)
                                      .Validate.NoApiError();

                //STEP 14
                var getMyLykkeSettings = walletApi.MyLykkeSettings
                                         .GetMyLykkeSettings(token)
                                         .Validate.StatusCode(HttpStatusCode.OK)
                                         .Validate.NoApiError();
                Assert.That(getMyLykkeSettings.GetResponseObject().Result.MyLykkeEnabled,
                            Is.True);

                //STEP 15
                var postClientKeys = walletApi.ClientKeys
                                     .PostClientKeys(new ClientKeysModel()
                {
                    PubKey            = bitcoinPrivateKey.PubKey.ToString(),
                    EncodedPrivateKey = AesUtils.Encrypt(bitcoinPrivateKey.ToString(), password)
                }, token)
                                     .Validate.StatusCode(HttpStatusCode.OK)
                                     .Validate.NoApiError();

                #endregion

                var clientId = lykkePrivateApi.ClientAccount.ClientAccountInformation.
                               GetClientsByEmail(email).GetResponseObject().FirstOrDefault()?.Id;

                Assert.That(clientId, Is.Not.Null, "UnExpected ClientId is null.");

                var walletId = lykkePrivateApi.ClientAccount.Wallets.GetWalletsForClientById(clientId).
                               GetResponseObject().FirstOrDefault()?.Id;
                Assert.That(walletId, Is.Not.Null, $"Dont have any wallets for client {clientId}");

                // fill wallet with manual CashIn
                var manualCashIn = new ManualCashInRequestModel
                {
                    Amount   = 10,
                    AssetId  = currentAssetId,
                    ClientId = clientId,
                    Comment  = "AutotestFund",
                    UserId   = "Autotest user"
                };
                var cryptoToWalletResponse = lykkePrivateApi.ExchangeOperation.PostManualCashIn(manualCashIn);

                // we have crypto. Go to make CashOut
                var mobileSteps = new MobileSteps(walletApi);
                var keys        = mobileSteps.Login(email, password, pin);
                var SignatureVerificationToken = mobileSteps.GetAccessToken(email, keys.token, keys.privateKey);

                //complete backup
                var backUp = walletApi.BackupCompleted.PostBackupCompleted(token);

                var cashOut = new HotWalletCashoutOperation {
                    AssetId = currentAssetId, DestinationAddress = currentBlockchainSettings.HotWalletAddress, Volume = 5
                };

                var cashOutRequest = walletApi.HotWallet.PostCashOut(cashOut, SignatureVerificationToken, token);

                if (cashOutRequest.GetResponseObject().Error.Message.ToLower().Contains("address is invalid"))
                {
                    Assert.Pass("Error message contain 'address is invalid'");
                }
                else
                {
                    var getDiscl  = walletApi.AssetDisclaimers.Get(token);
                    var postDiscl = walletApi.AssetDisclaimers.PostApproveById(getDiscl.GetResponseObject().Result.Disclaimers[0].Id, token);

                    //make cashout again
                    SignatureVerificationToken = mobileSteps.GetAccessToken(email, keys.token, keys.privateKey);
                    cashOutRequest             = walletApi.HotWallet.PostCashOut(cashOut, SignatureVerificationToken, token);

                    Assert.That(cashOutRequest.GetResponseObject().Error.Message.ToLower(), Does.Contain("address is invalid"), "Unexpected error message");
                }
            }
Exemplo n.º 3
0
        public void BuyAssetLimitOrderTest()
        {
            string asset             = "EUR";
            double assetBalance      = 0;
            string assetToBuy        = "BTC";
            double assetToBuyBalance = 0;
            double volume            = 0.0001;
            string assetPair         = "BTCEUR"; //TODO What about vise versa?
            double assetPairPrice    = 0;
            string orderId           = null;
            string token             = null;
            Key    key = null;

            Step($"Login as {email} user", () =>
            {
                var loginStep         = new MobileSteps(walletApi).Login(email, password, pin);
                var encodedPrivateKey = loginStep.encodedPrivateKey;
                var privateKey        = AesUtils.Decrypt(encodedPrivateKey, password);
                token = loginStep.token;
                key   = Key.Parse(privateKey);
            });

            Step("Get current wallets and balances", () =>
            {
                var walltes = walletApi.Wallets.GetWalltes(token)
                              .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                              .GetResponseObject().Result;

                var assetBalanceNullable = walltes.Lykke.Assets
                                           .FirstOrDefault(wallet => wallet.Id == asset)?.Balance;
                Assert.That(assetBalanceNullable, Is.Not.Null);
                assetBalance = assetBalanceNullable.Value;
                //TODO: Should 100 eur be enough???
                Assert.That(assetBalance, Is.GreaterThan(100), $"Less than 100 {asset} at the wallet!");

                var assetToBuyBalanceNullable = walltes.Lykke.Assets
                                                .FirstOrDefault(wallet => wallet.Id == assetToBuy)?.Balance;
                Assert.That(assetToBuyBalanceNullable, Is.Not.Null);
                assetToBuyBalance = assetToBuyBalanceNullable.Value;
            });

            Step("Find price to purchase", () =>
            {
                var assetPairRates = walletApi.AssetPairRates.GetById(assetPair, token)
                                     .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                                     .GetResponseObject().Result;
                Assert.That(assetPairRates.Rate.Ask, Is.Not.Null);
                assetPairPrice = assetPairRates.Rate.Ask.Value;
            });

            Step($"Buy {assetToBuy} for {asset}", () =>
            {
                string message = walletApi.SignatureVerificationToken
                                 .GetKeyConfirmation(email, token)
                                 .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                                 .GetResponseObject().Result?.Message;
                Assert.That(message, Is.Not.Null);

                var signedMessage = key.SignMessage(message);

                string accessToken = walletApi.SignatureVerificationToken
                                     .PostKeyConfirmation(new RecoveryTokenChallangeResponse(email, signedMessage), token)
                                     .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                                     .GetResponseObject().Result.AccessToken;
                Assert.That(accessToken, Is.Not.Null);

                orderId = walletApi.HotWallet
                          .PostLimitOrder(new HotWalletLimitOperation
                {
                    AssetId   = assetToBuy,
                    AssetPair = assetPair,
                    Price     = assetPairPrice,
                    Volume    = volume
                }, accessToken, token)
                          .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                          .GetResponseObject().Result.Order?.Id;
                Assert.That(orderId, Is.Not.Null);
            });

            Step("Waiting for 1 minute until asset has been sold", () =>
            {
                Assert.That(() => walletApi.LimitOrders.GetOffchainLimitList(token, assetPair)
                            .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                            .GetResponseObject().Result.Orders,
                            Is.Empty.After(60 * 1000, 1000));
            });

            Step($"Assert that {assetToBuy} balance has been increased, and {asset} balance decreased", () =>
            {
                Assert.That(walletApi.Wallets.GetWalletsById(assetToBuy, token)
                            .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                            .GetResponseObject().Result.Balance,
                            Is.EqualTo(assetToBuyBalance + volume).Within(assetToBuyBalance * 0.01));

                Assert.That(walletApi.Wallets.GetWalletsById(asset, token)
                            .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                            .GetResponseObject().Result.Balance,
                            Is.EqualTo(assetBalance - volume * assetPairPrice).Within(assetBalance * 0.01));
            });

            Step("Asserting history", () =>
            {
                Assert.That(() => walletApi.History.GetByAssetId("", token)
                            .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError()
                            .GetResponseObject().Result
                            .Any(record => record.Trade?.OrderId == orderId && record.Trade?.Asset == asset),
                            Is.True.After(60 * 1000, 1000));
            });
        }