From 3dcfd5e873d5cd10903a550b0343dbe5f0bbcd5a Mon Sep 17 00:00:00 2001 From: Kamil Mukhametzyanov Date: Tue, 13 Oct 2020 09:14:57 +0300 Subject: [PATCH 1/2] fix waitlist --- core/state/waitlist/waitlist.go | 2 +- core/state/waitlist/waitlist_test.go | 52 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/core/state/waitlist/waitlist.go b/core/state/waitlist/waitlist.go index 2cdca5c0a..eb046d9fb 100644 --- a/core/state/waitlist/waitlist.go +++ b/core/state/waitlist/waitlist.go @@ -164,7 +164,7 @@ func (wl *WaitList) Delete(address types.Address, pubkey types.Pubkey, coin type value := big.NewInt(0) items := make([]Item, 0, len(w.List)-1) for _, item := range w.List { - if item.CandidateId != candidate.ID && item.Coin != coin { + if item.CandidateId != candidate.ID || item.Coin != coin { items = append(items, item) } else { value.Add(value, item.Value) diff --git a/core/state/waitlist/waitlist_test.go b/core/state/waitlist/waitlist_test.go index 795cacdbb..49e517bb9 100644 --- a/core/state/waitlist/waitlist_test.go +++ b/core/state/waitlist/waitlist_test.go @@ -54,3 +54,55 @@ func TestWaitListToGetByAddressAndPubKey(t *testing.T) { t.Fatal("Incorrect amount of items in waitlist") } } + +func TestWaitListToPartialDelete(t *testing.T) { + b := bus.NewBus() + b.SetChecker(checker.NewChecker(b)) + mutableTree, _ := tree.NewMutableTree(0, db.NewMemDB(), 1024) + + wl, err := NewWaitList(b, mutableTree) + if err != nil { + t.Fatal(err) + } + + candidatesState, err := candidates.NewCandidates(b, mutableTree) + if err != nil { + t.Fatal(err) + } + + addr, pubkey, coin, val := types.Address{0}, types.Pubkey{0}, types.GetBaseCoinID(), big.NewInt(1e18) + candidatesState.Create(addr, addr, addr, pubkey, 10) + + wl.AddWaitList(addr, pubkey, coin, val) + wl.AddWaitList(addr, pubkey, 1, val) + wl.AddWaitList(addr, pubkey, 2, val) + if err := wl.Commit(); err != nil { + t.Fatal(err) + } + + _, _, err = mutableTree.SaveVersion() + if err != nil { + t.Fatal(err) + } + + wl.Delete(addr, pubkey, 0) + wl.Delete(addr, pubkey, 1) + wl.AddWaitList(addr, pubkey, 1, big.NewInt(1e17)) + _, _, err = mutableTree.SaveVersion() + if err != nil { + t.Fatal(err) + } + + items := wl.GetByAddressAndPubKey(addr, pubkey) + if len(items) != 2 { + t.Fatal("Incorrect amount of items in waitlist") + } + + if items[1].Value.Cmp(big.NewInt(1e17)) != 0 || items[1].Coin != 1 { + t.Fatal("Invalid waitlist data") + } + + if items[0].Value.Cmp(val) != 0 || items[0].Coin != 2 { + t.Fatal("Invalid waitlist data") + } +} From 0b86bd1989b6dd9f81751257657288f4b8b4c85b Mon Sep 17 00:00:00 2001 From: Kamil Mukhametzyanov Date: Tue, 13 Oct 2020 09:54:25 +0300 Subject: [PATCH 2/2] fix --- core/state/waitlist/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/state/waitlist/model.go b/core/state/waitlist/model.go index 0ddc7be37..c33d191e6 100644 --- a/core/state/waitlist/model.go +++ b/core/state/waitlist/model.go @@ -22,6 +22,6 @@ func (m *Model) AddToList(candidateId uint32, coin types.CoinID, value *big.Int) m.List = append(m.List, Item{ CandidateId: candidateId, Coin: coin, - Value: value, + Value: new(big.Int).Set(value), }) }