Example #1
0
        public async Task SetReceiver_Test()
        {
            // without authorized
            {
                var setReceiverRet = await TokenContractStub.SetFeeReceiver.SendWithExceptionAsync(new Address());

                setReceiverRet.TransactionResult.Error.ShouldContain("No permission");
            }

            var methodName   = nameof(TokenContractImplContainer.TokenContractImplStub.InitializeFromParentChain);
            var initialInput = new InitializeFromParentChainInput
            {
                Creator = DefaultAddress,
                RegisteredOtherTokenContractAddresses = { { 1, TokenContractAddress } }
            };

            await SubmitAndApproveProposalOfDefaultParliament(TokenContractAddress, methodName, initialInput);

            await TokenContractStub.SetFeeReceiver.SendAsync(DefaultAddress);

            var feeReceiver = await TokenContractStub.GetFeeReceiver.CallAsync(new Empty());

            feeReceiver.Value.ShouldBe(DefaultAddress.Value);

            // fee receiver is just allowed to set one time

            var repeatSetRet = await TokenContractStub.SetFeeReceiver.SendWithExceptionAsync(DefaultAddress);

            repeatSetRet.TransactionResult.Error.ShouldContain("Fee receiver already set");
        }
        public override Empty InitializeFromParentChain(InitializeFromParentChainInput input)
        {
            Assert(!State.InitializedFromParentChain.Value, "MultiToken has been initialized");
            State.InitializedFromParentChain.Value = true;
            foreach (var pair in input.ResourceAmount)
            {
                State.ResourceAmount[pair.Key] = pair.Value;
            }

            foreach (var pair in input.RegisteredOtherTokenContractAddresses)
            {
                State.CrossChainTransferWhiteList[pair.Key] = pair.Value;
            }

            SetSideChainCreator(input.Creator);
            return(new Empty());
        }
        private async Task InitialTokenContractAsync(bool issueToken = true)
        {
            await CreateTokenAsync("CPU", ResourceSupply, issueToken);
            await CreateTokenAsync("RAM", ResourceSupply, issueToken);
            await CreateTokenAsync("DISK", ResourceSupply, issueToken);
            await CreateTokenAsync("NET", ResourceSupply, issueToken);

            var defaultParliamentOrganization = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty());

            var setSideChainCreatorProposalInput = new InitializeFromParentChainInput
            {
                ResourceAmount =
                {
                    { "CPU",  CpuAmount  },
                    { "RAM",  RamAmount  },
                    { "DISK", DiskAmount },
                    { "NET",  NetAmount  }
                },
                Creator = Creator
            };

            await ParliamentReachAnAgreementAsync(TokenContractAddress, defaultParliamentOrganization,
                                                  nameof(TokenContractImplContainer.TokenContractImplStub.InitializeFromParentChain),
                                                  setSideChainCreatorProposalInput);

            var updateRentalInput = new UpdateRentalInput
            {
                Rental =
                {
                    { "CPU",  Rental },
                    { "RAM",  Rental },
                    { "DISK", Rental },
                    { "NET",  Rental },
                }
            };
            await TokenContractStub.SetPrimaryTokenSymbol.SendAsync(new SetPrimaryTokenSymbolInput { Symbol = NativeTokenSymbol });

            await TokenContractStub.InitializeAuthorizedController.SendAsync(new Empty());

            await UpdateSideChainRentalDefaultProposalAsync(
                nameof(TokenContractImplContainer.TokenContractImplStub.UpdateRental), updateRentalInput);
        }
Example #4
0
        public async Task ClaimTransactionFee_Balance_With_Receiver_Test()
        {
            var tokenSymbol = "JAN";
            var feeAmount   = 10000;

            await CreateTokenAsync(DefaultSender, tokenSymbol);

            var receiver = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty());

            var input = new InitializeFromParentChainInput
            {
                Creator = receiver
            };

            await SubmitAndPassProposalOfDefaultParliamentAsync(TokenContractAddress,
                                                                nameof(TokenContractImplContainer.TokenContractImplStub.InitializeFromParentChain), input);
            await SubmitAndPassProposalOfDefaultParliamentAsync(TokenContractAddress,
                                                                nameof(TokenContractImplContainer.TokenContractImplStub.SetFeeReceiver), receiver);

            var beforeBurned = await GetTokenSupplyAmount(tokenSymbol);

            var beforeBalance = await GetBalanceAsync(receiver, tokenSymbol);

            var claimFeeInput = new TotalTransactionFeesMap
            {
                Value =
                {
                    { tokenSymbol, feeAmount }
                }
            };
            await TokenContractStub.ClaimTransactionFees.SendAsync(claimFeeInput);

            var afterBurned = await GetTokenSupplyAmount(tokenSymbol);

            var afterBalance = await GetBalanceAsync(receiver, tokenSymbol);

            var shouldBurned = feeAmount.Div(10);

            (beforeBurned - afterBurned).ShouldBe(shouldBurned);
            (afterBalance - beforeBalance).ShouldBe(feeAmount - shouldBurned);
        }