Skip to content

Commit b05501a

Browse files
roman-khimovshargonvncoelho
authored
NEO: clear LastGasPerVote when voting for NULL, fix neo-project#2894 (neo-project#3173)
This value won't be used in any way, so save some bytes of storage. Signed-off-by: Roman Khimov <roman@nspcc.ru> Co-authored-by: Shargon <shargon@gmail.com> Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
1 parent 413cfc4 commit b05501a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Neo/SmartContract/Native/NeoToken.cs

+4
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ private async ContractTask<bool> Vote(ApplicationEngine engine, UInt160 account,
393393
{
394394
validator_new.Votes += state_account.Balance;
395395
}
396+
else
397+
{
398+
state_account.LastGasPerVote = 0;
399+
}
396400
engine.SendNotification(Hash, "Vote",
397401
new VM.Types.Array(engine.ReferenceCounter) { account.ToArray(), from?.ToArray() ?? StackItem.Null, voteTo?.ToArray() ?? StackItem.Null, state_account.Balance });
398402
if (gasDistribution is not null)

tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs

+3
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ public void Check_Vote_VoteToNull()
192192
var accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable<NeoAccountState>();
193193
accountState.Balance = 100;
194194
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
195+
snapshot.Add(CreateStorageKey(23, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new BigInteger(100500)));
195196
var ret = Check_Vote(snapshot, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
196197
ret.Result.Should().BeTrue();
197198
ret.State.Should().BeTrue();
198199
accountState = snapshot.TryGet(CreateStorageKey(20, from_Account)).GetInteroperable<NeoAccountState>();
199200
accountState.VoteTo.Should().Be(ECCurve.Secp256r1.G);
201+
accountState.LastGasPerVote.Should().Be(100500);
200202

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

216219
[TestMethod]

0 commit comments

Comments
 (0)