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 Candidate registered event #2779

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public override StackItem ToStackItem(ReferenceCounter referenceCounter)

internal class CandidateState : IInteroperable
{
public bool Registered = true;
public bool Registered;
public BigInteger Votes;

public void FromStackItem(StackItem stackItem)
Expand Down
16 changes: 8 additions & 8 deletions tests/neo.UnitTests/SmartContract/Native/UT_NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Check_Vote()

// normal case

snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState()));
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
ret = Check_Vote(snapshot, from, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand All @@ -106,7 +106,7 @@ public void Check_Vote_Sameaccounts()
byte[] from = Contract.GetBFTAddress(ProtocolSettings.Default.StandbyValidators).ToArray();
var accountState = snapshot.TryGet(CreateStorageKey(20, from)).GetInteroperable<NeoAccountState>();
accountState.Balance = 100;
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState()));
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
var ret = Check_Vote(snapshot, from, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand Down Expand Up @@ -138,7 +138,7 @@ public void Check_Vote_ChangeVote()
snapshot.Add(CreateStorageKey(20, from_Account), new StorageItem(new NeoAccountState()));
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()));
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
var ret = Check_Vote(snapshot, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand All @@ -150,7 +150,7 @@ public void Check_Vote_ChangeVote()
G_stateValidator.Votes.Should().Be(100);
var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray();
snapshot.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState { Balance = 200 }));
snapshot.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState()));
snapshot.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState() { Registered = true }));
ret = Check_Vote(snapshot, from_Account, from, true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand All @@ -171,7 +171,7 @@ public void Check_Vote_VoteToNull()
snapshot.Add(CreateStorageKey(20, from_Account), new StorageItem(new NeoAccountState()));
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()));
snapshot.Add(CreateStorageKey(33, ECCurve.Secp256r1.G.ToArray()), new StorageItem(new CandidateState() { Registered = true }));
var ret = Check_Vote(snapshot, from_Account, ECCurve.Secp256r1.G.ToArray(), true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand All @@ -183,7 +183,7 @@ public void Check_Vote_VoteToNull()
G_stateValidator.Votes.Should().Be(100);
var G_Account = Contract.CreateSignatureContract(ECCurve.Secp256r1.G).ScriptHash.ToArray();
snapshot.Add(CreateStorageKey(20, G_Account), new StorageItem(new NeoAccountState { Balance = 200 }));
snapshot.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState()));
snapshot.Add(CreateStorageKey(33, from), new StorageItem(new CandidateState() { Registered = true }));
ret = Check_Vote(snapshot, from_Account, null, true, persistingBlock);
ret.Result.Should().BeTrue();
ret.State.Should().BeTrue();
Expand Down Expand Up @@ -579,7 +579,7 @@ public void TestGetCandidates2()
result.Count().Should().Be(0);

StorageKey key = NativeContract.NEO.CreateStorageKey(33, ECCurve.Secp256r1.G);
snapshot.Add(key, new StorageItem(new CandidateState()));
snapshot.Add(key, new StorageItem(new CandidateState() { Registered = true }));
NativeContract.NEO.GetCandidatesInternal(snapshot).Count().Should().Be(1);
}

Expand Down Expand Up @@ -876,7 +876,7 @@ public void TestVote()
Balance = 1,
VoteTo = ECCurve.Secp256r1.G
}));
snapshot.Add(keyValidator, new StorageItem(new CandidateState()));
snapshot.Add(keyValidator, new StorageItem(new CandidateState() { Registered = true }));
ret = Check_Vote(snapshot, account.ToArray(), ECCurve.Secp256r1.G.ToArray(), true, _persistingBlock);
ret.State.Should().BeTrue();
ret.Result.Should().BeTrue();
Expand Down