public void OrderTest(string asset1, string asset2, BuyOrSell buyOrSell, Order order, double volume) { string assetPair = asset1 + asset2; double asset1Balance = 0; double asset2Balance = 0; double assetPairPrice = 0; string orderId = null; if (order == Order.Limit) { Step("Cancel any limit orders user already has", () => { steps.CancelAnyLimitOrder(token); }); } Step("Get current wallets and balances", () => { asset1Balance = steps.GetAssetBalance(asset1, token); asset2Balance = steps.GetAssetBalance(asset2, token); }); if (order == Order.Limit) { Step("Find prices", () => { assetPairPrice = steps.FindPriceInOrderBook(buyOrSell, volume, assetPair, token); }); } Step($"{buyOrSell} {volume} {asset1} for {asset2}", () => { string accessToken = steps.GetAccessToken(email, token, key); double assetVolume = buyOrSell == BuyOrSell.Buy ? volume : -volume; //TODO: Add assertion to check volume limits if (order == Order.Limit) { Console.WriteLine($"Placing Limit order for pair {asset1 + asset2} with price {assetPairPrice}"); orderId = walletApi.HotWallet .PostLimitOrder(new HotWalletLimitOperation { AssetId = asset1, AssetPair = asset1 + asset2, Price = assetPairPrice, Volume = assetVolume }, accessToken, token) .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError() .GetResponseObject().Result.Order?.Id; } else { var marketOrder = walletApi.HotWallet .PostMarketOrder(new HotWalletOperation { AssetId = asset1, AssetPair = assetPair, Volume = assetVolume }, accessToken, token) .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError() .GetResponseObject().Result; orderId = marketOrder.Order?.Id; Assert.That(marketOrder.Order?.Price, Is.Not.Null, "No order price found"); assetPairPrice = marketOrder.Order.Price.Value; Console.WriteLine($"Market order has been placed for pair {asset1 + asset2} with price {assetPairPrice}"); } Assert.That(orderId, Is.Not.Null.Or.Not.Empty, "Order Id is null or empty"); }); if (order == Order.Limit) { 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).Seconds.PollEvery(1).Seconds, "Limit order has not been sold!"); }); } Step("Assert that balance has been changed", () => { double expectedAsset1Balance = buyOrSell == BuyOrSell.Buy ? asset1Balance + volume : asset1Balance - volume; double expectedAsset2Balance = buyOrSell == BuyOrSell.Buy ? asset2Balance - volume * assetPairPrice : asset2Balance + volume * assetPairPrice; //TODO: Add more acurate assertion //TODO: Remove after and polling? Assert.That(() => steps.GetAssetBalance(asset1, token), Is.EqualTo(expectedAsset1Balance).Within(expectedAsset1Balance * 0.01) .After(60).Seconds.PollEvery(2).Seconds, $"{asset1} is not equal to expected"); Assert.That(() => steps.GetAssetBalance(asset2, token), Is.EqualTo(expectedAsset2Balance).Within(expectedAsset2Balance * 0.02) .After(60).Seconds.PollEvery(2).Seconds, $"{asset2} is not equal to expected"); }); Step("Asserting history", () => { if (walletApi.ApiUrl.Contains("test")) { Console.WriteLine("BUG: Wrong order id in history, skipping step"); return; } Assert.That(() => walletApi.History.GetByAssetId("", token) .Validate.StatusCode(HttpStatusCode.OK).Validate.NoApiError() .GetResponseObject().Result .Any(record => record.Trade?.OrderId == orderId && record.Trade?.Asset == asset1), Is.True.After(60).Seconds.PollEvery(5).Seconds, "No history found for the last order"); }); }
// [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"); } }