Skip to content

Commit

Permalink
refactor: move DPoS feaures under Lib9c project
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Mar 29, 2024
1 parent 6da9f8a commit 90cc46c
Show file tree
Hide file tree
Showing 75 changed files with 433 additions and 533 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Immutable;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System.Collections.Immutable;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class DelegateCtrlTest : PoSTest
{
private readonly PublicKey _operatorPublicKey;
Expand Down Expand Up @@ -149,12 +149,15 @@ public void BalanceTest(
Assert.Equal(
Asset.GovernanceToken * (selfDelegateAmount + delegateAmount),
_states.GetBalance(ReservedAddress.UnbondedPool, Asset.GovernanceToken));
var balanceA = _states.GetBalance(
Delegation.DeriveAddress(_operatorAddress, _validatorAddress),
Asset.Share);
var balanceB = _states.GetBalance(
Delegation.DeriveAddress(_delegatorAddress, _validatorAddress),
Asset.Share);
Assert.Equal(
ValidatorCtrl.GetValidator(_states, _validatorAddress)!.DelegatorShares,
_states.GetBalance(
Delegation.DeriveAddress(_operatorAddress, _validatorAddress), Asset.Share)
+ _states.GetBalance(
Delegation.DeriveAddress(_delegatorAddress, _validatorAddress), Asset.Share));
balanceA + balanceB);
}

private void Initialize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Collections.Immutable;
using Lib9c.DPoS.Action;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System.Collections.Immutable;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class RedelegateCtrlTest : PoSTest
{
private readonly PublicKey _srcOperatorPublicKey;
Expand Down Expand Up @@ -276,22 +276,32 @@ public void BalanceTest(
Assert.Equal(
Asset.GovernanceToken * (2 * selfDelegateAmount + delegateAmount),
_states.GetBalance(ReservedAddress.UnbondedPool, Asset.GovernanceToken));
var balanceA = _states.GetBalance(
Delegation.DeriveAddress(
_srcOperatorAddress,
_srcValidatorAddress),
Asset.Share);
var balanceB = _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress,
_srcValidatorAddress),
Asset.Share);
Assert.Equal(
ValidatorCtrl.GetValidator(_states, _srcValidatorAddress)!.DelegatorShares,
_states.GetBalance(
Delegation.DeriveAddress(
_srcOperatorAddress, _srcValidatorAddress), Asset.Share)
+ _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress, _srcValidatorAddress), Asset.Share));
balanceA + balanceB);
balanceA = _states.GetBalance(
Delegation.DeriveAddress(
_dstOperatorAddress,
_dstValidatorAddress),
Asset.Share);
balanceB = _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress,
_dstValidatorAddress),
Asset.Share);
Assert.Equal(
ValidatorCtrl.GetValidator(_states, _dstValidatorAddress)!.DelegatorShares,
_states.GetBalance(
Delegation.DeriveAddress(
_dstOperatorAddress, _dstValidatorAddress), Asset.Share)
+ _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress, _dstValidatorAddress), Asset.Share));
balanceA + balanceB);
RedelegationEntry entry = new RedelegationEntry(
_states.GetDPoSState(
RedelegateCtrl.GetRedelegation(_states, _redelegationAddress)!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Immutable;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System.Collections.Immutable;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class UndelegateCtrlTest : PoSTest
{
private readonly PublicKey _operatorPublicKey;
Expand Down Expand Up @@ -330,14 +330,19 @@ public void BalanceTest(
Assert.Equal(
Asset.GovernanceToken * (selfDelegateAmount + delegateAmount),
_states.GetBalance(ReservedAddress.UnbondedPool, Asset.GovernanceToken));
var balanceA = _states.GetBalance(
Delegation.DeriveAddress(
_operatorAddress,
_validatorAddress),
Asset.Share);
var balanceB = _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress,
_validatorAddress),
Asset.Share);
Assert.Equal(
ValidatorCtrl.GetValidator(_states, _validatorAddress)!.DelegatorShares,
_states.GetBalance(
Delegation.DeriveAddress(
_operatorAddress, _validatorAddress), Asset.Share)
+ _states.GetBalance(
Delegation.DeriveAddress(
_delegatorAddress, _validatorAddress), Asset.Share));
balanceA + balanceB);
Assert.Equal(
Asset.ConsensusToken * (selfDelegateAmount + delegateAmount - undelegateAmount),
_states.GetBalance(_validatorAddress, Asset.ConsensusToken));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Immutable;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System.Collections.Immutable;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class ValidatorCtrlTest : PoSTest
{
private readonly PublicKey _operatorPublicKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class ValidatorPowerIndexCtrlTest : PoSTest
{
private readonly ImmutableHashSet<Currency> _nativeTokens;
Expand Down Expand Up @@ -58,7 +58,8 @@ public ValidatorPowerIndexCtrlTest()
},
addr,
key,
Asset.GovernanceToken * 10, _nativeTokens);
Asset.GovernanceToken * 10,
_nativeTokens);
ValidatorAddresses.Add(Validator.DeriveAddress(addr));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Module;
using Xunit;

