Skip to content

Commit

Permalink
client/asset/dcr: fix AccountOwnsAddress for foreign addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Aug 4, 2022
1 parent de176b4 commit cfdfcc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/asset/dcr/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func (w *spvWallet) AddressInfo(ctx context.Context, addrStr string) (*AddressIn
func (w *spvWallet) AccountOwnsAddress(ctx context.Context, addr stdaddr.Address, _ string) (bool, error) {
ka, err := w.KnownAddress(ctx, addr)
if err != nil {
if errors.Is(err, walleterrors.NotExist) {
return false, nil
}
return false, fmt.Errorf("KnownAddress error: %w", err)
}
if ka.AccountName() != w.acctName {
Expand Down
10 changes: 9 additions & 1 deletion client/asset/dcr/spv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ func TestAccountOwnsAddress(t *testing.T) {
t.Fatal("failed initial success. have = false")
}

// KnownAddress error
// Foreign address
dcrw.knownAddrErr = walleterrors.NotExist
if have, err := w.AccountOwnsAddress(tCtx, tPKHAddr, ""); err != nil {
t.Fatalf("unexpected error when should just be have = false for foreign address: %v", err)
} else if have {
t.Fatalf("shouldn't have, but have for foreign address")
}

// Other KnownAddress error
dcrw.knownAddrErr = tErr
if _, err := w.AccountOwnsAddress(tCtx, tPKHAddr, ""); err == nil {
t.Fatal("no error for KnownAddress error")
Expand Down

0 comments on commit cfdfcc4

Please sign in to comment.