Skip to content

Commit

Permalink
test: Add test code for ValidatorDelegationSetCtrl.
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Apr 2, 2024
1 parent 69f72d1 commit 3bcb166
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .Lib9c.Tests/Action/DPoS/Control/ValidatorDelegationSetCtrlTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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.Misc;
using Nekoyume.Action.DPoS.Model;
using Nekoyume.Module;
using Xunit;

public class ValidatorDelegationSetCtrlTest : PoSTest
{
private readonly PublicKey _operatorPublicKey;
private readonly Address _operatorAddress;
private readonly Address _validatorAddress;
private readonly ImmutableHashSet<Currency> _nativeTokens;
private IWorld _states;

public ValidatorDelegationSetCtrlTest()
: base()
{
_operatorPublicKey = new PrivateKey().PublicKey;
_operatorAddress = _operatorPublicKey.Address;
_validatorAddress = Validator.DeriveAddress(_operatorAddress);
_nativeTokens = ImmutableHashSet.Create(
Asset.GovernanceToken, Asset.ConsensusToken, Asset.Share);
_states = InitializeStates();
_states = _states.MintAsset(
context: new ActionContext { PreviousState = _states, },
recipient: _operatorAddress,
value: Asset.GovernanceToken * 100000);
_states = ValidatorCtrl.Create(
states: _states,
ctx: new ActionContext { PreviousState = _states, },
operatorAddress: _operatorAddress,
operatorPublicKey: _operatorPublicKey,
Asset.GovernanceToken * 10,
nativeTokens: _nativeTokens
);
}

[Fact]
public void PromoteTest()
{
var validatorDelegationSet = ValidatorDelegationSetCtrl.GetValidatorDelegationSet(
_states,
_validatorAddress
);
Assert.NotNull(validatorDelegationSet);
Assert.Single(validatorDelegationSet.Set);
var delegation = DelegateCtrl.GetDelegation(
states: _states,
delegationAddress: validatorDelegationSet.Set[0]
);
Assert.NotNull(delegation);
Assert.Equal(_validatorAddress, delegation.ValidatorAddress);
Assert.Equal(_operatorAddress, delegation.DelegatorAddress);
}
}
}

0 comments on commit 3bcb166

Please sign in to comment.