Skip to content

Commit e72efe8

Browse files
committed
tests: added example of currencyrate plugin RPC calls
1 parent f6253ba commit e72efe8

5 files changed

Lines changed: 88 additions & 16 deletions

File tree

doc/schemas/currencyconvert.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,20 @@
5252
],
5353
"resources": [
5454
"Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
55+
],
56+
"examples": [
57+
{
58+
"request": {
59+
"id": "example:currencyconvert#1",
60+
"method": "currencyconvert",
61+
"params": {
62+
"amount": 100,
63+
"currency": "USD"
64+
}
65+
},
66+
"response": {
67+
"msat": 155974480
68+
}
69+
}
5570
]
5671
}

doc/schemas/currencyrate.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
}
8787
},
8888
"response": {
89-
"rate": 67889.825
89+
"rate": 64113.052
9090
}
9191
},
9292
{
@@ -102,7 +102,7 @@
102102
}
103103
},
104104
"response": {
105-
"rate": 67931.9
105+
"rate": 64130.09
106106
}
107107
}
108108
]

doc/schemas/listcurrencyrates.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,44 @@
6363
],
6464
"resources": [
6565
"Main web site: [https://github.com/ElementsProject/lightning](https://github.com/ElementsProject/lightning)"
66+
],
67+
"examples": [
68+
{
69+
"request": {
70+
"id": "example:listcurrencyrates#1",
71+
"method": "listcurrencyrates",
72+
"params": {
73+
"currency": "USD"
74+
}
75+
},
76+
"response": {
77+
"currencyrates": [
78+
{
79+
"amount": 64130.09,
80+
"source": "binance"
81+
},
82+
{
83+
"amount": 64099.33,
84+
"source": "blockchain.info"
85+
},
86+
{
87+
"amount": 64117.405,
88+
"source": "coinbase"
89+
},
90+
{
91+
"amount": 64117.67,
92+
"source": "bitstamp"
93+
},
94+
{
95+
"amount": 64108.7,
96+
"source": "kraken"
97+
},
98+
{
99+
"amount": 64103.0,
100+
"source": "coingecko"
101+
}
102+
]
103+
}
104+
}
66105
]
67106
}

doc/schemas/listnetworkevents.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,74 +171,74 @@
171171
"type": "connect",
172172
"timestamp": 1738000000,
173173
"reason": "connect command \"pytest:connect#22\"",
174-
"duration_nsec": 2331000
174+
"duration_nsec": 1477000
175175
},
176176
{
177177
"created_index": 3,
178178
"peer_id": "0258f3ff3e0853ccc09f6fe89823056d7c0c55c95fab97674df5e1ad97a72f6265",
179179
"type": "connect",
180180
"timestamp": 1738000000,
181181
"reason": "connect command \"pytest:connect#24\"",
182-
"duration_nsec": 1476000
182+
"duration_nsec": 949000
183183
},
184184
{
185185
"created_index": 4,
186186
"peer_id": "038194b5f32bdf0aa59812c86c4ef7ad2f294104fa027d1ace9b469bb6f88cf37b",
187187
"type": "ping",
188188
"timestamp": 1738000000,
189-
"duration_nsec": 327000
189+
"duration_nsec": 364000
190190
},
191191
{
192192
"created_index": 5,
193193
"peer_id": "02287bfac8b99b35477ebe9334eede1e32b189e24644eb701c079614712331cec0",
194194
"type": "connect",
195195
"timestamp": 1738000000,
196-
"reason": "connect command \"pytest:connect#420\"",
197-
"duration_nsec": 2546000
196+
"reason": "connect command \"pytest:connect#416\"",
197+
"duration_nsec": 1844000
198198
},
199199
{
200200
"created_index": 6,
201201
"peer_id": "02287bfac8b99b35477ebe9334eede1e32b189e24644eb701c079614712331cec0",
202202
"type": "disconnect",
203203
"timestamp": 1738000000,
204-
"duration_nsec": 8447000
204+
"duration_nsec": 7947000
205205
},
206206
{
207207
"created_index": 7,
208208
"peer_id": "0258f3ff3e0853ccc09f6fe89823056d7c0c55c95fab97674df5e1ad97a72f6265",
209209
"type": "disconnect",
210210
"timestamp": 1738000000,
211-
"duration_nsec": 81968678000
211+
"duration_nsec": 78635382000
212212
},
213213
{
214214
"created_index": 8,
215215
"peer_id": "0258f3ff3e0853ccc09f6fe89823056d7c0c55c95fab97674df5e1ad97a72f6265",
216216
"type": "connect",
217217
"timestamp": 1738000000,
218218
"reason": "reconnect by timer",
219-
"duration_nsec": 4035000
219+
"duration_nsec": 3529000
220220
},
221221
{
222222
"created_index": 9,
223223
"peer_id": "02287bfac8b99b35477ebe9334eede1e32b189e24644eb701c079614712331cec0",
224224
"type": "connect",
225225
"timestamp": 1738000000,
226-
"reason": "connect command \"pytest:connect#462\"",
227-
"duration_nsec": 918000
226+
"reason": "connect command \"pytest:connect#458\"",
227+
"duration_nsec": 633000
228228
},
229229
{
230230
"created_index": 10,
231231
"peer_id": "02287bfac8b99b35477ebe9334eede1e32b189e24644eb701c079614712331cec0",
232232
"type": "disconnect",
233233
"timestamp": 1738000000,
234-
"duration_nsec": 6087454000
234+
"duration_nsec": 6094786000
235235
},
236236
{
237237
"created_index": 11,
238238
"peer_id": "0258f3ff3e0853ccc09f6fe89823056d7c0c55c95fab97674df5e1ad97a72f6265",
239239
"type": "disconnect",
240240
"timestamp": 1738000000,
241-
"duration_nsec": 58975900000
241+
"duration_nsec": 58905461000
242242
}
243243
]
244244
}
@@ -261,7 +261,7 @@
261261
"type": "connect",
262262
"timestamp": 1738000000,
263263
"reason": "connect command \"pytest:connect#22\"",
264-
"duration_nsec": 2331000
264+
"duration_nsec": 1477000
265265
}
266266
]
267267
}

