Example #1
0
        GenerateTokenInitializationCallList()
        {
            var tokenContractCallList = new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList();

            tokenContractCallList.Add(nameof(TokenContract.Create), new CreateInput
            {
                Symbol        = TokenHolderContractTestConstants.NativeTokenSymbol,
                Decimals      = 8,
                IsBurnable    = true,
                TokenName     = "elf token",
                TotalSupply   = TokenHolderContractTestConstants.NativeTokenTotalSupply,
                Issuer        = Starter,
                LockWhiteList =
                {
                    ProfitContractAddress,
                    TokenHolderContractAddress
                }
            });
            tokenContractCallList.Add(nameof(TokenContract.SetPrimaryTokenSymbol),
                                      new SetPrimaryTokenSymbolInput {
                Symbol = "ELF"
            });
            tokenContractCallList.Add(nameof(TokenContract.Issue), new IssueInput
            {
                Symbol = TokenHolderContractTestConstants.NativeTokenSymbol,
                Amount = (long)(TokenHolderContractTestConstants.NativeTokenTotalSupply * 0.12),
                To     = Address.FromPublicKey(StarterKeyPair.PublicKey),
                Memo   = "Issue token to default user for vote.",
            });

            UserKeyPairs.ForEach(creatorKeyPair => tokenContractCallList.Add(nameof(TokenContract.Issue),
                                                                             new IssueInput
            {
                Symbol = TokenHolderContractTestConstants.NativeTokenSymbol,
                Amount = (long)(TokenHolderContractTestConstants.NativeTokenTotalSupply * 0.1),
                To     = Address.FromPublicKey(creatorKeyPair.PublicKey),
                Memo   = "set voters few amount for voting."
            }));

            return(tokenContractCallList);
        }
Example #2
0
        protected void InitializeContracts()
        {
            BasicContractZeroStub = GetContractZeroTester(StarterKeyPair);

            ProfitContractAddress = AsyncHelper.RunSync(() =>
                                                        BasicContractZeroStub.DeploySystemSmartContract.SendAsync(
                                                            new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(ProfitContract).Assembly.Location)),
                Name     = ProfitSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateProfitInitializationCallList()
            })).Output;
            ProfitContractStub = GetProfitContractTester(StarterKeyPair);

            //deploy token holder contract
            TokenHolderContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                             .DeploySystemSmartContract.SendAsync(
                                                                 new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenHolderContract).Assembly.Location)),
                Name     = TokenHolderSmartContractAddressNameProvider.Name,
                TransactionMethodCallList =
                    new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList()
            })).Output;
            TokenHolderContractStub = GetTokenHolderContractTester(StarterKeyPair);

            //deploy token contract
            TokenContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                       .DeploySystemSmartContract.SendAsync(
                                                           new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(TokenContract).Assembly.Location)),
                Name     = TokenSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateTokenInitializationCallList()
            })).Output;
            TokenContractStub = GetTokenContractTester(StarterKeyPair);

            //deploy parliament auth contract
            ParliamentContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                            .DeploySystemSmartContract.SendAsync(
                                                                new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(ParliamentContract).Assembly.Location)),
                Name     = ParliamentSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateParliamentInitializationCallList()
            })).Output;
            ParliamentContractStub = GetParliamentContractTester(StarterKeyPair);

            ConsensusContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                           .DeploySystemSmartContract.SendAsync(
                                                               new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(AEDPoSContract).Assembly.Location)),
                Name     = ConsensusSmartContractAddressNameProvider.Name,
                TransactionMethodCallList = GenerateConsensusInitializationCallList()
            })).Output;
            AEDPoSContractStub = GetConsensusContractTester(StarterKeyPair);

            //deploy DApp contract
            DAppContractAddress = AsyncHelper.RunSync(() => GetContractZeroTester(StarterKeyPair)
                                                      .DeploySystemSmartContract.SendAsync(
                                                          new SystemContractDeploymentInput
            {
                Category = KernelConstants.CodeCoverageRunnerCategory,
                Code     = ByteString.CopyFrom(File.ReadAllBytes(typeof(DAppContract).Assembly.Location)),
                Name     = DappSmartContractAddressNameProvider.Name,
                TransactionMethodCallList =
                    new SystemContractDeploymentInput.Types.SystemTransactionMethodCallList
                {
                    Value =
                    {
                        new SystemContractDeploymentInput.Types.SystemTransactionMethodCall
                        {
                            MethodName = nameof(DAppContractStub.InitializeForUnitTest),
                            Params     = new AElf.Contracts.TestContract.DApp.InitializeInput
                            {
                                ProfitReceiver = Address.FromPublicKey(UserKeyPairs[1].PublicKey)
                            }.ToByteString()
                        }
                    }
                }
            })).Output;
            DAppContractStub = GetTester <DAppContainer.DAppStub>(DAppContractAddress,
                                                                  UserKeyPairs.First());
        }
Example #3
0
        public async Task DistributeProfits_ClaimWithTokenHolderContract()
        {
            await AddBeneficiaryTest();

            await TokenHolderContractStub.DistributeProfits.SendAsync(new DistributeProfitsInput
            {
                SchemeManager = Starter,
                AmountsMap    = { { "ELF", 0L } }
            });

            {
                var balance = (await TokenContractStub.GetBalance.CallAsync(new GetBalanceInput
                {
                    Owner = UserAddresses.First(),
                    Symbol = "ELF"
                })).Balance;
                balance.ShouldBe((long)(TokenHolderContractTestConstants.NativeTokenTotalSupply * 0.1));
            }

            var userTokenHolderStub =
                GetTester <TokenHolderContractContainer.TokenHolderContractStub>(TokenHolderContractAddress, UserKeyPairs.First());
            await userTokenHolderStub.ClaimProfits.SendAsync(new ClaimProfitsInput
            {
                SchemeManager = Starter,
            });

            {
                var balance = (await TokenContractStub.GetBalance.CallAsync(new GetBalanceInput
                {
                    Owner = UserAddresses.First(),
                    Symbol = "ELF"
                })).Balance;
                balance.ShouldBe((long)(TokenHolderContractTestConstants.NativeTokenTotalSupply * 0.1) + 10000);
            }
        }
Example #4
0
        public async Task DistributeProfits_Without_Authority_Test()
        {
            await TokenHolderContractStub.CreateScheme.SendAsync(new CreateTokenHolderProfitSchemeInput
            {
                Symbol = "Test"
            });

            var senderWithoutAuthority =
                GetTester <TokenHolderContractImplContainer.TokenHolderContractImplStub>(TokenHolderContractAddress,
                                                                                         UserKeyPairs.First());
            var distributeRet = await senderWithoutAuthority.DistributeProfits.SendWithExceptionAsync(
                new DistributeProfitsInput
            {
                SchemeManager = Starter
            });

            distributeRet.TransactionResult.Error.ShouldContain("No permission to distribute profits");
        }