namespace Lib9c.DPoS.Tests.Control
namespace Lib9c.Tests.Action.DPoS.Control
{
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class ValidatorSetCtrlTest : PoSTest
{
private ImmutableHashSet<Currency> _nativeTokens;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using Lib9c.DPoS.Control;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;
using Nekoyume.Module;
using Xunit;
using Validator = Lib9c.DPoS.Model.Validator;

namespace Lib9c.DPoS.Tests
namespace Lib9c.Tests.Action.DPoS
{
using System.Collections.Generic;
using System.Collections.Immutable;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Consensus;
using Nekoyume.Action.DPoS.Control;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;
using Validator = Nekoyume.Action.DPoS.Model.Validator;

public class DistributeTest : PoSTest
{
private readonly ImmutableHashSet<Currency> _nativeTokens;
Expand Down Expand Up @@ -172,13 +172,13 @@ public void ValidatorSetTest()
OperatorAddresses[3]);

var (baseProposerReward, _)
= (blockReward * AllocateReward.BaseProposerRewardNumer)
.DivRem(AllocateReward.BaseProposerRewardDenom);
= (blockReward * AllocateReward.BaseProposerRewardNumerator)
.DivRem(AllocateReward.BaseProposerRewardDenominator);
var (bonusProposerReward, _)
= (blockReward * (205 + 307)
* AllocateReward.BonusProposerRewardNumer)
* AllocateReward.BonusProposerRewardNumerator)
.DivRem((100 + (101 + 200) * 50 - 101 - 102 + 204 + 306)
* AllocateReward.BonusProposerRewardDenom);
* AllocateReward.BonusProposerRewardDenominator);
FungibleAssetValue proposerReward = baseProposerReward + bonusProposerReward;
FungibleAssetValue validatorRewardSum = blockReward - proposerReward;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Lib9c.DPoS.Model;
using Xunit;

namespace Lib9c.DPoS.Tests.Model
namespace Lib9c.Tests.Action.DPoS.Model
{
using Nekoyume.Action.DPoS.Model;
using Xunit;

public class DelegationTest : PoSTest
{
private readonly Delegation _delegation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Xunit;

namespace Lib9c.DPoS.Tests.Model
namespace Lib9c.Tests.Action.DPoS.Model
{
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Xunit;

public class RedelegationEntryTest : PoSTest
{
private readonly RedelegationEntry _redelegationEntry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Lib9c.DPoS.Model;
using Xunit;

namespace Lib9c.DPoS.Tests.Model
namespace Lib9c.Tests.Action.DPoS.Model
{
using Nekoyume.Action.DPoS.Model;
using Xunit;

public class RedelegationTest : PoSTest
{
private readonly Redelegation _redelegation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Lib9c.DPoS.Exception;
using Lib9c.DPoS.Misc;
using Lib9c.DPoS.Model;
using Xunit;

namespace Lib9c.DPoS.Tests.Model
namespace Lib9c.Tests.Action.DPoS.Model
{
using Nekoyume.Action.DPoS.Exception;
using Nekoyume.Action.DPoS.Misc;
using Nekoyume.Action.DPoS.Model;
using Xunit;

public class UndelegationEntryTest : PoSTest
{
private readonly UndelegationEntry _undelegationEntry;
Expand Down
Loading

0 comments on commit 90cc46c

Please sign in to comment.