@@ -56,7 +56,10 @@ func TestAliasStoreRequest(t *testing.T) {
5656 require .NoError (t , err )
5757 defer db .Close ()
5858
59+ updateChan := make (chan struct {}, 1 )
60+
5961 linkUpdater := func (shortID lnwire.ShortChannelID ) error {
62+ updateChan <- struct {}{}
6063 return nil
6164 }
6265
@@ -76,6 +79,88 @@ func TestAliasStoreRequest(t *testing.T) {
7679 require .Equal (t , nextAlias , alias2 )
7780}
7881
82+ // TestAliasLifecycle tests that the aliases can be created and deleted.
83+ func TestAliasLifecycle (t * testing.T ) {
84+ t .Parallel ()
85+
86+ // Create the backend database and use this to create the aliasStore.
87+ dbPath := filepath .Join (t .TempDir (), "testdb" )
88+ db , err := kvdb .Create (
89+ kvdb .BoltBackendName , dbPath , true , kvdb .DefaultDBTimeout ,
90+ )
91+ require .NoError (t , err )
92+ defer db .Close ()
93+
94+ updateChan := make (chan struct {}, 1 )
95+
96+ linkUpdater := func (shortID lnwire.ShortChannelID ) error {
97+ updateChan <- struct {}{}
98+ return nil
99+ }
100+
101+ aliasStore , err := NewManager (db , linkUpdater )
102+ require .NoError (t , err )
103+
104+ const (
105+ base = uint64 (123123123 )
106+ alias = uint64 (456456456 )
107+ )
108+
109+ // Parse the aliases and base to short channel ID format.
110+ baseScid := lnwire .NewShortChanIDFromInt (base )
111+ aliasScid := lnwire .NewShortChanIDFromInt (alias )
112+ aliasScid2 := lnwire .NewShortChanIDFromInt (alias + 1 )
113+
114+ // Add the first alias.
115+ err = aliasStore .AddLocalAlias (aliasScid , baseScid , false , true )
116+ require .NoError (t , err )
117+
118+ // The link updater should be called.
119+ <- updateChan
120+
121+ // Query the aliases and verify the results.
122+ aliasList := aliasStore .GetAliases (baseScid )
123+ require .Len (t , aliasList , 1 )
124+ require .Contains (t , aliasList , aliasScid )
125+
126+ // Add the second alias.
127+ err = aliasStore .AddLocalAlias (aliasScid2 , baseScid , false , true )
128+ require .NoError (t , err )
129+
130+ // The link updater should be called.
131+ <- updateChan
132+
133+ // Query the aliases and verify the results.
134+ aliasList = aliasStore .GetAliases (baseScid )
135+ require .Len (t , aliasList , 2 )
136+ require .Contains (t , aliasList , aliasScid )
137+ require .Contains (t , aliasList , aliasScid2 )
138+
139+ // Delete the first alias.
140+ err = aliasStore .DeleteLocalAlias (aliasScid , baseScid )
141+ require .NoError (t , err )
142+
143+ // The link updater should be called.
144+ <- updateChan
145+
146+ // Query the aliases and verify that first one doesn't exist anymore.
147+ aliasList = aliasStore .GetAliases (baseScid )
148+ require .Len (t , aliasList , 1 )
149+ require .Contains (t , aliasList , aliasScid2 )
150+ require .NotContains (t , aliasList , aliasScid )
151+
152+ // Delete the second alias.
153+ err = aliasStore .DeleteLocalAlias (aliasScid2 , baseScid )
154+ require .NoError (t , err )
155+
156+ // The link updater should be called.
157+ <- updateChan
158+
159+ // Query the aliases and verify that none exists.
160+ aliasList = aliasStore .GetAliases (baseScid )
161+ require .Len (t , aliasList , 0 )
162+ }
163+
79164// TestGetNextScid tests that given a current lnwire.ShortChannelID,
80165// getNextScid returns the expected alias to use next.
81166func TestGetNextScid (t * testing.T ) {
0 commit comments