Skip to content

Commit

Permalink
Merge pull request #3396 from AElfProject/hotfix/increase-backup-subs…
Browse files Browse the repository at this point in the history
…idy-totalshare

Increase backup subsidy total share
  • Loading branch information
jason-aelf authored Apr 18, 2023
2 parents b4df4f6 + 6be5cd9 commit a0804d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contract/AElf.Contracts.Profit/ProfitContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,16 @@ public override Empty ContributeProfits(ContributeProfitsInput input)

return new Empty();
}

public override Empty IncreaseBackupSubsidyTotalShare(Hash schemeId)
{
Assert(!State.BackupSubsidyTotalShareIncreased.Value, "Already increased");
State.BackupSubsidyTotalShareIncreased.Value = true;
var scheme = State.SchemeInfos[schemeId];
scheme.TotalShares = scheme.TotalShares.Add(1);
State.SchemeInfos[schemeId] = scheme;
return new Empty();
}

public override Empty ResetManager(ResetManagerInput input)
{
Expand Down
2 changes: 2 additions & 0 deletions contract/AElf.Contracts.Profit/ProfitContractState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public partial class ProfitContractState : ContractState
public MappedState<string, MethodFees> TransactionFees { get; set; }

public SingletonState<AuthorityInfo> MethodFeeController { get; set; }

public BoolState BackupSubsidyTotalShareIncreased { get; set; }
}
4 changes: 4 additions & 0 deletions protobuf/profit_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ service ProfitContract {
rpc RemoveSubScheme (RemoveSubSchemeInput) returns (google.protobuf.Empty) {
}

// Increase backup subsidy TotalShare
rpc IncreaseBackupSubsidyTotalShare (aelf.Hash) returns (google.protobuf.Empty) {
}

// Reset the manager of a scheme.
rpc ResetManager (ResetManagerInput) returns (google.protobuf.Empty) {
}
Expand Down
13 changes: 13 additions & 0 deletions test/AElf.Contracts.Profit.Tests/ProfitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,19 @@ await ProfitContractStub.ClaimProfits.SendAsync(new ClaimProfitsInput
details.Details.First().LastProfitPeriod.ShouldBe(scheme.CurrentPeriod);
}
}

[Fact]
public async Task IncreaseBackupSubsidyTotalShare_Test()
{
var schemeId = await CreateSchemeAsync();
var scheme = await ProfitContractStub.GetScheme.CallAsync(schemeId);
scheme.TotalShares.ShouldBe(0);
await ProfitContractStub.IncreaseBackupSubsidyTotalShare.SendAsync(schemeId);
scheme = await ProfitContractStub.GetScheme.CallAsync(schemeId);
scheme.TotalShares.ShouldBe(1);
var result = await ProfitContractStub.IncreaseBackupSubsidyTotalShare.SendWithExceptionAsync(schemeId);
result.TransactionResult.Error.ShouldContain("Already increased");
}

private async Task ContributeProfits(Hash schemeId, long amount = 100)
{
Expand Down

0 comments on commit a0804d7

Please sign in to comment.