fix: TestWalletNotifications checkEvents

pull/30053/head
Halimao 8 months ago
parent a71f6f91fd
commit cef3a9a762
  1. 16
      accounts/keystore/keystore_test.go

@ -17,6 +17,7 @@
package keystore package keystore
import ( import (
"fmt"
"math/rand" "math/rand"
"os" "os"
"runtime" "runtime"
@ -339,8 +340,8 @@ func TestWalletNotifications(t *testing.T) {
for ev := range updates { for ev := range updates {
events = append(events, walletEvent{ev, ev.Wallet.Accounts()[0]}) events = append(events, walletEvent{ev, ev.Wallet.Accounts()[0]})
} }
checkAccounts(t, live, ks.Wallets())
checkEvents(t, wantEvents, events) checkEvents(t, wantEvents, events)
checkAccounts(t, live, ks.Wallets())
} }
// TestImportECDSA tests the import functionality of a keystore. // 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. // 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) { func checkEvents(t *testing.T, want []walletEvent, have []walletEvent) {
for _, wantEv := range want { filter := make(map[string]struct{})
nmatch := 0 for _, haveEv := range have {
for ; len(have) > 0; nmatch++ { filter[fmt.Sprintf("%s-%d", haveEv.a.Address.String(), haveEv.Kind)] = struct{}{}
if have[0].Kind != wantEv.Kind || have[0].a != wantEv.a {
break
}
have = have[1:]
} }
if nmatch == 0 { for _, wantEv := range want {
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) t.Fatalf("can't find event with Kind=%v for %x", wantEv.Kind, wantEv.a.Address)
} }
} }

Loading…
Cancel
Save