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

NEO: clear LastGasPerVote when voting for NULL, fix #2894 #3173

Merged
merged 3 commits into from
Mar 7, 2024
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
4 changes: 4 additions & 0 deletions src/Neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ private async ContractTask<bool> Vote(ApplicationEngine engine, UInt160 account,
{
validator_new.Votes += state_account.Balance;
}
else
{
state_account.LastGasPerVote = 0;
}
engine.SendNotification(Hash, "Vote",
new VM.Types.Array(engine.ReferenceCounter) { account.ToArray(), from?.ToArray() ?? StackItem.Null, voteTo?.ToArray() ?? StackItem.Null, state_account.Balance });
if (gasDistribution is not null)
Expand Down
3 changes: 3 additions & 0 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ public void Check_Vote_VoteToNull()
var accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable<NeoAccountState>();
accountState.Balance = 100;
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
snapshot.Add(CreateStorageKey(23, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new BigInteger(100500)));
var ret = Check_Vote(snapshot, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable<NeoAccountState>();
accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G);
accountState.LastGasPerVote.Should().Be(100500);

//from vote to null account G votes becomes 0
var G_stateValidator = snapshot.GetAndChange(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray())).GetInteroperable<CandidateState>();
Expand All @@ -211,6 +213,7 @@ public void Check_Vote_VoteToNull()
G_stateValidator.Votes.Should().Be(0);
accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable<NeoAccountState>();
accountState.VoteTo.Should().Be(null);
accountState.LastGasPerVote.Should().Be(0);
}

[TestMethod]
Expand Down
Loading