Skip to content

Commit

Permalink
backend: add another watchonly unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Dec 14, 2023
1 parent 1d890c8 commit 2335f10
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,4 +1523,48 @@ func TestWatchonly(t *testing.T) {
checkShownAccountsLen(t, b, 3, 6)
})

// Adding new accounts after the keytore has been connected: new account is watched if the
// keystore is already watched.
t.Run("", func(t *testing.T) {
b := newBackend(t, testnetDisabled, regtestDisabled)
defer b.Close()

ks := makeBitBox02Multi()

rootFingerprint, err := ks.RootFingerprint()
require.NoError(t, err)

b.registerKeystore(ks)
checkShownAccountsLen(t, b, 3, 3)
require.NoError(t, b.SetWatchonly(rootFingerprint, true))

// An account may already have been added as part of autodiscover, so we add two.
newAccountCode1, err := b.CreateAndPersistAccountConfig(
coinpkg.CodeBTC,
"Bitcoin account name",
ks,
)
require.NoError(t, err)
require.Equal(t, accountsTypes.Code("v0-55555555-btc-1"), newAccountCode1)

expectedNewAccountCode2 := accountsTypes.Code("v0-55555555-btc-2")
// Make sure the account to be added has not been added yet (autodiscover), so we know we
// are testing the correct setting of the Watch flag when a new account is persisted.
require.Nil(t, b.Config().AccountsConfig().Lookup(expectedNewAccountCode2))

newAccountCode2, err := b.CreateAndPersistAccountConfig(
coinpkg.CodeBTC,
"Bitcoin account name 2",
ks,
)
require.NoError(t, err)
require.Equal(t, expectedNewAccountCode2, newAccountCode2)

require.NoError(t, err)

b.DeregisterKeystore()

// Accounts, including the newly added ones, remain loaded.
checkShownAccountsLen(t, b, 5, 5)
})
}

0 comments on commit 2335f10

Please sign in to comment.