Пример #1
0
        public async Task TransferAuthorizationForTokenConvert_Test()
        {
            var newParliament = new Parliament.CreateOrganizationInput
            {
                ProposerAuthorityRequired = false,
                ProposalReleaseThreshold  = new Acs3.ProposalReleaseThreshold
                {
                    MaximalAbstentionThreshold = 1,
                    MaximalRejectionThreshold  = 1,
                    MinimalApprovalThreshold   = 1,
                    MinimalVoteThreshold       = 1
                },
                ParliamentMemberProposingAllowed = false
            };
            var createNewParliament =
                (await ParliamentContractStub.CreateOrganization.SendAsync(newParliament)).TransactionResult;

            createNewParliament.Status.ShouldBe(TransactionResultStatus.Mined);
            var calculatedNewParliamentAddress = await ParliamentContractStub.CalculateOrganizationAddress.CallAsync(newParliament);

            var newAuthority = new Acs1.AuthorityInfo
            {
                ContractAddress = ParliamentContractAddress,
                OwnerAddress    = calculatedNewParliamentAddress
            };

            await ExecuteProposalTransaction(Tester, TokenConverterContractAddress, nameof(TokenConverterContractContainer.TokenConverterContractStub.ChangeConnectorController), newAuthority);

            var controller = await TokenConverterContractStub.GetControllerForManageConnector.CallAsync(new Empty());

            controller.OwnerAddress.ShouldBe(calculatedNewParliamentAddress);
        }
Пример #2
0
        public async Task Authorization_Transfer_Success()
        {
            await InitialTokenContract();

            var defaultOrganizationAddress =
                await ParliamentStubs.First().GetDefaultOrganizationAddress.CallAsync(new Empty());

            var newParliament = new Parliament.CreateOrganizationInput
            {
                ProposerAuthorityRequired = false,
                ProposalReleaseThreshold  = new ProposalReleaseThreshold
                {
                    MaximalAbstentionThreshold = 1,
                    MaximalRejectionThreshold  = 1,
                    MinimalApprovalThreshold   = 1,
                    MinimalVoteThreshold       = 1
                },
                ParliamentMemberProposingAllowed = false
            };
            var parliamentStub         = ParliamentStubs.First();
            var createNewParliamentRet = await parliamentStub.CreateOrganization.SendAsync(newParliament);

            var newParliamentAddress = new Address();

            newParliamentAddress.MergeFrom(createNewParliamentRet.TransactionResult.ReturnValue);
            var authority = new Acs1.AuthorityInfo
            {
                ContractAddress = ContractAddresses[ParliamentSmartContractAddressNameProvider.Name],
                OwnerAddress    = newParliamentAddress
            };
            var sideCreator          = Address.FromPublicKey(SampleECKeyPairs.KeyPairs[0].PublicKey);
            var parliamentOrgAddress = defaultOrganizationAddress;
            var twoProposers         = new List <Address> {
                parliamentOrgAddress, sideCreator
            };
            var createOrganizationInput2 = new CreateOrganizationInput
            {
                ProposerWhiteList = new ProposerWhiteList
                {
                    Proposers = { twoProposers }
                },
                OrganizationMemberList = new OrganizationMemberList
                {
                    OrganizationMembers = { twoProposers }
                },
                ProposalReleaseThreshold = new ProposalReleaseThreshold
                {
                    MinimalApprovalThreshold   = twoProposers.Count,
                    MinimalVoteThreshold       = twoProposers.Count,
                    MaximalRejectionThreshold  = 0,
                    MaximalAbstentionThreshold = 0
                }
            };

            var associationAddressRet = (await AssociationStub.CreateOrganization.SendAsync(createOrganizationInput2)).TransactionResult;
            var associationAddress    = new Address();

            associationAddress.MergeFrom(associationAddressRet.ReturnValue);
            var toAssociationProposal = new CreateProposalInput
            {
                ToAddress = ContractAddresses[TokenSmartContractAddressNameProvider.Name],
                // ContractMethodName = nameof(TokenContractContainer.TokenContractStub.ChangeSideChainParliamentController),
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub.ChangeSideChainParliamentController),
                Params              = authority.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = associationAddress
            };
            var associationProposalRet = (await AssociationStub.CreateProposal.SendAsync(toAssociationProposal)).TransactionResult;
            var associationProposalId  = new Hash();

            associationProposalId.MergeFrom(associationProposalRet.ReturnValue);

            await ParliamentReachAnAgreementAsync(new CreateProposalInput
            {
                ToAddress           = ContractAddresses[AssociationSmartContractAddressNameProvider.Name],
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Approve),
                Params              = associationProposalId.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = parliamentOrgAddress
            });

            await AssociationStub.Approve.SendAsync(associationProposalId);

            await AssociationStub.Release.SendAsync(associationProposalId);

            twoProposers = new List <Address> {
                newParliamentAddress, sideCreator
            };
            createOrganizationInput2 = new CreateOrganizationInput
            {
                ProposerWhiteList = new ProposerWhiteList
                {
                    Proposers = { twoProposers }
                },
                OrganizationMemberList = new OrganizationMemberList
                {
                    OrganizationMembers = { twoProposers }
                },
                ProposalReleaseThreshold = new ProposalReleaseThreshold
                {
                    MinimalApprovalThreshold   = twoProposers.Count,
                    MinimalVoteThreshold       = twoProposers.Count,
                    MaximalRejectionThreshold  = 0,
                    MaximalAbstentionThreshold = 0
                }
            };
            associationAddressRet = (await AssociationStub.CreateOrganization.SendAsync(createOrganizationInput2)).TransactionResult;
            associationAddress    = new Address();
            associationAddress.MergeFrom(associationAddressRet.ReturnValue);
            var updateParam = new UpdateRentedResourcesInput();
            var symbolDic   = new Dictionary <string, int> {
                ["CPU"] = 101
            };

            updateParam.ResourceAmount.Add(symbolDic);
            toAssociationProposal = new CreateProposalInput
            {
                ToAddress           = ContractAddresses[TokenSmartContractAddressNameProvider.Name],
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub.UpdateRentedResources),
                Params              = updateParam.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = associationAddress
            };
            associationProposalRet = (await AssociationStub.CreateProposal.SendAsync(toAssociationProposal)).TransactionResult;
            associationProposalId  = new Hash();
            associationProposalId.MergeFrom(associationProposalRet.ReturnValue);

            await ParliamentReachAnAgreementAsync(new CreateProposalInput
            {
                ToAddress           = ContractAddresses[AssociationSmartContractAddressNameProvider.Name],
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Approve),
                Params              = associationProposalId.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = newParliamentAddress
            });

            await AssociationStub.Approve.SendAsync(associationProposalId);

            await AssociationStub.Release.SendAsync(associationProposalId);

            var resourceUsage = await TokenStub.GetResourceUsage.CallAsync(new Empty());

            resourceUsage.Value["CPU"].ShouldBe(101);
        }