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

Backmerge 1.20.2 #3063

Merged
merged 11 commits into from
Dec 3, 2024
6 changes: 3 additions & 3 deletions .Lib9c.Tests/Action/Guild/ClaimRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,16 @@ var expectedProposerReward
AllocateRewardCurrency))
.ToArray();

Assert.Equal(expectedRemainGuildReward, actualRemainGuildReward);
Assert.Equal(expectedValidatorBalance, actualValidatorBalance);
Assert.Equal(expectedDelegatorBalances, actualDelegatorBalances);
Assert.Equal(expectedValidatorGuildReward, actualValidatorGuildReward);
Assert.Equal(expectedDelegatorGuildClaims, actualDelegatorGuildRewards);
Assert.Equal(expectedValidatorClaim, actualValidatorReward);
Assert.Equal(expectedGuildClaims, actualGuildRewards);
Assert.Equal(expectedGuildParticipantClaims, actualGuildParticipantRewards);
Assert.Equal(expectedRemainReward, actualRemainReward);

// Flushing to remainder pool is now inactive.
// Assert.Equal(expectedRemainGuildReward, actualRemainGuildReward);
// Assert.Equal(expectedRemainReward, actualRemainReward);
foreach (var key in guildParticipantKeys)
{
Assert.Throws<InvalidOperationException>(
Expand Down
41 changes: 41 additions & 0 deletions .Lib9c.Tests/Action/ItemEnhancementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,5 +544,46 @@ public void Execute_With_Hammer(bool oldStart)
Assert.Equal(preItemUsable.ItemId, resultEquipment.ItemId);
Assert.Equal(expectedCost, slotResult.gold);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void Execute_Throw_InvalidItemTypeException(bool withMaterials)
{
var types = ItemEnhancement.HammerBannedTypes;
foreach (var itemSubType in types)
{
var row =
_tableSheets.EquipmentItemSheet.Values.First(r => r.ItemSubType == itemSubType);
var equipment = ItemFactory.CreateItemUsable(row, Guid.NewGuid(), 0);
_avatarState.inventory.AddItem(equipment);
_initialState = _initialState.SetAvatarState(_avatarAddress, _avatarState);
var materialIds = new List<Guid>();
if (withMaterials)
{
materialIds.Add(Guid.NewGuid());
materialIds.Add(Guid.NewGuid());
}

var action = new ItemEnhancement
{
itemId = equipment.ItemId,
materialIds = materialIds,
avatarAddress = _avatarAddress,
slotIndex = 0,
hammers = new Dictionary<int, int>
{
[600301] = 3,
},
};
Assert.Throws<InvalidItemTypeException>(() => action.Execute(new ActionContext
{
BlockIndex = 1,
PreviousState = _initialState,
RandomSeed = 0,
Signer = _agentAddress,
}));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void Execute()
var bond = repository.GetBond(validator, validatorKey.Address);
var validatorList = repository.GetValidatorList();

Assert.Equal(validatorKey.Address, Assert.Single(validator.Delegators));
Assert.Equal(gold.RawValue, bond.Share);
Assert.Equal(validator.Validator, Assert.Single(validatorList.Validators));
Assert.Equal(validator.Validator, Assert.Single(validatorList.ActiveSet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void Execute()
var actualValidatorList = actualRepository.GetValidatorList();
var actualBond = actualRepository.GetBond(actualDelegatee, validatorKey.Address);

Assert.NotEqual(expectedDelegatee.Delegators, actualDelegatee.Delegators);
Assert.NotEqual(expectedDelegatee.Validator.Power, actualDelegatee.Validator.Power);
Assert.Equal(BigInteger.Zero, actualDelegatee.Validator.Power);
Assert.Empty(actualValidatorList.Validators);
Expand Down
16 changes: 2 additions & 14 deletions .Lib9c.Tests/Delegation/DelegateeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Lib9c.Tests.Delegation
using System.Numerics;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Delegation;
using Xunit;

Expand Down Expand Up @@ -38,7 +39,6 @@ public void GetSet()
delegatee.Bond(delegator, delegatee.DelegationCurrency * 10, 10L);
var delegateeRecon = repo.GetDelegatee(delegatee.Address);
Assert.Equal(delegatee.Address, delegateeRecon.Address);
Assert.Equal(delegator.Address, Assert.Single(delegateeRecon.Delegators));
Assert.Equal(delegatee.TotalDelegated, delegateeRecon.TotalDelegated);
Assert.Equal(delegatee.TotalShares, delegateeRecon.TotalShares);
}
Expand Down Expand Up @@ -70,7 +70,6 @@ public void Bond()

var bondedShare = testDelegatee.Bond(testDelegator1, bonding, 10L);
var bondedShare1 = _fixture.TestRepository.GetBond(testDelegatee, testDelegator1.Address).Share;
Assert.Equal(testDelegator1.Address, Assert.Single(testDelegatee.Delegators));
Assert.Equal(share, bondedShare);
Assert.Equal(share1, bondedShare1);
Assert.Equal(totalShare, testDelegatee.TotalShares);
Expand All @@ -83,7 +82,6 @@ public void Bond()
totalBonding += bonding;
bondedShare = testDelegatee.Bond(testDelegator1, bonding, 20L);
bondedShare1 = _fixture.TestRepository.GetBond(testDelegatee, testDelegator1.Address).Share;
Assert.Equal(testDelegator1.Address, Assert.Single(testDelegatee.Delegators));
Assert.Equal(share, bondedShare);
Assert.Equal(share1, bondedShare1);
Assert.Equal(totalShare, testDelegatee.TotalShares);
Expand All @@ -96,9 +94,6 @@ public void Bond()
totalBonding += bonding;
bondedShare = testDelegatee.Bond(testDelegator2, bonding, 30L);
var bondedShare2 = _fixture.TestRepository.GetBond(testDelegatee, testDelegator2.Address).Share;
Assert.Equal(2, testDelegatee.Delegators.Count);
Assert.Contains(testDelegator1.Address, testDelegatee.Delegators);
Assert.Contains(testDelegator2.Address, testDelegatee.Delegators);
Assert.Equal(share, bondedShare);
Assert.Equal(share2, bondedShare2);
Assert.Equal(totalShare, testDelegatee.TotalShares);
Expand Down Expand Up @@ -163,9 +158,6 @@ public void Unbond()
totalDelegated -= unbondingFAV;
var unbondedFAV = testDelegatee.Unbond(testDelegator1, unbonding, 3L);
var shareAfterUnbond = _fixture.TestRepository.GetBond(testDelegatee, testDelegator1.Address).Share;
Assert.Equal(2, testDelegatee.Delegators.Count);
Assert.Contains(testDelegator1.Address, testDelegatee.Delegators);
Assert.Contains(testDelegator2.Address, testDelegatee.Delegators);
Assert.Equal(unbondingFAV, unbondedFAV);
Assert.Equal(share1, shareAfterUnbond);
Assert.Equal(totalShares, testDelegatee.TotalShares);
Expand All @@ -178,9 +170,6 @@ public void Unbond()
totalDelegated -= unbondingFAV;
unbondedFAV = testDelegatee.Unbond(testDelegator2, unbonding, 4L);
shareAfterUnbond = _fixture.TestRepository.GetBond(testDelegatee, testDelegator2.Address).Share;
Assert.Equal(2, testDelegatee.Delegators.Count);
Assert.Contains(testDelegator1.Address, testDelegatee.Delegators);
Assert.Contains(testDelegator2.Address, testDelegatee.Delegators);
Assert.Equal(unbondingFAV, unbondedFAV);
Assert.Equal(share2, shareAfterUnbond);
Assert.Equal(totalShares, testDelegatee.TotalShares);
Expand All @@ -191,7 +180,6 @@ public void Unbond()
totalDelegated -= unbondingFAV;
unbondedFAV = testDelegatee.Unbond(testDelegator1, share1, 5L);
shareAfterUnbond = _fixture.TestRepository.GetBond(testDelegatee, testDelegator1.Address).Share;
Assert.Equal(testDelegator2.Address, Assert.Single(testDelegatee.Delegators));
Assert.Equal(unbondingFAV, unbondedFAV);
Assert.Equal(BigInteger.Zero, shareAfterUnbond);
Assert.Equal(totalShares, testDelegatee.TotalShares);
Expand All @@ -207,7 +195,7 @@ public void CannotUnbondInvalidDelegator()
_fixture.DummyDelegator1, BigInteger.One, 10L));
}

[Fact]
[Fact(Skip = "Flushing to remainder pool is now inactive.")]
public void ClearRemainderRewards()
{
var repo = _fixture.TestRepository;
Expand Down
36 changes: 24 additions & 12 deletions .Lib9c.Tests/Delegation/DelegatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void Delegate()
Assert.Equal(delegateShare, share);
Assert.Equal(delegateFAV, delegatee1.TotalDelegated);
Assert.Equal(delegateShare, delegatee1.TotalShares);
Assert.Equal(delegator.Address, Assert.Single(delegatee1.Delegators));
Assert.Equal(delegatee1.Address, Assert.Single(delegator.Delegatees));

var delegateFAV2 = delegatee1.DelegationCurrency * 20;
Expand All @@ -71,7 +70,6 @@ public void Delegate()
Assert.Equal(delegateShare + delegateShare2, share);
Assert.Equal(delegateFAV + delegateFAV2, delegatee1.TotalDelegated);
Assert.Equal(delegateShare + delegateShare2, delegatee1.TotalShares);
Assert.Equal(delegator.Address, Assert.Single(delegatee1.Delegators));
Assert.Equal(delegatee1.Address, Assert.Single(delegator.Delegatees));

delegator.Delegate(delegatee2, delegateFAV, 3L);
Expand Down Expand Up @@ -112,7 +110,6 @@ public void Undelegate()
Assert.Equal(initialShare - undelegatingShare, share1);
Assert.Equal(delegatingFAV - undelegatingFAV, delegatee.TotalDelegated);
Assert.Equal(initialShare - undelegatingShare, delegatee.TotalShares);
Assert.Equal(delegator.Address, Assert.Single(delegatee.Delegators));
Assert.Equal(delegatee.Address, Assert.Single(delegator.Delegatees));
Assert.Equal(unbondLockIn.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address);
var entriesByExpireHeight = Assert.Single(unbondLockIn.Entries);
Expand All @@ -137,7 +134,6 @@ public void Undelegate()
Assert.Equal(delegatee.DelegationCurrency * 0, delegatee.TotalDelegated);
Assert.Equal(System.Numerics.BigInteger.Zero, delegatee.TotalShares);
Assert.Empty(delegator.Delegatees);
Assert.Empty(delegatee.Delegators);
Assert.Equal(unbondLockIn.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address);
Assert.Equal(2, unbondLockIn.Entries.Count);

Expand Down Expand Up @@ -215,8 +211,6 @@ public void Redelegate()
Assert.Equal(redelegatedDstShare, delegatee2.TotalShares);
Assert.Equal(delegatingFAV - redelegatingFAV, delegatee1.TotalDelegated);
Assert.Equal(redelegatingFAV, delegatee2.TotalDelegated);
Assert.Equal(delegator.Address, Assert.Single(delegatee1.Delegators));
Assert.Equal(delegator.Address, Assert.Single(delegatee2.Delegators));
Assert.Equal(2, delegator.Delegatees.Count);
Assert.Equal(rebondGrace.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address);
var entriesByExpireHeight = Assert.Single(rebondGrace.Entries);
Expand Down Expand Up @@ -247,8 +241,6 @@ public void Redelegate()
Assert.Equal(redelegatedDstShare + redelegatedDstShare2, delegatee2.TotalShares);
Assert.Equal(delegatingFAV - redelegatingFAV - redelegatingFAV2, delegatee1.TotalDelegated);
Assert.Equal(redelegatingFAV + redelegatingFAV2, delegatee2.TotalDelegated);
Assert.Empty(delegatee1.Delegators);
Assert.Equal(delegator.Address, Assert.Single(delegatee2.Delegators));
Assert.Equal(delegatee2.Address, Assert.Single(delegator.Delegatees));
Assert.Equal(rebondGrace.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address);
Assert.Equal(2, rebondGrace.Entries.Count);
Expand Down Expand Up @@ -357,7 +349,12 @@ public void RewardOnDelegate()
Assert.Equal(delegatorInitialBalance - delegatingFAV2 * 2, delegator2Balance);
Assert.Equal(rewards1, delegator1RewardBalances);
Assert.Equal(rewards2, delegator2RewardBalances);
Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);

// Flushing to remainder pool is now inactive.
// Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);
Assert.Equal(
rewards.Select(r => r * 2).Zip(rewards1.Zip(rewards2, (f, s) => f + s), (f, s) => f - s).ToArray(),
collectedRewards);
}

[Fact]
Expand Down Expand Up @@ -431,7 +428,12 @@ public void RewardOnUndelegate()
Assert.Equal(delegatorInitialBalance - delegatingFAV2, delegator2Balance);
Assert.Equal(rewards1, delegator1RewardBalances);
Assert.Equal(rewards2, delegator2RewardBalances);
Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);

