Exemplo n.º 1
0
        public static async Task <bool> DeleteClientAccount(string clientId)
        {
            ApiConsumer consumer = new ApiConsumer(ApiPaths.CLIENT_ACCOUNT_SERVICE_PREFIX, ApiPaths.CLIENT_ACCOUNT_SERVICE_BASEURL, false);

            string url            = ApiPaths.CLIENT_ACCOUNT_PATH + "/" + clientId;
            var    deleteResponse = await consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.DELETE);

            if (deleteResponse.Status != HttpStatusCode.OK)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static async Task StopAlgoInstance(ApiConsumer apiConsumer, InstanceDataDTO postInstanceData)
        {
            StopBinaryDTO stopAlgo = new StopBinaryDTO()
            {
                AlgoId     = postInstanceData.AlgoId,
                InstanceId = postInstanceData.InstanceId
            };
            var stopAlgoRequest = await apiConsumer.ExecuteRequest(stopAlgoPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

            StopBinaryResponseDTO stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(stopAlgoRequest.ResponseJson);

            int retryCounter = 1;

            while ((stopAlgoResponce.Status.Equals("Deploying") || stopAlgoResponce.Status.Equals("Started")) && retryCounter <= 30)
            {
                System.Threading.Thread.Sleep(10000);
                stopAlgoRequest = await apiConsumer.ExecuteRequest(stopAlgoPath, Helpers.EmptyDictionary, JsonUtils.SerializeObject(stopAlgo), Method.POST);

                stopAlgoResponce = JsonUtils.DeserializeJson <StopBinaryResponseDTO>(stopAlgoRequest.ResponseJson);

                retryCounter++;
            }
        }
Exemplo n.º 3
0
        public static async Task <StatisticsDTO> GetStatisticsResponseAsync(ApiConsumer apiConsumer, InstanceDataDTO postInstanceData, int waitTime = 10000)
        {
            // Build statistics endpoint query param dictionary
            Dictionary <string, string> statisticsQueryParams = new Dictionary <string, string>()
            {
                { "instanceId", postInstanceData.InstanceId }
            };

            Wait.ForPredefinedTime(waitTime); // Wait for some trades to be done
            Response statisticsResponse = await apiConsumer.ExecuteRequest(statisticsPath, statisticsQueryParams, null, Method.GET);

            Assert.That(statisticsResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            return(JsonUtils.DeserializeJson <StatisticsDTO>(statisticsResponse.ResponseJson));
        }
        private async Task PrepareTestData()
        {
            var TestClient = await Consumer.RegisterNewUser();

            TestClientId = TestClient.Account.Id;
            var walletsFromDB    = this.WalletRepository.GetAllAsync(w => w.ClientId == TestClientId && w.State != "deleted");
            var operationsFromDB = this.OperationsRepository.GetAllAsync(o => o.PartitionKey == OperationsEntity.GeneratePartitionKey() && o.ClientId.ToString() == TestClientId);

            this.TestAssetId      = Constants.TestAssetId;
            this.AssetPrecission  = 2;
            this.AllWalletsFromDb = (await walletsFromDB).Cast <WalletEntity>().ToList();
            this.TestWallet       = await CreateTestWallet();

            //fill wallet with funds
            await MEConsumer.Client.UpdateBalanceAsync(Guid.NewGuid().ToString(), TestWallet.Id, Constants.TestAssetId, 50.0);

            this.TestWalletWithBalanceId = TestWallet.Id;


            this.TestWalletDelete = await CreateTestWallet();

            this.TestWalletAccount = await AccountRepository.TryGetAsync(TestWallet.Id) as AccountEntity;

            this.TestWalletOperations = await CreateTestWallet();

            this.TestWalletRegenerateKey = await CreateTestWallet(true);

            this.TestOperation = await CreateTestOperation();

            this.TestOperationCancel = await CreateTestOperation();

            this.TestOperationCreateDetails = await CreateTestOperation();

            this.TestOperationRegisterDetails = await CreateTestOperation();


            this.ClientInfoConsumer = new ApiConsumer(_apiV2Settings);
            await this.ClientInfoConsumer.RegisterNewUser();

            AddOneTimeCleanupAction(async() => await ClientAccounts.DeleteClientAccount(ClientInfoConsumer.ClientInfo.Account.Id));

            // set the id to the default one in case it has been changed by any test
            BaseAssetDTO body     = new BaseAssetDTO(this.TestAssetId);
            var          response = await Consumer.ExecuteRequest(ApiPaths.ASSETS_BASEASSET_PATH, Helpers.EmptyDictionary, JsonUtils.SerializeObject(body), Method.POST);
        }
Exemplo n.º 5
0
        public async Task ClaimInvitationLink()
        {
            await this.PrepareClainInvitationLink();

            var url = $"{ApiPaths.REFERRAL_LINKS_PATH}/{GlobalConstants.AutoTest}/claim";

            //send request without data
            var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NotFound);

            var body = new InvitationLinkClaimDTO()
            {
                ReferalLinkUrl = GlobalConstants.AutoTest,
                IsNewClient    = false
            };

            //send request with wrong data
            response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(body), Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NotFound);



            //Create link to be claimed
            var         createLinkUrl      = ApiPaths.REFERRAL_LINKS_INVITATION_PATH;
            ApiConsumer createLinkConsumer = this.InvitationLinkClaimersConsumers[0];

            this.InvitationLinkClaimersConsumers.RemoveAt(0);

            var createLinkResponse = await createLinkConsumer.ExecuteRequest(createLinkUrl, Helpers.EmptyDictionary, null, Method.POST);

            Assert.True(createLinkResponse.Status == HttpStatusCode.Created);
            var createdLink = JsonUtils.DeserializeJson <RequestInvitationLinkResponseDto>(createLinkResponse.ResponseJson);

            body = new InvitationLinkClaimDTO()
            {
                ReferalLinkUrl = createdLink.RefLinkUrl,
                IsNewClient    = true
            };
            string claimParam = JsonUtils.SerializeObject(body);

            url = $"{ApiPaths.REFERRAL_LINKS_INVITATION_PATH}/{createdLink.RefLinkId}/claim";

            for (int i = 0; i < this.InvitationLinkClaimersConsumers.Count; i++)
            {
                ApiConsumer claimConsumer = this.InvitationLinkClaimersConsumers[i];
                var         claimResponse = await claimConsumer.ExecuteRequest(url, Helpers.EmptyDictionary, claimParam, Method.PUT);

                InvitationLinkClaimResponseDTO parsedClaimResponse = JsonUtils.DeserializeJson <InvitationLinkClaimResponseDTO>(claimResponse.ResponseJson);

                ClientBalanceResponseModel senderBalance   = null;
                ClientBalanceResponseModel recieverBalance = null;

                if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                {
                    List <ClientBalanceResponseModel> senderBalances = (await this.BalancesClient.GetClientBalances(createLinkConsumer.ClientInfo.Account.Id)).ToList();
                    senderBalance = senderBalances.Where(b => b.AssetId == Constants.TREE_COIN_ID).FirstOrDefault();

                    List <ClientBalanceResponseModel> recieverBalances = (await this.BalancesClient.GetClientBalances(claimConsumer.ClientInfo.Account.Id)).ToList();
                    recieverBalance = recieverBalances.Where(b => b.AssetId == Constants.TREE_COIN_ID).FirstOrDefault();
                }

                var statisticsResponse = await createLinkConsumer.ExecuteRequest($"{ApiPaths.REFERRAL_LINKS_PATH}/statistics", Helpers.EmptyDictionary, null, Method.GET);

                RefLinksStatisticsDTO linkStatistics = JsonUtils.DeserializeJson <RefLinksStatisticsDTO>(statisticsResponse.ResponseJson);

                //assert first five claimers should claim successfully and recieve reward
                if (i < 6)
                {
                    //Assert.True(Guid.TryParse(parsedClaimResponse.TransactionRewardSender, out Guid temp1));
                    //Assert.True(Guid.TryParse(parsedClaimResponse.TransactionRewardRecipient, out Guid temp2));
                    if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                    {
                        Assert.True(senderBalance.Balance == (i + 1) * Constants.TREE_COIN_INVIRATION_AWARD);
                        Assert.True(recieverBalance.Balance == Constants.TREE_COIN_INVIRATION_AWARD);
                    }
                }
                else
                {
                    //Assert.Null(parsedClaimResponse.TransactionRewardSender);
                    //Assert.Null(parsedClaimResponse.TransactionRewardRecipient);
                    if (Constants.TREE_COIN_INVIRATION_AWARD != 0.0)
                    {
                        Assert.True(senderBalance.Balance == 5 * Constants.TREE_COIN_INVIRATION_AWARD);
                        Assert.Null(recieverBalance);
                    }
                }

                Assert.True(linkStatistics.NumberOfInvitationLinksAccepted == i + 1);

                //attempt to claim again with single user should result in error
                if (i == 0)
                {
                    var secondClaimResponse = await claimConsumer.ExecuteRequest(url, Helpers.EmptyDictionary, claimParam, Method.POST);

                    Assert.True(secondClaimResponse.Status != HttpStatusCode.OK);
                }
            }
        }