Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor generic delegation #3093

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Action/Guild/ClaimRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void ExecuteWithFixture(IClaimRewardFixture fixture)
// Calculate expected values for comparison with actual values.
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedGuildRepository = new GuildRepository(expectedRepository);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedTotalShares = expectedDelegatee.TotalShares;
var expectedValidatorShare
= expectedRepository.GetBond(expectedDelegatee, validatorKey.Address).Share;
Expand Down Expand Up @@ -346,7 +346,7 @@ var expectedProposerReward
// Then
var validatorRepository = new ValidatorRepository(world, actionContext);
var guildRepository = new GuildRepository(world, actionContext);
var delegatee = validatorRepository.GetValidatorDelegatee(validatorKey.Address);
var delegatee = validatorRepository.GetDelegatee(validatorKey.Address);
var actualRemainGuildReward = world.GetBalance(delegatee.RewardRemainderPoolAddress, GuildAllocateRewardCurrency);
var actualValidatorBalance = world.GetBalance(StakeState.DeriveAddress(validatorKey.Address), DelegationCurrency);
var actualValidatorGuildReward = world.GetBalance(validatorKey.Address, GuildAllocateRewardCurrency);
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/Guild/GuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected static IWorld EnsureToSlashValidator(

var guildRepository = new GuildRepository(
validatorRepository.World, validatorRepository.ActionContext);
var guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress);
var guildDelegatee = guildRepository.GetDelegatee(validatorAddress);
guildDelegatee.Slash(slashFactor, blockHeight, blockHeight);

return guildRepository.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void Execute()

var guildRepository = new GuildRepository(world, new ActionContext { });
var validatorRepository = new ValidatorRepository(world, new ActionContext { });
var guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress);
var validatorDelegatee = validatorRepository.GetValidatorDelegatee(validatorAddress);
var guildDelegatee = guildRepository.GetDelegatee(validatorAddress);
var validatorDelegatee = validatorRepository.GetDelegatee(validatorAddress);

Assert.False(validatorDelegatee.IsActive);
Assert.Equal(ValidatorDelegatee.InactiveDelegationPoolAddress, guildDelegatee.DelegationPoolAddress);
Expand All @@ -55,10 +55,10 @@ public void Execute()

guildRepository = new GuildRepository(world, new ActionContext { });
validatorRepository = new ValidatorRepository(world, new ActionContext { });
guildDelegatee = guildRepository.GetGuildDelegatee(validatorAddress);
validatorDelegatee = validatorRepository.GetValidatorDelegatee(validatorAddress);
guildDelegatee = guildRepository.GetDelegatee(validatorAddress);
validatorDelegatee = validatorRepository.GetDelegatee(validatorAddress);