// Flushing to remainder pool is now inactive.
// Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);
Assert.Equal(
rewards.Select(r => r * 2).Zip(rewards1.Zip(rewards2, (f, s) => f + s), (f, s) => f - s).ToArray(),
collectedRewards);
}

[Fact]
Expand Down Expand Up @@ -506,7 +508,12 @@ public void RewardOnRedelegate()
Assert.Equal(delegatorInitialBalance - delegatingFAV2, delegator2Balance);
Assert.Equal(rewards1, delegator1RewardBalances);
Assert.Equal(rewards2, delegator2RewardBalances);
Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);

// Flushing to remainder pool is now inactive.
// Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);
Assert.Equal(
rewards.Select(r => r * 2).Zip(rewards1.Zip(rewards2, (f, s) => f + s), (f, s) => f - s).ToArray(),
collectedRewards);
}

[Fact]
Expand Down Expand Up @@ -581,7 +588,12 @@ public void RewardOnClaim()
Assert.Equal(delegatorInitialBalance - delegatingFAV2, delegator2Balance);
Assert.Equal(rewards1, delegator1RewardBalances);
Assert.Equal(rewards2, delegator2RewardBalances);
Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);

// Flushing to remainder pool is now inactive.
// Assert.Equal(delegatee.RewardCurrencies.Select(c => c * 0), collectedRewards);
Assert.Equal(
rewards.Select(r => r * 2).Zip(rewards1.Zip(rewards2, (f, s) => f + s), (f, s) => f - s).ToArray(),
collectedRewards);
}
}
}
Loading
Loading