(node_factory)
| 4118 | |
| 4119 | |
| 4120 | def test_datastore_keylist(node_factory): |
| 4121 | # Suppress plugins that use the datastore (keep list empty for assertions below). |
| 4122 | l1 = node_factory.get_node(options={"disable-plugin": ["cln-xpay", "bookkeeper", "bwatch"]}) |
| 4123 | |
| 4124 | # Starts empty |
| 4125 | assert l1.rpc.listdatastore() == {'datastore': []} |
| 4126 | assert l1.rpc.listdatastore(['a']) == {'datastore': []} |
| 4127 | assert l1.rpc.listdatastore(['a', 'b']) == {'datastore': []} |
| 4128 | |
| 4129 | # Cannot add child to existing! |
| 4130 | l1.rpc.datastore(key='a', string='aval') |
| 4131 | with pytest.raises(RpcError, match=r'1206.*Parent key \[a\] exists'): |
| 4132 | l1.rpc.datastore(key=['a', 'b'], string='abval', |
| 4133 | mode='create-or-replace') |
| 4134 | # Listing subkey gives DNE. |
| 4135 | assert l1.rpc.listdatastore(['a', 'b']) == {'datastore': []} |
| 4136 | l1.rpc.deldatastore(key=['a']) |
| 4137 | |
| 4138 | # Create child key. |
| 4139 | l1.rpc.datastore(key=['a', 'b'], string='abval') |
| 4140 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 4141 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 4142 | 'generation': 0, |
| 4143 | 'string': 'abval', |
| 4144 | 'hex': b'abval'.hex()}]} |
| 4145 | |
| 4146 | # Cannot create key over that |
| 4147 | with pytest.raises(RpcError, match='has children'): |
| 4148 | l1.rpc.datastore(key='a', string='aval', mode='create-or-replace') |
| 4149 | |
| 4150 | # Can create another key. |
| 4151 | l1.rpc.datastore(key=['a', 'b2'], string='ab2val') |
| 4152 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 4153 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 4154 | 'string': 'abval', |
| 4155 | 'generation': 0, |
| 4156 | 'hex': b'abval'.hex()}, |
| 4157 | {'key': ['a', 'b2'], |
| 4158 | 'string': 'ab2val', |
| 4159 | 'generation': 0, |
| 4160 | 'hex': b'ab2val'.hex()}]} |
| 4161 | |
| 4162 | # Can create subkey. |
| 4163 | l1.rpc.datastore(key=['a', 'b3', 'c'], string='ab2val') |
| 4164 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 4165 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 4166 | 'string': 'abval', |
| 4167 | 'generation': 0, |
| 4168 | 'hex': b'abval'.hex()}, |
| 4169 | {'key': ['a', 'b2'], |
| 4170 | 'string': 'ab2val', |
| 4171 | 'generation': 0, |
| 4172 | 'hex': b'ab2val'.hex()}, |
| 4173 | {'key': ['a', 'b3']}]} |
| 4174 | |
| 4175 | # Can update subkey |
| 4176 | l1.rpc.datastore(key=['a', 'b3', 'c'], string='2', mode='must-append') |
| 4177 | assert l1.rpc.listdatastore(key=['a', 'b3', 'c']) == {'datastore': [{'key': ['a', 'b3', 'c'], |
nothing calls this directly
no test coverage detected