Beispiel #1
0
        public override Empty SetSymbolsToPayTxSizeFee(SymbolListToPayTxSizeFee input)
        {
            AssertControllerForSymbolToPayTxSizeFee();
            Assert(input != null, "invalid input");
            bool isPrimaryTokenExist = false;
            var  symbolList          = new List <string>();
            var  primaryTokenSymbol  = GetPrimaryTokenSymbol(new Empty());

            Assert(!string.IsNullOrEmpty(primaryTokenSymbol.Value), "primary token does not exist");
            foreach (var tokenInfo in input.SymbolsToPayTxSizeFee)
            {
                if (tokenInfo.TokenSymbol == primaryTokenSymbol.Value)
                {
                    isPrimaryTokenExist = true;
                    Assert(tokenInfo.AddedTokenWeight == 1 && tokenInfo.BaseTokenWeight == 1,
                           $"symbol:{tokenInfo.TokenSymbol} weight should be 1");
                }

                AssertSymbolToPayTxFeeIsValid(tokenInfo);
                Assert(!symbolList.Contains(tokenInfo.TokenSymbol), $"symbol:{tokenInfo.TokenSymbol} repeat");
                symbolList.Add(tokenInfo.TokenSymbol);
            }

            Assert(isPrimaryTokenExist, $"primary token:{primaryTokenSymbol.Value} not included");
            State.SymbolListToPayTxSizeFee.Value = input;
            Context.Fire(new ExtraTokenListModified
            {
                SymbolListToPayTxSizeFee = input
            });
            return(new Empty());
        }
Beispiel #2
0
        public async Task ChangeSymbolsToPayTXSizeFeeController_Success_Test()
        {
            var primaryToken = await TokenContractStub.GetPrimaryTokenSymbol.CallAsync(new Empty());

            var newSymbolList = new SymbolListToPayTxSizeFee();

            newSymbolList.SymbolsToPayTxSizeFee.Add(new SymbolToPayTxSizeFee
            {
                TokenSymbol      = primaryToken.Value,
                AddedTokenWeight = 1,
                BaseTokenWeight  = 1
            });

            // create a new organization to be replace the controller of SetSymbolsToPayTxSizeFee
            var newAuthority = await CreateNewParliamentAddressAsync();

            // get the default parliament that is the controller of SetSymbolsToPayTxSizeFee
            var defaultParliamentAddress = await GetDefaultParliamentAddressAsync();

            // create a proposal to replace the controller
            var createProposalInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = newAuthority.ToByteString(),
                OrganizationAddress = defaultParliamentAddress,
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub
                                             .ChangeSymbolsToPayTXSizeFeeController),
                ExpiredTime = TimestampHelper.GetUtcNow().AddHours(1)
            };

            await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(createProposalInput);

            // the new controller try to send SetSymbolsToPayTxSizeFee
            var updateInput = new CreateProposalInput
            {
                ToAddress           = TokenContractAddress,
                Params              = newSymbolList.ToByteString(),
                OrganizationAddress = newAuthority.OwnerAddress,
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub.SetSymbolsToPayTxSizeFee),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddHours(1)
            };

            await MainChainTesterCreatApproveAndReleaseProposalForParliamentAsync(updateInput);

            var symbolSet = await TokenContractStub.GetSymbolsToPayTxSizeFee.CallAsync(new Empty());

            symbolSet.SymbolsToPayTxSizeFee.Count.ShouldBe(1);
        }
Beispiel #3
0
        public async Task ChargeTransactionFees_With_Different_Transaction_Size_Fee_Token(int[] order, long[] balance,
                                                                                          int[] baseWeight, int[] tokenWeight, long sizeFee, string chargeSymbol, long chargeAmount, bool isSuccess)
        {
            await SetPrimaryTokenSymbolAsync();

            var methodName     = nameof(TokenContractContainer.TokenContractStub.Transfer);
            var basicMethodFee = 1000;
            var methodFee      = new MethodFees
            {
                MethodName = methodName,
                Fees       =
                {
                    new MethodFee
                    {
                        Symbol   = NativeTokenSymbol,
                        BasicFee = basicMethodFee
                    }
                }
            };

            await SubmitAndPassProposalOfDefaultParliamentAsync(TokenContractAddress,
                                                                nameof(TokenContractImplContainer.TokenContractImplStub.SetMethodFee), methodFee);

            var tokenSymbolList   = new [] { NativeTokenSymbol, "CWJ", "YPA" };
            var tokenCount        = 3;
            var orderedSymbolList = new string[tokenCount];
            var index             = 0;

            foreach (var o in order)
            {
                orderedSymbolList[index++] = tokenSymbolList[o - 1];
            }

            var sizeFeeSymbolList = new SymbolListToPayTxSizeFee();

            for (var i = 0; i < tokenCount; i++)
            {
                var tokenSymbol = orderedSymbolList[i];
                if (tokenSymbol != NativeTokenSymbol)
                {
                    await CreateTokenAsync(DefaultSender, tokenSymbol);
                }
                if (balance[i] > 0)
                {
                    await IssueTokenAsync(tokenSymbol, balance[i]);
                }
                sizeFeeSymbolList.SymbolsToPayTxSizeFee.Add(new SymbolToPayTxSizeFee
                {
                    TokenSymbol      = tokenSymbol,
                    AddedTokenWeight = tokenWeight[i],
                    BaseTokenWeight  = baseWeight[i]
                });
            }

            await SubmitAndPassProposalOfDefaultParliamentAsync(TokenContractAddress,
                                                                nameof(TokenContractImplContainer.TokenContractImplStub.SetSymbolsToPayTxSizeFee), sizeFeeSymbolList);

            var beforeBalanceList = await GetDefaultBalancesAsync(orderedSymbolList);

            var chargeTransactionFeesInput = new ChargeTransactionFeesInput
            {
                MethodName         = methodName,
                ContractAddress    = TokenContractAddress,
                TransactionSizeFee = sizeFee,
            };

            chargeTransactionFeesInput.SymbolsToPayTxSizeFee.AddRange(sizeFeeSymbolList.SymbolsToPayTxSizeFee);

            var chargeFeeRet = await TokenContractStub.ChargeTransactionFees.SendAsync(chargeTransactionFeesInput);

            chargeFeeRet.Output.Success.ShouldBe(isSuccess);
            var afterBalanceList = await GetDefaultBalancesAsync(orderedSymbolList);

            for (var i = 0; i < tokenCount; i++)
            {
                var balanceDiff = beforeBalanceList[i] - afterBalanceList[i];
                if (orderedSymbolList[i] == chargeSymbol)
                {
                    balanceDiff.ShouldBe(chargeAmount);
                }
                else
                {
                    if (orderedSymbolList[i] == NativeTokenSymbol)
                    {
                        balanceDiff -= basicMethodFee;
                    }
                    balanceDiff.ShouldBe(0);
                }
            }
        }