@@ -9,25 +9,27 @@ import (
9
9
10
10
const (
11
11
testMetaCaveat = "lnd-custom lit-mac-fw meta:{\" actor_name\" :" +
12
- "\" re-balancer \" ,\" trigger\" :\" channel 7413345453234435345 " +
13
- "depleted\" ,\" intent\" :\" increase outbound liquidity by " +
14
- "2000000 sats\" }"
15
-
16
- testRulesCaveat = "lnd-custom lit-mac-fw rules:[{ \" name \" :" +
17
- " \" re-balance-limits \" , \" restrictions \" : " +
18
- "{ \" first-hop-ignore-list \" :\" 03abcd...,02badb01... \" , " +
19
- "\" max-hops \" : \" 4 \" , \" off-chain-fees-sats \" :\" 10 \" }} ," +
20
- "{ \" name \" :\" time-limits \" ,\" restrictions \" :" +
21
- "{ \" re-balance-min-interval-seconds\" :\" 3600\" }}] "
12
+ "\" autopilot \" , \" feature \" : \" re-balance \" ,\" trigger\" :" +
13
+ "\" channel 7413345453234435345 depleted\" ,\" intent\" :" +
14
+ "\" increase outbound liquidity by 2000000 sats\" ," +
15
+ " \" structured_json_data \" : \" {} \" }"
16
+
17
+ testRulesCaveat = "lnd-custom lit-mac-fw rules:{ \" session_rules \" :{ " +
18
+ "\" rate-limit \" :\" 1/10 \" }, \" feature_rules \" :{ \" AutoFees \" :{ " +
19
+ "\" first-hop-ignore-list \" :\" 03abcd...,02badb01... \" ," +
20
+ "\" max-hops \" :\" 4 \" } ,\" Rebalance \" :{ \" off-chain-fees-sats \" :" +
21
+ "\" 10 \" , \" re-balance-min-interval-seconds\" :\" 3600\" }}} "
22
22
)
23
23
24
24
// TestInterceptMetaInfo makes sure that a meta information struct can be
25
25
// formatted as a caveat and then parsed again successfully.
26
26
func TestInterceptMetaInfo (t * testing.T ) {
27
27
info := & InterceptMetaInfo {
28
- ActorName : "re-balancer" ,
29
- Trigger : "channel 7413345453234435345 depleted" ,
30
- Intent : "increase outbound liquidity by 2000000 sats" ,
28
+ ActorName : "autopilot" ,
29
+ Feature : "re-balance" ,
30
+ Trigger : "channel 7413345453234435345 depleted" ,
31
+ Intent : "increase outbound liquidity by 2000000 sats" ,
32
+ StructuredJsonData : "{}" ,
31
33
}
32
34
33
35
caveat , err := info .ToCaveat ()
@@ -90,19 +92,21 @@ func TestParseMetaInfoCaveat(t *testing.T) {
90
92
// TestInterceptRule makes sure that a rules list struct can be formatted as a
91
93
// caveat and then parsed again successfully.
92
94
func TestInterceptRule (t * testing.T ) {
93
- rules := []* InterceptRule {{
94
- Name : "re-balance-limits" ,
95
- Restrictions : map [string ]string {
96
- "off-chain-fees-sats" : "10" ,
97
- "max-hops" : "4" ,
98
- "first-hop-ignore-list" : "03abcd...,02badb01..." ,
95
+ rules := & InterceptRules {
96
+ FeatureRules : map [string ]map [string ]string {
97
+ "AutoFees" : {
98
+ "first-hop-ignore-list" : "03abcd...,02badb01..." ,
99
+ "max-hops" : "4" ,
100
+ },
101
+ "Rebalance" : {
102
+ "off-chain-fees-sats" : "10" ,
103
+ "re-balance-min-interval-seconds" : "3600" ,
104
+ },
99
105
},
100
- }, {
101
- Name : "time-limits" ,
102
- Restrictions : map [string ]string {
103
- "re-balance-min-interval-seconds" : "3600" ,
106
+ SessionRules : map [string ]string {
107
+ "rate-limit" : "1/10" ,
104
108
},
105
- }}
109
+ }
106
110
107
111
caveat , err := RulesToCaveat (rules )
108
112
require .NoError (t , err )
@@ -122,7 +126,7 @@ func TestParseRulesCaveat(t *testing.T) {
122
126
name string
123
127
input string
124
128
err error
125
- result [] * InterceptRule
129
+ result * InterceptRules
126
130
}{{
127
131
name : "empty string" ,
128
132
input : "" ,
@@ -138,23 +142,25 @@ func TestParseRulesCaveat(t *testing.T) {
138
142
"'b' looking for beginning of value" ),
139
143
}, {
140
144
name : "empty JSON" ,
141
- input : "lnd-custom lit-mac-fw rules:[]" ,
142
- result : []* InterceptRule {},
143
- }, {
144
- name : "empty rules" ,
145
- input : "lnd-custom lit-mac-fw rules:[{}, {}]" ,
146
- result : []* InterceptRule {{}, {}},
145
+ input : "lnd-custom lit-mac-fw rules:{}" ,
146
+ result : & InterceptRules {},
147
147
}, {
148
148
name : "valid rules" ,
149
- input : "lnd-custom lit-mac-fw rules:[{\" name\" :\" foo\" }, " +
150
- "{\" restrictions\" :{\" foo\" :\" bar\" }}]" ,
151
- result : []* InterceptRule {{
152
- Name : "foo" ,
153
- }, {
154
- Restrictions : map [string ]string {
155
- "foo" : "bar" ,
149
+ input : "lnd-custom lit-mac-fw rules:{\" session_rules\" :" +
150
+ "{\" rate-limit\" :\" 2000\" }, \" feature_rules\" :" +
151
+ "{\" Autofees\" :{\" foo\" :\" bar\" , \" rate-limit\" :" +
152
+ "\" 1000\" }}}" ,
153
+ result : & InterceptRules {
154
+ FeatureRules : map [string ]map [string ]string {
155
+ "Autofees" : {
156
+ "foo" : "bar" ,
157
+ "rate-limit" : "1000" ,
158
+ },
156
159
},
157
- }},
160
+ SessionRules : map [string ]string {
161
+ "rate-limit" : "2000" ,
162
+ },
163
+ },
158
164
}}
159
165
160
166
for _ , tc := range testCases {
0 commit comments