mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
fix: TestWalletNotifications checkEvents
This commit is contained in:
parent
a71f6f91fd
commit
cef3a9a762
1 changed files with 7 additions and 9 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package keystore
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime"
|
||||
|
|
@ -339,8 +340,8 @@ func TestWalletNotifications(t *testing.T) {
|
|||
for ev := range updates {
|
||||
events = append(events, walletEvent{ev, ev.Wallet.Accounts()[0]})
|
||||
}
|
||||
checkAccounts(t, live, ks.Wallets())
|
||||
checkEvents(t, wantEvents, events)
|
||||
checkAccounts(t, live, ks.Wallets())
|
||||
}
|
||||
|
||||
// TestImportECDSA tests the import functionality of a keystore.
|
||||
|
|
@ -443,15 +444,12 @@ func checkAccounts(t *testing.T, live map[common.Address]accounts.Account, walle
|
|||
|
||||
// checkEvents checks that all events in 'want' are present in 'have'. Events may be present multiple times.
|
||||
func checkEvents(t *testing.T, want []walletEvent, have []walletEvent) {
|
||||
filter := make(map[string]struct{})
|
||||
for _, haveEv := range have {
|
||||
filter[fmt.Sprintf("%s-%d", haveEv.a.Address.String(), haveEv.Kind)] = struct{}{}
|
||||
}
|
||||
for _, wantEv := range want {
|
||||
nmatch := 0
|
||||
for ; len(have) > 0; nmatch++ {
|
||||
if have[0].Kind != wantEv.Kind || have[0].a != wantEv.a {
|
||||
break
|
||||
}
|
||||
have = have[1:]
|
||||
}
|
||||
if nmatch == 0 {
|
||||
if _, ok := filter[fmt.Sprintf("%s-%d", wantEv.a.Address.String(), wantEv.Kind)]; !ok {
|
||||
t.Fatalf("can't find event with Kind=%v for %x", wantEv.Kind, wantEv.a.Address)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue