Example #1
0
def test_database_store_from_text_store_initial_version(data) -> None:
    wallet_path = tempfile.mktemp()
    text_store = TextStore(wallet_path, data=data)
    try:
        # Verify that the seed version is rejected (the assertion is hit).
        with pytest.raises(AssertionError):
            DatabaseStore.from_text_store(text_store)
    finally:
        text_store.close()
Example #2
0
def test_database_store_from_text_store_version_init_set(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "database")
    try:
        text_store = TextStore(wallet_path,
                               data={"seed_version": MIGRATION_FIRST})
        # Verify that the seed version is accepted (no assertion hit).
        db_store = DatabaseStore.from_text_store(text_store)
        _check_database_store_version_init_set(db_store, MIGRATION_CURRENT)
    finally:
        db_store.close()
        text_store.close()
Example #3
0
def test_database_store_from_text_store_version_init_set() -> None:
    wallet_path = tempfile.mktemp()
    try:
        text_store = TextStore(
            wallet_path,
            data={"seed_version": DatabaseStore.INITIAL_MIGRATION})
        # Verify that the seed version is accepted (no assertion hit).
        db_store = DatabaseStore.from_text_store(text_store)
        _check_database_store_version_init_set(db_store,
                                               DatabaseStore.INITIAL_MIGRATION)
    finally:
        db_store.close()
        text_store.close()
Example #4
0
def test_textstore_read_raw_data(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "wallet")
    store = TextStore(wallet_path)
    try:
        # No write operation has been done yet on the store.
        with pytest.raises(FileNotFoundError):
            store._read_raw_data()
        # Commit the empty JSON lump to disk.
        store.write()
        data = store._read_raw_data()
        assert data == b'{}'
        assert not store.is_encrypted()
    finally:
        store.close()
Example #5
0
def test_text_store__write_version_incompatible(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "database")
    store = TextStore(wallet_path)
    try:
        store.put("seed_version", TextStore.FINAL_SEED_VERSION + 1)
        with pytest.raises(IncompatibleWalletError):
            store.write()
    finally:
        store.close()
Example #6
0
def test_text_store__write_version_incompatible() -> None:
    wallet_path = tempfile.mktemp()
    store = TextStore(wallet_path)
    try:
        store.put("seed_version", TextStore.FINAL_SEED_VERSION + 1)
        with pytest.raises(IncompatibleWalletError):
            store.write()
    finally:
        store.close()
Example #7
0
def test_text_store__raise_unsupported_version() -> None:
    wallet_path = tempfile.mktemp()
    store = TextStore(wallet_path)

    with pytest.raises(Exception) as e:
        store._raise_unsupported_version(5)
    assert "To open this wallet" in e.value.args[0]

    with pytest.raises(Exception) as e:
        store._raise_unsupported_version(6)
    assert "It does not contain any keys" in e.value.args[0]

    store.put("master_public_keys", 1)

    with pytest.raises(Exception) as e:
        store._raise_unsupported_version(6)
    assert "Please open this file" in e.value.args[0]
Example #8
0
def test_textstore_load_data_valid(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "wallet")
    store = TextStore(wallet_path)
    try:
        store.load_data(b"{}")
    finally:
        store.close()
Example #9
0
def test_textstore_load_data_valid() -> None:
    wallet_path = tempfile.mktemp()
    store = TextStore(wallet_path)
    try:
        store.load_data(b"{}")
    finally:
        store.close()
Example #10
0
def test_store_load_data_invalid(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "wallet")
    store = TextStore(wallet_path)
    try:
        with pytest.raises(OSError):
            store.load_data(b"x{}")
    finally:
        store.close()
Example #11
0
def test_store_load_data_invalid() -> None:
    wallet_path = tempfile.mktemp()
    store = TextStore(wallet_path)
    try:
        with pytest.raises(OSError):
            store.load_data(b"x{}")
    finally:
        store.close()
Example #12
0
def test_text_store__raise_unsupported_version(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "database")
    store = TextStore(wallet_path)
    try:
        with pytest.raises(Exception) as e:
            store._raise_unsupported_version(5)
        assert "To open this wallet" in e.value.args[0]

        with pytest.raises(Exception) as e:
            store._raise_unsupported_version(6)
        assert "It does not contain any keys" in e.value.args[0]

        store.put("master_public_keys", 1)

        with pytest.raises(Exception) as e:
            store._raise_unsupported_version(6)
        assert "Please open this file" in e.value.args[0]
    finally:
        store.close()
Example #13
0
def test_store__write(tmp_path) -> None:
    wallet_path = os.path.join(tmp_path, "wallet")
    store = TextStore(wallet_path)
    try:
        assert not store.is_primed()
        store.put("number", 10)
        store._write()
        assert store.is_primed()
        # This will raise an assertion if there is not locatible JSON lump.
        store._read_raw_data()
        assert store.get("number") == 10
    finally:
        store.close()

    store = TextStore(wallet_path)
    try:
        assert store.is_primed()
        # We need to do this here because the wallet storage normally does it.
        store.load_data(store._read_raw_data())
        assert store.get("number") == 10
    finally:
        store.close()