| 2741 | |
| 2742 | |
| 2743 | def test_datastore_keylist(node_factory): |
| 2744 | l1 = node_factory.get_node() |
| 2745 | |
| 2746 | # Starts empty |
| 2747 | assert l1.rpc.listdatastore() == {'datastore': []} |
| 2748 | assert l1.rpc.listdatastore(['a']) == {'datastore': []} |
| 2749 | assert l1.rpc.listdatastore(['a', 'b']) == {'datastore': []} |
| 2750 | |
| 2751 | # Cannot add child to existing! |
| 2752 | l1.rpc.datastore(key='a', string='aval') |
| 2753 | with pytest.raises(RpcError, match=r'1206.*Parent key \[a\] exists'): |
| 2754 | l1.rpc.datastore(key=['a', 'b'], string='abval', |
| 2755 | mode='create-or-replace') |
| 2756 | # Listing subkey gives DNE. |
| 2757 | assert l1.rpc.listdatastore(['a', 'b']) == {'datastore': []} |
| 2758 | l1.rpc.deldatastore(key=['a']) |
| 2759 | |
| 2760 | # Create child key. |
| 2761 | l1.rpc.datastore(key=['a', 'b'], string='abval') |
| 2762 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 2763 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 2764 | 'generation': 0, |
| 2765 | 'string': 'abval', |
| 2766 | 'hex': b'abval'.hex()}]} |
| 2767 | |
| 2768 | # Cannot create key over that |
| 2769 | with pytest.raises(RpcError, match='has children'): |
| 2770 | l1.rpc.datastore(key='a', string='aval', mode='create-or-replace') |
| 2771 | |
| 2772 | # Can create another key. |
| 2773 | l1.rpc.datastore(key=['a', 'b2'], string='ab2val') |
| 2774 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 2775 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 2776 | 'string': 'abval', |
| 2777 | 'generation': 0, |
| 2778 | 'hex': b'abval'.hex()}, |
| 2779 | {'key': ['a', 'b2'], |
| 2780 | 'string': 'ab2val', |
| 2781 | 'generation': 0, |
| 2782 | 'hex': b'ab2val'.hex()}]} |
| 2783 | |
| 2784 | # Can create subkey. |
| 2785 | l1.rpc.datastore(key=['a', 'b3', 'c'], string='ab2val') |
| 2786 | assert l1.rpc.listdatastore() == {'datastore': [{'key': ['a']}]} |
| 2787 | assert l1.rpc.listdatastore(key=['a']) == {'datastore': [{'key': ['a', 'b'], |
| 2788 | 'string': 'abval', |
| 2789 | 'generation': 0, |
| 2790 | 'hex': b'abval'.hex()}, |
| 2791 | {'key': ['a', 'b2'], |
| 2792 | 'string': 'ab2val', |
| 2793 | 'generation': 0, |
| 2794 | 'hex': b'ab2val'.hex()}, |
| 2795 | {'key': ['a', 'b3']}]} |
| 2796 | |
| 2797 | # Can update subkey |
| 2798 | l1.rpc.datastore(key=['a', 'b3', 'c'], string='2', mode='must-append') |
| 2799 | assert l1.rpc.listdatastore(key=['a', 'b3', 'c']) == {'datastore': [{'key': ['a', 'b3', 'c'], |
| 2800 | 'string': 'ab2val2', |