-
Notifications
You must be signed in to change notification settings - Fork 48
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 errors on DPoS #2515
Merged
Merged
Fix errors on DPoS #2515
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e6a4af6
refactor: rename AllocateRewardCtrl
limebell 98ffc27
bump: libplanet
limebell 181d40f
feat: adjust changes from the libplanet API changes
limebell 24bca50
test: add regression test
limebell 939328c
bugfix: fix logic error in dpos methods
limebell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
namespace Lib9c.Tests.Action.DPoS.Sys | ||
{ | ||
using System.Linq; | ||
using Libplanet.Action.State; | ||
using Libplanet.Crypto; | ||
using Libplanet.Types.Assets; | ||
using Nekoyume.Action.DPoS; | ||
using Nekoyume.Action.DPoS.Control; | ||
using Nekoyume.Action.DPoS.Misc; | ||
using Nekoyume.Action.DPoS.Model; | ||
using Nekoyume.Action.DPoS.Sys; | ||
using Nekoyume.Module; | ||
using Xunit; | ||
|
||
public class UpdateValidatorsTest : PoSTest | ||
{ | ||
[Fact] | ||
public void Execute() | ||
{ | ||
// Prepare initial state. | ||
IWorld initialState = new World(new MockWorldState()); | ||
const int count = 4; | ||
var validatorKeys = Enumerable.Range(0, count).Select(_ => new PrivateKey().PublicKey).ToArray(); | ||
initialState = validatorKeys.Aggregate( | ||
initialState, | ||
(current, key) => current.MintAsset( | ||
new ActionContext(), | ||
key.Address, | ||
new FungibleAssetValue(Asset.GovernanceToken, 1, 0))); | ||
foreach (var key in validatorKeys) | ||
{ | ||
Assert.Equal(1, initialState.GetBalance(key.Address, Asset.GovernanceToken).MajorUnit); | ||
Assert.Equal(0, initialState.GetBalance(key.Address, Asset.GovernanceToken).MinorUnit); | ||
} | ||
|
||
// Stake 1 for each validator. | ||
foreach (var key in validatorKeys) | ||
{ | ||
initialState = new PromoteValidator( | ||
key, | ||
new FungibleAssetValue(Asset.GovernanceToken, 1, 0)).Execute( | ||
new ActionContext | ||
{ | ||
PreviousState = initialState, | ||
Signer = key.Address, | ||
}); | ||
} | ||
|
||
Assert.Equal(0, ValidatorSetCtrl.FetchBondedValidatorSet(initialState).Item2.Count); | ||
Assert.Equal(0, initialState.GetValidatorSet().TotalCount); | ||
|
||
// Execute the action. | ||
initialState = new UpdateValidators().Execute( | ||
new ActionContext | ||
{ | ||
PreviousState = initialState, | ||
LastCommit = null, | ||
}); | ||
|
||
Assert.Equal(count, ValidatorSetCtrl.FetchBondedValidatorSet(initialState).Item2.Count); | ||
Assert.Equal(count, initialState.GetValidatorSet().TotalCount); | ||
Assert.Equal( | ||
validatorKeys.ToHashSet(), | ||
initialState.GetValidatorSet() | ||
.Validators.Select(validator => validator.PublicKey) | ||
.ToHashSet()); | ||
|
||
initialState = new Undelegate( | ||
Validator.DeriveAddress(validatorKeys[0].Address), | ||
new FungibleAssetValue(Asset.Share, 100, 0)).Execute( | ||
new ActionContext | ||
{ | ||
PreviousState = initialState, | ||
Signer = validatorKeys[0].Address, | ||
}); | ||
|
||
Assert.Equal(count, ValidatorSetCtrl.FetchBondedValidatorSet(initialState).Item2.Count); | ||
Assert.Equal(count, initialState.GetValidatorSet().TotalCount); | ||
|
||
// Execute the action. | ||
initialState = new UpdateValidators().Execute( | ||
new ActionContext | ||
{ | ||
PreviousState = initialState, | ||
LastCommit = null, | ||
}); | ||
|
||
Assert.Equal(count - 1, ValidatorSetCtrl.FetchBondedValidatorSet(initialState).Item2.Count); | ||
Assert.Equal(count - 1, initialState.GetValidatorSet().TotalCount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule .Libplanet
updated
47 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
RewardGold
action no longer used? I'm asking because I'm not sure. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In PoS, gold distribution will be executed by PoS logic. Missing logic will be moved to block action later.