mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-01 20:48:38 +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
|
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) {
|
||||||
|
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 {
|
for _, wantEv := range want {
|
||||||
nmatch := 0
|
if _, ok := filter[fmt.Sprintf("%s-%d", wantEv.a.Address.String(), wantEv.Kind)]; !ok {
|
||||||
for ; len(have) > 0; nmatch++ {
|
|
||||||
if have[0].Kind != wantEv.Kind || have[0].a != wantEv.a {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
have = have[1:]
|
|
||||||
}
|
|
||||||
if nmatch == 0 {
|
|
||||||
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…
Reference in a new issue