Assert.True(validatorRepository.GetValidatorDelegatee(validatorAddress).IsActive);
Assert.True(validatorRepository.GetDelegatee(validatorAddress).IsActive);
Assert.Equal(ValidatorDelegatee.ActiveDelegationPoolAddress, guildDelegatee.DelegationPoolAddress);
Assert.Equal(ValidatorDelegatee.ActiveDelegationPoolAddress, validatorDelegatee.DelegationPoolAddress);
Assert.Equal(delegated, world.GetBalance(ValidatorDelegatee.ActiveDelegationPoolAddress, Currencies.GuildGold));
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/StakeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private IWorld Execute(
if (guildRepository.TryGetGuildParticipant(new AgentAddress(signer), out var guildParticipant))
{
var guild = guildRepository.GetGuild(guildParticipant.GuildAddress);
var validator = guildRepository.GetGuildDelegatee(guild.ValidatorAddress);
var validator = guildRepository.GetDelegatee(guild.ValidatorAddress);
var bond = guildRepository.GetBond(validator, signer);
var amountNCG = _ncg * amount;
var expectedGG = DelegationUtil.GetGuildCoinFromNCG(amountNCG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ var expectedProposerReward
}

var validatorAddress = vote.ValidatorPublicKey.Address;
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorAddress);
var actualDelegatee = actualRepository.GetDelegatee(validatorAddress);
var validatorRewardAddress = actualDelegatee.DistributionPoolAddress();
var actualDelegationBalance = world.GetBalance(validatorAddress, DelegationCurrency);
var actualCommission = world.GetBalance(validatorAddress, GuildAllocateRewardCurrency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Execute()

// Then
var repository = new ValidatorRepository(world, actionContext);
var validator = repository.GetValidatorDelegatee(validatorKey.Address);
var validator = repository.GetDelegatee(validatorKey.Address);
var bond = repository.GetBond(validator, validatorKey.Address);
var validatorList = repository.GetValidatorList();

Expand Down Expand Up @@ -222,7 +222,7 @@ private void ExecuteWithFixture(IDelegateValidatorFixture fixture)

// When
var expectedRepository = new ValidatorRepository(world, new ActionContext());
var expectedValidator = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedValidator = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedValidatorBalance = validatorBalance - validatorCash - validatorCashToDelegate;
var expectedPower = validatorCash.RawValue + validatorCashToDelegate.RawValue;

Expand All @@ -237,7 +237,7 @@ private void ExecuteWithFixture(IDelegateValidatorFixture fixture)

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualValidator = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualValidator = actualRepository.GetDelegatee(validatorKey.Address);
var actualValidatorBalance = GetBalance(world, validatorKey.Address);
var actualPower = actualValidator.Power;
var actualBond = actualRepository.GetBond(actualValidator, validatorKey.Address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Execute()

// Then
var repository = new ValidatorRepository(world, actionContext);
var validator = repository.GetValidatorDelegatee(validatorKey.Address);
var validator = repository.GetDelegatee(validatorKey.Address);
var bond = repository.GetBond(validator, validatorKey.Address);
var validatorList = repository.GetValidatorList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Execute()

// When
var expectedRepository = new GuildRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetGuildDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedUnbondingSet = expectedRepository.GetUnbondingSet();
var expectedReleaseCount = expectedUnbondingSet.UnbondingRefs.Count;
var expectedDepositGold = expectedDelegatee.FAVFromShare(share);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Execute()

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualPercentage = actualDelegatee.CommissionPercentage;

Assert.Equal(11, actualPercentage);
Expand Down Expand Up @@ -119,7 +119,7 @@ public void Execute_Theory(int oldCommissionPercentage, int newCommissionPercent

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualPercentage = actualDelegatee.CommissionPercentage;

Assert.Equal(newCommissionPercentage, actualPercentage);
Expand Down Expand Up @@ -235,7 +235,7 @@ public void Execute_Theory_WitValue(int period)

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualPercentage = actualDelegatee.CommissionPercentage;

Assert.Equal(expectedCommission, actualPercentage);
Expand Down Expand Up @@ -280,7 +280,7 @@ public void Execute_With_SameValue_Throw()

// When
var repository = new ValidatorRepository(world, new ActionContext());
var delegatee = repository.GetValidatorDelegatee(validatorKey.Address);
var delegatee = repository.GetDelegatee(validatorKey.Address);
var commissionPercentage = delegatee.CommissionPercentage;
var setValidatorCommission = new SetValidatorCommission(
commissionPercentage: commissionPercentage);
Expand Down
14 changes: 7 additions & 7 deletions .Lib9c.Tests/Action/ValidatorDelegation/SlashValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Execute()

// When
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedValidatorShare = expectedRepository.GetBond(
expectedDelegatee, validatorKey.Address).Share;

Expand Down Expand Up @@ -96,7 +96,7 @@ public void Execute()
// Then
var balance = GetBalance(world, validatorKey.Address);
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualValidatorShare = actualRepository.GetBond(actualDelegatee, validatorKey.Address).Share;

Assert.True(actualDelegatee.Jailed);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void Execute_ByAbstain()

// Then
var repository = new ValidatorRepository(world, actionContext);
var delegatee = repository.GetValidatorDelegatee(validatorKey.Address);
var delegatee = repository.GetDelegatee(validatorKey.Address);
Assert.True(delegatee.Jailed);
Assert.False(delegatee.Tombstoned);
}
Expand All @@ -184,7 +184,7 @@ public void Execute_ToJailedValidator_ThenNothingHappens()

// When
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedJailed = expectedDelegatee.Jailed;
var evidence = CreateDuplicateVoteEvidence(validatorKey, height - 1);
var lastCommit = new BlockCommit(
Expand All @@ -205,7 +205,7 @@ public void Execute_ToJailedValidator_ThenNothingHappens()

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualJailed = actualDelegatee.Jailed;

Assert.Equal(expectedJailed, actualJailed);
Expand All @@ -224,7 +224,7 @@ public void Execute_ByAbstain_ToJailedValidator_ThenNothingHappens()
world = EnsureJailedValidator(world, validatorKey, ref height);

var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedTotalDelegated = expectedDelegatee.TotalDelegated;

// When
Expand All @@ -249,7 +249,7 @@ public void Execute_ByAbstain_ToJailedValidator_ThenNothingHappens()

// Then
var actualRepisitory = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepisitory.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepisitory.GetDelegatee(validatorKey.Address);
var actualTotalDelegated = actualDelegatee.TotalDelegated;

Assert.True(actualDelegatee.Jailed);
Expand Down
20 changes: 10 additions & 10 deletions .Lib9c.Tests/Action/ValidatorDelegation/UndelegateValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Execute()

// When
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address);
var undelegateValidator = new UndelegateValidator(expectedBond.Share);
actionContext = new ActionContext
Expand All @@ -66,7 +66,7 @@ public void Execute()
world = undelegateValidator.Execute(actionContext);

var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualValidatorList = actualRepository.GetValidatorList();
var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address);

Expand Down Expand Up @@ -182,15 +182,15 @@ public void Execute_FromJailedValidator()
BlockIndex = height,
};
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address);

