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

Fix delegation not being listed #2505

Merged
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
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);
}
}
}
12 changes: 12 additions & 0 deletions Lib9c/Action/DPoS/Control/Bond.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ internal static (IWorld, FungibleAssetValue) Execute(
states = DelegateCtrl.Distribute(states, ctx, nativeTokens, addrs);
}

states = ValidatorDelegationSetCtrl.Add(
states: states,
validatorAddress: validatorAddress,
delegationAddress: delegationAddress
);

return (states, issuedShare);
}

Expand Down Expand Up @@ -140,6 +146,12 @@ internal static (IWorld, FungibleAssetValue) Cancel(
states = DelegateCtrl.Distribute(states, ctx, nativeTokens, addrs);
}

states = ValidatorDelegationSetCtrl.Remove(
states: states,
validatorAddress: validatorAddress,
delegationAddress: delegationAddress
);

return (states, unbondingConsensusToken);
}
}
Expand Down
Loading