(node_factory)
| 4181 | |
| 4182 | |
| 4183 | def test_datastoreusage(node_factory): |
| 4184 | # Suppress plugins that use the datastore (same as test_datastore / test_datastore_keylist). |
| 4185 | l1: LightningNode = node_factory.get_node(options={"disable-plugin": ["cln-xpay", "bookkeeper", "bwatch"]}) |
| 4186 | assert l1.rpc.datastoreusage() == {'datastoreusage': {'key': '[]', 'total_bytes': 0}} |
| 4187 | |
| 4188 | data = 'somedatatostoreinthedatastore' # len 29 |
| 4189 | l1.rpc.datastore(key=["a", "b"], string=data) |
| 4190 | assert l1.rpc.datastoreusage() == {'datastoreusage': {'key': '[]', 'total_bytes': (29 + 1 + 1 + 1)}} |
| 4191 | assert l1.rpc.datastoreusage(key="a") == {'datastoreusage': {'key': '[a]', 'total_bytes': (29 + 1 + 1 + 1)}} |
| 4192 | assert l1.rpc.datastoreusage(key=["a", "b"]) == {'datastoreusage': {'key': '[a,b]', 'total_bytes': (29 + 1 + 1 + 1)}} |
| 4193 | |
| 4194 | # add second leaf |
| 4195 | l1.rpc.datastore(key=["a", "c"], string=data) |
| 4196 | assert l1.rpc.datastoreusage() == {'datastoreusage': {'key': '[]', 'total_bytes': (29 + 1 + 1 + 1 + 29 + 1 + 1 + 1)}} |
| 4197 | assert l1.rpc.datastoreusage(key=["a", "b"]) == {'datastoreusage': {'key': '[a,b]', 'total_bytes': (29 + 1 + 1 + 1)}} |
| 4198 | assert l1.rpc.datastoreusage(key=["a", "c"]) == {'datastoreusage': {'key': '[a,c]', 'total_bytes': (29 + 1 + 1 + 1)}} |
| 4199 | |
| 4200 | # check that the key is also counted as stored data |
| 4201 | l1.rpc.datastore(key=["a", "thisissomelongkeythattriestostore46bytesofdata"], string=data) |
| 4202 | assert l1.rpc.datastoreusage() == {'datastoreusage': {'key': '[]', 'total_bytes': (29 + 1 + 1 + 46 + 64)}} |
| 4203 | assert l1.rpc.datastoreusage(key=["a", "thisissomelongkeythattriestostore46bytesofdata"]) == {'datastoreusage': {'key': '[a,thisissomelongkeythattriestostore46bytesofdata]', 'total_bytes': (29 + 1 + 1 + 46)}} |
| 4204 | |
| 4205 | # check that the root is also counted |
| 4206 | l1.rpc.datastore(key=["thisissomelongkeythattriestostore46bytesofdata", "a"], string=data) |
| 4207 | assert l1.rpc.datastoreusage(key=["thisissomelongkeythattriestostore46bytesofdata", "a"]) == {'datastoreusage': {'key': '[thisissomelongkeythattriestostore46bytesofdata,a]', 'total_bytes': (29 + 1 + 1 + 46)}} |
| 4208 | |
| 4209 | # check really deep data |
| 4210 | l1.rpc.datastore(key=["a", "d", "e", "f", "g"], string=data) |
| 4211 | assert l1.rpc.datastoreusage(key=["a", "d", "e", "f", "g"]) == {'datastoreusage': {'key': '[a,d,e,f,g]', 'total_bytes': (29 + 1 + 1 + 1 + 1 + 1 + 4)}} |
| 4212 | assert l1.rpc.datastoreusage() == {'datastoreusage': {'key': '[]', 'total_bytes': (29 + 1 + 1 + 1 + 1 + 1 + 4 + 218)}} |
| 4213 | |
| 4214 | |
| 4215 | @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', |
nothing calls this directly
no test coverage detected