tests/autogenerate-rpc-examples.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
ALL_RPC_EXAMPLES = {}
3434
EXAMPLES_JSON = {}
3535
LOG_FILE = './tests/autogenerate-examples-status.log'
36-
IGNORE_RPCS_LIST = ['dev-splice', 'reckless', 'sql-template', 'currencyconvert', 'splicein', 'createproof', 'clnrest-register-path', 'sendamount', 'graceful', 'askrene-remove-channel-update', 'currencyrate', 'spliceout', 'askrene-bias-node', 'xkeysend', 'listcurrencyrates', 'delnetworkevent', 'cancelrecurringinvoice', 'injectonionmessage']
36+
IGNORE_RPCS_LIST = ['dev-splice', 'reckless', 'sql-template', 'splicein', 'createproof', 'clnrest-register-path', 'sendamount', 'graceful', 'askrene-remove-channel-update', 'spliceout', 'askrene-bias-node', 'xkeysend', 'delnetworkevent', 'cancelrecurringinvoice', 'injectonionmessage']
3737
EXPECTED_WALLET_TXIDS = defaultdict(set)
3838

3939

@@ -1653,6 +1653,23 @@ def generate_list_examples(bitcoind, l1, l2, l3, c12, c23_2, inv_l31, inv_l32, o
16531653
raise
16541654

16551655

1656+
def generate_currencyrate_examples(l3):
1657+
"""Generates plugin currencyrate examples"""
1658+
try:
1659+
logger.info('Currencyrate Start...')
1660+
list_currencies_res1 = l3.rpc.listcurrencyrates(currency='USD')
1661+
update_example(node=l3, method='listcurrencyrates', params={'currency': 'USD'}, response=list_currencies_res1)
1662+
currencyconvert_res1 = l3.rpc.currencyconvert(amount=100, currency='USD')
1663+
update_example(node=l3, method='currencyconvert', params={'amount': 100, 'currency': 'USD'}, response=currencyconvert_res1)
1664+
currencyrate_res1 = l3.rpc.currencyrate(currency="USD")
1665+
update_example(node=l3, method='currencyrate', params={'currency': 'USD'}, description=["Get the median BTC/USD rate across all configured sources:"], response=currencyrate_res1)
1666+
currencyrate_res2 = l3.rpc.currencyrate(currency='USD', source='binance')
1667+
update_example(node=l3, method='currencyrate', params={'currency': 'USD', 'source': 'binance'}, description=["Get the BTC/USD rate from the Binance source only:"], response=currencyrate_res2)
1668+
logger.info('Currencyrate Done!')
1669+
except Exception as e:
1670+
logger.error(f'Error in generating currencyrate examples: {e}')
1671+
1672+
16561673
@pytest.fixture(autouse=True)
16571674
def setup_logging():
16581675
logger.setLevel(logging.DEBUG)
@@ -1770,6 +1787,7 @@ def list_missing_examples():
17701787
generate_autoclean_delete_examples(l1, l2, l3, l4, l5, c12, c23)
17711788
generate_backup_recovery_examples(node_factory, l4, l5, l6, regenerate_blockchain)
17721789
generate_list_examples(bitcoind, l1, l2, l3, c12, c23_2, inv_l31, inv_l32, offer_l23, inv_req_l1_l22, address_l22)
1790+
generate_currencyrate_examples(l3)
17731791
update_examples_in_schema_files()
17741792
logger.info('All Done!!!')
17751793
except Exception as e:

0 commit comments

Comments
 (0)