mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
aliasmgr: add alias lifecycle test
This commit is contained in:
parent
9d90485eeb
commit
7ace55582b
1 changed files with 85 additions and 0 deletions
|
@ -56,7 +56,10 @@ func TestAliasStoreRequest(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
updateChan := make(chan struct{}, 1)
|
||||||
|
|
||||||
linkUpdater := func(shortID lnwire.ShortChannelID) error {
|
linkUpdater := func(shortID lnwire.ShortChannelID) error {
|
||||||
|
updateChan <- struct{}{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +79,88 @@ func TestAliasStoreRequest(t *testing.T) {
|
||||||
require.Equal(t, nextAlias, alias2)
|
require.Equal(t, nextAlias, alias2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAliasLifecycle tests that the aliases can be created and deleted.
|
||||||
|
func TestAliasLifecycle(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
// Create the backend database and use this to create the aliasStore.
|
||||||
|
dbPath := filepath.Join(t.TempDir(), "testdb")
|
||||||
|
db, err := kvdb.Create(
|
||||||
|
kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout,
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
updateChan := make(chan struct{}, 1)
|
||||||
|
|
||||||
|
linkUpdater := func(shortID lnwire.ShortChannelID) error {
|
||||||
|
updateChan <- struct{}{}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
aliasStore, err := NewManager(db, linkUpdater)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
const (
|
||||||
|
base = uint64(123123123)
|
||||||
|
alias = uint64(456456456)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parse the aliases and base to short channel ID format.
|
||||||
|
baseScid := lnwire.NewShortChanIDFromInt(base)
|
||||||
|
aliasScid := lnwire.NewShortChanIDFromInt(alias)
|
||||||
|
aliasScid2 := lnwire.NewShortChanIDFromInt(alias + 1)
|
||||||
|
|
||||||
|
// Add the first alias.
|
||||||
|
err = aliasStore.AddLocalAlias(aliasScid, baseScid, false, true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// The link updater should be called.
|
||||||
|
<-updateChan
|
||||||
|
|
||||||
|
// Query the aliases and verify the results.
|
||||||
|
aliasList := aliasStore.GetAliases(baseScid)
|
||||||
|
require.Len(t, aliasList, 1)
|
||||||
|
require.Contains(t, aliasList, aliasScid)
|
||||||
|
|
||||||
|
// Add the second alias.
|
||||||
|
err = aliasStore.AddLocalAlias(aliasScid2, baseScid, false, true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// The link updater should be called.
|
||||||
|
<-updateChan
|
||||||
|
|
||||||
|
// Query the aliases and verify the results.
|
||||||
|
aliasList = aliasStore.GetAliases(baseScid)
|
||||||
|
require.Len(t, aliasList, 2)
|
||||||
|
require.Contains(t, aliasList, aliasScid)
|
||||||
|
require.Contains(t, aliasList, aliasScid2)
|
||||||
|
|
||||||
|
// Delete the first alias.
|
||||||
|
err = aliasStore.DeleteLocalAlias(aliasScid, baseScid)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// The link updater should be called.
|
||||||
|
<-updateChan
|
||||||
|
|
||||||
|
// Query the aliases and verify that first one doesn't exist anymore.
|
||||||
|
aliasList = aliasStore.GetAliases(baseScid)
|
||||||
|
require.Len(t, aliasList, 1)
|
||||||
|
require.Contains(t, aliasList, aliasScid2)
|
||||||
|
require.NotContains(t, aliasList, aliasScid)
|
||||||
|
|
||||||
|
// Delete the second alias.
|
||||||
|
err = aliasStore.DeleteLocalAlias(aliasScid2, baseScid)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// The link updater should be called.
|
||||||
|
<-updateChan
|
||||||
|
|
||||||
|
// Query the aliases and verify that none exists.
|
||||||
|
aliasList = aliasStore.GetAliases(baseScid)
|
||||||
|
require.Len(t, aliasList, 0)
|
||||||
|
}
|
||||||
|
|
||||||
// TestGetNextScid tests that given a current lnwire.ShortChannelID,
|
// TestGetNextScid tests that given a current lnwire.ShortChannelID,
|
||||||
// getNextScid returns the expected alias to use next.
|
// getNextScid returns the expected alias to use next.
|
||||||
func TestGetNextScid(t *testing.T) {
|
func TestGetNextScid(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue