@@ -3734,12 +3734,12 @@ func TestDisabledChannelIDs(t *testing.T) {
3734
3734
}
3735
3735
}
3736
3736
3737
- // TestEdgePolicyMissingMaxHtcl tests that if we find a ChannelEdgePolicy in
3737
+ // TestEdgePolicyMissingMaxHTLC tests that if we find a ChannelEdgePolicy in
3738
3738
// the DB that indicates that it should support the htlc_maximum_value_msat
3739
3739
// field, but it is not part of the opaque data, then we'll handle it as it is
3740
3740
// unknown. It also checks that we are correctly able to overwrite it when we
3741
3741
// receive the proper update.
3742
- func TestEdgePolicyMissingMaxHtcl (t * testing.T ) {
3742
+ func TestEdgePolicyMissingMaxHTLC (t * testing.T ) {
3743
3743
t .Parallel ()
3744
3744
ctx := context .Background ()
3745
3745
@@ -3797,45 +3797,10 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
3797
3797
require .ErrorIs (t , err , ErrEdgePolicyOptionalFieldNotFound )
3798
3798
3799
3799
// Put the stripped bytes in the DB.
3800
- err = kvdb .Update (boltStore .db , func (tx kvdb.RwTx ) error {
3801
- edges := tx .ReadWriteBucket (edgeBucket )
3802
- if edges == nil {
3803
- return ErrEdgeNotFound
3804
- }
3805
-
3806
- edgeIndex := edges .NestedReadWriteBucket (edgeIndexBucket )
3807
- if edgeIndex == nil {
3808
- return ErrEdgeNotFound
3809
- }
3810
-
3811
- var edgeKey [33 + 8 ]byte
3812
- copy (edgeKey [:], from )
3813
- byteOrder .PutUint64 (edgeKey [33 :], edge1 .ChannelID )
3814
-
3815
- var scratch [8 ]byte
3816
- var indexKey [8 + 8 ]byte
3817
- copy (indexKey [:], scratch [:])
3818
- byteOrder .PutUint64 (indexKey [8 :], edge1 .ChannelID )
3819
-
3820
- updateIndex , err := edges .CreateBucketIfNotExists (
3821
- edgeUpdateIndexBucket ,
3822
- )
3823
- if err != nil {
3824
- return err
3825
- }
3826
-
3827
- if err := updateIndex .Put (indexKey [:], nil ); err != nil {
3828
- return err
3829
- }
3830
-
3831
- return edges .Put (edgeKey [:], stripped )
3832
- }, func () {})
3833
- require .NoError (t , err , "error writing db" )
3800
+ putSerializedPolicy (t , boltStore .db , from , chanID , stripped )
3834
3801
3835
3802
// And add the second, unmodified edge.
3836
- if err := graph .UpdateEdgePolicy (ctx , edge2 ); err != nil {
3837
- t .Fatalf ("unable to update edge: %v" , err )
3838
- }
3803
+ require .NoError (t , graph .UpdateEdgePolicy (ctx , edge2 ))
3839
3804
3840
3805
// Attempt to fetch the edge and policies from the DB. Since the policy
3841
3806
// we added is invalid according to the new format, it should be as we
@@ -3870,6 +3835,38 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
3870
3835
assertEdgeInfoEqual (t , dbEdgeInfo , edgeInfo )
3871
3836
}
3872
3837
3838
+ // putSerializedPolicy is a helper function that writes a serialized
3839
+ // ChannelEdgePolicy to the edge bucket in the database.
3840
+ func putSerializedPolicy (t * testing.T , db kvdb.Backend , from []byte ,
3841
+ chanID uint64 , b []byte ) {
3842
+
3843
+ err := kvdb .Update (db , func (tx kvdb.RwTx ) error {
3844
+ edges := tx .ReadWriteBucket (edgeBucket )
3845
+ require .NotNil (t , edges )
3846
+
3847
+ edgeIndex := edges .NestedReadWriteBucket (edgeIndexBucket )
3848
+ require .NotNil (t , edgeIndex )
3849
+
3850
+ var edgeKey [33 + 8 ]byte
3851
+ copy (edgeKey [:], from )
3852
+ byteOrder .PutUint64 (edgeKey [33 :], chanID )
3853
+
3854
+ var scratch [8 ]byte
3855
+ var indexKey [8 + 8 ]byte
3856
+ copy (indexKey [:], scratch [:])
3857
+ byteOrder .PutUint64 (indexKey [8 :], chanID )
3858
+
3859
+ updateIndex , err := edges .CreateBucketIfNotExists (
3860
+ edgeUpdateIndexBucket ,
3861
+ )
3862
+ require .NoError (t , err )
3863
+ require .NoError (t , updateIndex .Put (indexKey [:], nil ))
3864
+
3865
+ return edges .Put (edgeKey [:], b )
3866
+ }, func () {})
3867
+ require .NoError (t , err , "error writing db" )
3868
+ }
3869
+
3873
3870
// assertNumZombies queries the provided ChannelGraph for NumZombies, and
3874
3871
// asserts that the returned number is equal to expZombies.
3875
3872
func assertNumZombies (t * testing.T , graph * ChannelGraph , expZombies uint64 ) {
0 commit comments