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); }
public async Task ChangeSIdeChainRentalController_Success() { await InitialTokenContractAsync(); var member = Accounts[0].Address; var proposers = new List <Address> { member }; var newOrganizationCreationInput = new CreateOrganizationInput { OrganizationMemberList = new OrganizationMemberList { OrganizationMembers = { proposers } }, ProposalReleaseThreshold = new ProposalReleaseThreshold { MinimalApprovalThreshold = proposers.Count, MinimalVoteThreshold = proposers.Count, MaximalRejectionThreshold = 0, MaximalAbstentionThreshold = 0 }, ProposerWhiteList = new ProposerWhiteList { Proposers = { proposers } } }; var createNewAssociationOrganization = await AssociationContractStub.CreateOrganization.SendAsync(newOrganizationCreationInput); var newControllerAddress = new Address(); newControllerAddress.MergeFrom(createNewAssociationOrganization.TransactionResult.ReturnValue); var authority = new AuthorityInfo { ContractAddress = AssociationContractAddress, OwnerAddress = newControllerAddress }; await UpdateSideChainRentalDefaultProposalAsync( nameof(TokenContractImplContainer.TokenContractImplStub.ChangeSideChainRentalController), authority); var updateParam = new UpdateRentedResourcesInput(); var symbolDic = new Dictionary <string, int> { ["CPU"] = 101 }; updateParam.ResourceAmount.Add(symbolDic); var updateProposal = new CreateProposalInput { ToAddress = TokenContractAddress, ContractMethodName = nameof(TokenContractImplContainer.TokenContractImplStub.UpdateRentedResources), Params = updateParam.ToByteString(), ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1), OrganizationAddress = newControllerAddress }; var updateProposalRet = (await AssociationContractStub.CreateProposal.SendAsync(updateProposal)) .TransactionResult; var updateProposalId = new Hash(); updateProposalId.MergeFrom(updateProposalRet.ReturnValue); await AssociationContractStub.Approve.SendAsync(updateProposalId); await AssociationContractStub.Release.SendAsync(updateProposalId); var resourceUsage = await TokenContractStub.GetResourceUsage.CallAsync(new Empty()); resourceUsage.Value["CPU"].ShouldBe(101); }