Skip to content

Commit

Permalink
pin cbrrr version, add CI testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Feb 25, 2024
1 parent bd46e4b commit d7d7b8e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests
run-name: ${{ github.actor }} is running tests
on: push
jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.11', '3.12' ]
name: Python ${{ matrix.python-version }} tests
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install atmst python module
run: |
python3 -m pip install -v .
- name: Run the tests
run: |
python3 -m unittest -v
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"cbrrr@git+https://github.com/DavidBuchanan314/dag-cbrrr",
"cbrrr==0.0.1",
"more-itertools",
"lru-dict",
]
Expand Down
8 changes: 4 additions & 4 deletions src/atmst/blockstore/car_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def __init__(self, file: BinaryIO, validate_hashes: bool=True) -> None:
break # EOF
start = file.tell()
CID_LENGTH = 36 # XXX: this is a questionable assumption!!!
cid = file.read(CID_LENGTH)
if cid[:4] != b"\x01\x71\x12\x20": # I think this is enough to verify the assumption
cid = CID(file.read(CID_LENGTH))
if not cid.is_cidv1_dag_cbor_sha256_32(): # I think this is enough to verify the assumption
raise ValueError("unsupported CID type")
self.block_offsets[cid] = (start + CID_LENGTH, length - CID_LENGTH)
self.block_offsets[bytes(cid)] = (start + CID_LENGTH, length - CID_LENGTH)
file.seek(start + length)

def put_block(self, key: bytes, value: bytes) -> None:
Expand All @@ -83,7 +83,7 @@ def get_block(self, key: bytes) -> bytes:
if len(value) != length:
raise EOFError()
if self.validate_hashes:
if key[:4] != b"\x01\x71\x12\x20":
if key[:4] != CID.CIDV1_DAG_CBOR_SHA256_32_PFX:
raise ValueError("unsupported CID type")
digest = hashlib.sha256(value).digest()
if digest != key[4:]:
Expand Down

0 comments on commit d7d7b8e

Please sign in to comment.