var undelegateValidator = new UndelegateValidator(10);
world = undelegateValidator.Execute(actionContext);

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address);

Assert.Equal(expectedBond.Share - 10, actualBond.Share);
Expand All @@ -215,15 +215,15 @@ public void Execute_FromTombstonedValidator()
BlockIndex = height,
};
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedBond = expectedRepository.GetBond(expectedDelegatee, validatorKey.Address);

var undelegateValidator = new UndelegateValidator(10);
world = undelegateValidator.Execute(actionContext);

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address);

Assert.Equal(expectedBond.Share - 10, actualBond.Share);
Expand All @@ -244,7 +244,7 @@ public void Execute_JailsValidatorWhenUndelegationCausesLowDelegation()

// When
var expectedRepository = new ValidatorRepository(world, actionContext);
var expectedDelegatee = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedDelegatee = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedJailed = expectedDelegatee.Jailed;

var undelegateValidator = new UndelegateValidator(10);
Expand All @@ -258,7 +258,7 @@ public void Execute_JailsValidatorWhenUndelegationCausesLowDelegation()

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualDelegatee = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualDelegatee = actualRepository.GetDelegatee(validatorKey.Address);
var actualJailed = actualDelegatee.Jailed;
var actualJailedUntil = actualDelegatee.JailedUntil;

Expand All @@ -280,7 +280,7 @@ private void ExecuteWithFixture(IUndelegateValidatorFixture fixture)

// When
var expectedRepository = new ValidatorRepository(world, new ActionContext());
var expectedValidator = expectedRepository.GetValidatorDelegatee(validatorKey.Address);
var expectedValidator = expectedRepository.GetDelegatee(validatorKey.Address);
var expectedValidatorBalance = validatorBalance - validatorCash;
var expectedValidatorPower = expectedValidator.Power - fixture.ValidatorInfo.SubtractShare;

Expand All @@ -296,7 +296,7 @@ private void ExecuteWithFixture(IUndelegateValidatorFixture fixture)

// Then
var actualRepository = new ValidatorRepository(world, actionContext);
var actualValidator = actualRepository.GetValidatorDelegatee(validatorKey.Address);
var actualValidator = actualRepository.GetDelegatee(validatorKey.Address);
var actualValidatorBalance = GetBalance(world, validatorKey.Address);
var actualValiatorPower = actualValidator.Power;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Execute()

// Then
var repository = new ValidatorRepository(world, actionContext);
var delegatee = repository.GetValidatorDelegatee(validatorKey.Address);
var delegatee = repository.GetDelegatee(validatorKey.Address);
Assert.False(delegatee.Jailed);
Assert.Equal(-1, delegatee.JailedUntil);
Assert.False(delegatee.Tombstoned);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Execute_ExcludesTombstonedValidator()
var actualRepository = new ValidatorRepository(world, actionContext);
var actualValidators = actualRepository.GetValidatorList()
.ActiveSet().OrderBy(item => item.OperatorAddress).ToList();
var tombstonedValidator = actualRepository.GetValidatorDelegatee(validatorKeys[0].Address);
var tombstonedValidator = actualRepository.GetDelegatee(validatorKeys[0].Address);

Assert.True(tombstonedValidator.Tombstoned);
Assert.Equal(expectedValidators.Count - 1, actualValidators.Count);
Expand Down
Loading
Loading