public override Empty UpdateCoefficientsForSender(UpdateCoefficientsInput input) { AssertUserFeeController(); input.Coefficients.FeeTokenType = (int)FeeTypeEnum.Tx; // The only possible for now. UpdateCoefficients(input); return(new Empty()); }
/// <summary> /// Can only update one token at one time. /// </summary> /// <param name="input"></param> /// <returns></returns> public override Empty UpdateCoefficientsForContract(UpdateCoefficientsInput input) { Assert(input.Coefficients.FeeTokenType != (int)FeeTypeEnum.Tx, "Invalid fee type."); AssertDeveloperFeeController(); UpdateCoefficients(input); return(new Empty()); }
public async Task Update_Coefficient_For_Sender_Test(bool isFail, int[] pieceNumber, params int[][] newPieceFunctions) { var feeType = (int)FeeTypeEnum.Tx; var primaryTokenSymbol = await GetThePrimaryTokenAsync(); await IssuePrimaryTokenToMainChainTesterAsync(); var originalCoefficients = await GetCalculateFeeCoefficientsByFeeTypeAsync(feeType); var newPieceCoefficientList = newPieceFunctions.Select(x => new CalculateFeePieceCoefficients { Value = { x } }).ToList(); var updateInput = new UpdateCoefficientsInput { PieceNumbers = { pieceNumber }, Coefficients = new CalculateFeeCoefficients { FeeTokenType = feeType, } }; updateInput.Coefficients.PieceCoefficientsList.AddRange(newPieceCoefficientList); var proposalId = await CreateToRootForUserFeeByTwoLayerAsync(updateInput, nameof(TokenContractImplContainer.TokenContractImplStub.UpdateCoefficientsForSender)); await ApproveToRootForUserFeeByTwoLayerAsync(proposalId); await VoteToReferendumAsync(proposalId, primaryTokenSymbol); await ReleaseToRootForUserFeeByTwoLayerAsync(proposalId); var updatedCoefficients = await GetCalculateFeeCoefficientsByFeeTypeAsync(feeType); if (!isFail) { foreach (var newPieceFunction in newPieceFunctions) { var hasModified = GetCalculateFeePieceCoefficients(updatedCoefficients.PieceCoefficientsList, newPieceFunction[0]); var newCoefficient = newPieceFunction.Skip(1).ToArray(); hasModified.Value.Skip(1).ShouldBe(newCoefficient); } } else { var pieceCount = originalCoefficients.PieceCoefficientsList.Count; updatedCoefficients.PieceCoefficientsList.Count.ShouldBe(pieceCount); for (var i = 0; i < pieceCount; i++) { originalCoefficients.PieceCoefficientsList[i] .ShouldBe(updatedCoefficients.PieceCoefficientsList[i]); } } }
public async Task Update_Coefficient_For_Contract_Test(bool isFail, int feeType, int[] pieceNumber, params int[][] newPieceFunctions) { var originalCoefficients = await GetCalculateFeeCoefficientsByFeeTypeAsync(feeType); var newPieceCoefficientList = newPieceFunctions.Select(x => new CalculateFeePieceCoefficients { Value = { x } }).ToList(); var updateInput = new UpdateCoefficientsInput { PieceNumbers = { pieceNumber }, Coefficients = new CalculateFeeCoefficients { FeeTokenType = feeType, } }; updateInput.Coefficients.PieceCoefficientsList.AddRange(newPieceCoefficientList); var proposalId = await CreateToRootForDeveloperFeeByTwoLayerAsync(updateInput, nameof(TokenContractImplContainer.TokenContractImplStub.UpdateCoefficientsForContract)); await ApproveToRootForDeveloperFeeByTwoLayerAsync(proposalId); var middleApproveProposalId = await ApproveToRootForDeveloperFeeByMiddleLayerAsync(proposalId); await ApproveThenReleaseMiddleProposalForDeveloperAsync(middleApproveProposalId); await ReleaseToRootForDeveloperFeeByTwoLayerAsync(proposalId); var updatedCoefficients = await GetCalculateFeeCoefficientsByFeeTypeAsync(feeType); if (!isFail) { foreach (var newPieceFunction in newPieceFunctions) { var hasModified = GetCalculateFeePieceCoefficients(updatedCoefficients.PieceCoefficientsList, newPieceFunction[0]); var newCoefficient = newPieceFunction.Skip(1).ToArray(); hasModified.Value.Skip(1).ShouldBe(newCoefficient); } } else { var pieceCount = originalCoefficients.PieceCoefficientsList.Count; updatedCoefficients.PieceCoefficientsList.Count.ShouldBe(pieceCount); for (var i = 0; i < pieceCount; i++) { originalCoefficients.PieceCoefficientsList[i] .ShouldBe(updatedCoefficients.PieceCoefficientsList[i]); } } }
public async Task UpdateCoefficientForContract_With_Invalid_FeeType_Test() { await CreatePrimaryTokenAsync(); var updateInfo = new UpdateCoefficientsInput { Coefficients = new CalculateFeeCoefficients { FeeTokenType = (int)FeeTypeEnum.Tx } }; var initializeControllerRet = await TokenContractStub.InitializeAuthorizedController.SendAsync(new Empty()); initializeControllerRet.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined); var updateRet = await TokenContractStub.UpdateCoefficientsForContract.SendWithExceptionAsync(updateInfo); updateRet.TransactionResult.Error.ShouldContain("Invalid fee type"); }
private void UpdateCoefficients(UpdateCoefficientsInput input) { var feeType = input.Coefficients.FeeTokenType; var currentAllCoefficients = State.AllCalculateFeeCoefficients.Value; // Get coefficients for specific fee type. var currentCoefficients = currentAllCoefficients.Value.SingleOrDefault(x => x.FeeTokenType == feeType); Assert(currentCoefficients != null, "Specific fee type not existed before."); var inputPieceCoefficientsList = input.Coefficients.PieceCoefficientsList; // ReSharper disable once PossibleNullReferenceException var currentPieceCoefficientList = currentCoefficients.PieceCoefficientsList; var inputPieceCount = input.PieceNumbers.Count; Assert(inputPieceCount == inputPieceCoefficientsList.Count, "Piece numbers not match."); foreach (var coefficients in inputPieceCoefficientsList) { AssertCoefficientsValid(coefficients); } for (var i = 0; i < inputPieceCount; i++) { Assert(currentPieceCoefficientList.Count >= input.PieceNumbers[i], "Piece number exceeded."); var pieceIndex = input.PieceNumbers[i].Sub(1); var pieceCoefficients = inputPieceCoefficientsList[i]; currentPieceCoefficientList[pieceIndex] = pieceCoefficients; } AssertPieceUpperBoundsIsInOrder(currentPieceCoefficientList); State.AllCalculateFeeCoefficients.Value = currentAllCoefficients; Context.Fire(new CalculateFeeAlgorithmUpdated { AllTypeFeeCoefficients = currentAllCoefficients }); }
public async Task UpdateCoefficientForContract_Without_Authorization_Test() { await CreatePrimaryTokenAsync(); var updateInfo = new UpdateCoefficientsInput { Coefficients = new CalculateFeeCoefficients { FeeTokenType = (int)FeeTypeEnum.Read } }; var updateRet = await TokenContractStub.UpdateCoefficientsForContract.SendWithExceptionAsync(updateInfo); updateRet.TransactionResult.Error.ShouldContain( "controller does not initialize, call InitializeAuthorizedController first"); var initializeControllerRet = await TokenContractStub.InitializeAuthorizedController.SendAsync(new Empty()); initializeControllerRet.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined); updateRet = await TokenContractStub.UpdateCoefficientsForContract.SendWithExceptionAsync(updateInfo); updateRet.TransactionResult.Error.ShouldContain("no permission"); }