Skip to content

Commit 384fc82

Browse files
authored
Merge pull request #73 from davxy/ci
[CI] Vectors Validation
2 parents dfe2a78 + 3397ce4 commit 384fc82

File tree

13 files changed

+203
-183
lines changed

13 files changed

+203
-183
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI Workflow
2+
3+
on:
4+
# Run CI on push only for 'main' branch
5+
push:
6+
branches: [main]
7+
tags:
8+
- "v*"
9+
# Run CI on pull request for all branches
10+
pull_request:
11+
branches: ["**"]
12+
13+
jobs:
14+
validate:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
validator: [codec, accumulate, assurances, authorizations, disputes, history, preimages, reports, safrole, statistics]
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.8'
26+
- name: Install dependencies
27+
run: |
28+
pip install git+https://github.com/davxy/asn1tools.git
29+
- name: Validate ${{ matrix.validator }}
30+
run: ./${{ matrix.validator }}/validate.py

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ specific subsystem.
5555
- [Fallback](./traces/fallback): fallback block authoring, no-safrole, no-work-reports
5656
- [Safrole](./traces/safrole): safrole block authoring, no-work-reports
5757
- [Work Reports L0](./traces/reports-l0): basic work reports, no-safrole
58+
59+
## Vectors Validation
60+
61+
Validation scripts are included to verify the JSON files against the expected
62+
ASN.1 syntax provided with the test vectors. These scripts currently rely on my
63+
[asn1tools](https://github.com/davxy/asn1tools) fork.

accumulate/validate.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22

33
import os
44
import sys
5-
from pathlib import Path
65

7-
import asn1tools
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
88

9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

11+
os.chdir(script_dir)
1212

13-
# Validate tiny
14-
schema = asn1tools.compile_files(get_schema_files(False) + ["accumulate.asn"], codec="jer")
15-
for path in Path("tiny").iterdir():
16-
if path.is_file() and path.suffix == ".json":
17-
validate(schema, path, "TestCase")
18-
19-
# Validate full
20-
schema = asn1tools.compile_files(get_schema_files(True) + ["accumulate.asn"], codec="jer")
21-
for path in Path("full").iterdir():
22-
if path.is_file() and path.suffix == ".json":
23-
validate(schema, path, "TestCase")
13+
for spec in ["tiny", "full"]:
14+
validate_group("accumulate", "accumulate.asn", spec)

assurances/validate.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import os
44
import sys
5-
from pathlib import Path
65

7-
import asn1tools
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
88

9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

11+
os.chdir(script_dir)
1212

1313
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1414
def tweak_assignments_sequence_of_options(state_obj):
@@ -19,21 +19,10 @@ def tweak_assignments_sequence_of_options(state_obj):
1919
else:
2020
items[i] = {"some": items[i]}
2121

22-
2322
def tweak_callback(json_obj):
2423
tweak_assignments_sequence_of_options(json_obj['pre_state'])
2524
tweak_assignments_sequence_of_options(json_obj['post_state'])
2625
return json_obj
2726

28-
29-
# Validate tiny
30-
schema = asn1tools.compile_files(get_schema_files(False) + ["assurances.asn"], codec="jer")
31-
for path in Path("tiny").iterdir():
32-
if path.is_file() and path.suffix == ".json":
33-
validate(schema, path, "TestCase", tweak_callback)
34-
35-
# Validate full
36-
schema = asn1tools.compile_files(get_schema_files(True) + ["assurances.asn"], codec="jer")
37-
for path in Path("full").iterdir():
38-
if path.is_file() and path.suffix == ".json":
39-
validate(schema, path, "TestCase", tweak_callback)
27+
for spec in ["tiny", "full"]:
28+
validate_group("assurances", "assurances.asn", spec, tweak_callback)

authorizations/validate.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@
22

33
import os
44
import sys
5-
from pathlib import Path
65

7-
import asn1tools
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
88

9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

11+
os.chdir(script_dir)
1212

13-
# Validate tiny
14-
schema = asn1tools.compile_files(get_schema_files(False) + ["authorizations.asn"], codec="jer")
15-
for path in Path("tiny").iterdir():
16-
if path.is_file() and path.suffix == ".json":
17-
validate(schema, path, "TestCase")
18-
19-
# Validate full
20-
schema = asn1tools.compile_files(get_schema_files(True) + ["authorizations.asn"], codec="jer")
21-
for path in Path("full").iterdir():
22-
if path.is_file() and path.suffix == ".json":
23-
validate(schema, path, "TestCase")
13+
for spec in ["tiny", "full"]:
14+
validate_group("authorizations", "authorizations.asn", spec)

codec/validate.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
#!/usr/bin/env python
22

3-
from pathlib import Path
4-
import asn1tools
53
import os
64
import sys
75

8-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
98

10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

12-
# Validate tiny
13-
print("[Validating Tiny Spec]")
14-
schema = asn1tools.compile_files(get_schema_files(False), codec="jer")
15-
for path in Path("tiny").iterdir():
16-
if path.is_file() and path.suffix == ".json":
17-
validate(schema, path)
18-
19-
# Validate full
20-
print("[Validating Full Spec]")
21-
schema = asn1tools.compile_files(get_schema_files(True), codec="jer")
22-
for path in Path("full").iterdir():
23-
if path.is_file() and path.suffix == ".json":
24-
validate(schema, path)
11+
os.chdir(script_dir)
12+
13+
for spec in ["tiny", "full"]:
14+
validate_group("codec", None, spec)

disputes/validate.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import os
44
import sys
5-
from pathlib import Path
65

7-
import asn1tools
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
88

9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

11+
os.chdir(script_dir)
1212

1313
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1414
def tweak_sequence_of_options(state_obj):
@@ -20,21 +20,10 @@ def tweak_sequence_of_options(state_obj):
2020
items[i] = {"some": items[i]}
2121
return state_obj
2222

23-
2423
def tweak_callback(json_obj):
2524
tweak_sequence_of_options(json_obj['pre_state'])
2625
tweak_sequence_of_options(json_obj['post_state'])
2726
return json_obj
2827

29-
30-
# Validate tiny
31-
schema = asn1tools.compile_files(get_schema_files(False) + ["disputes.asn"], codec="jer")
32-
for path in Path("tiny").iterdir():
33-
if path.is_file() and path.suffix == ".json":
34-
validate(schema, path, "TestCase", tweak_callback)
35-
36-
# Validate full
37-
schema = asn1tools.compile_files(get_schema_files(True) + ["disputes.asn"], codec="jer")
38-
for path in Path("full").iterdir():
39-
if path.is_file() and path.suffix == ".json":
40-
validate(schema, path, "TestCase", tweak_callback)
28+
for spec in ["tiny", "full"]:
29+
validate_group("disputes", "disputes.asn", spec, tweak_callback)

history/validate.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import os
44
import sys
5-
from pathlib import Path
65

7-
import asn1tools
6+
script_dir = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
88

9-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../jam-types-asn')))
10-
from utils import get_schema_files, validate
9+
from utils import validate_group # noqa: E402
1110

11+
os.chdir(script_dir)
1212

1313
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1414
def tweak_sequence_of_options(state_obj):
@@ -21,14 +21,9 @@ def tweak_sequence_of_options(state_obj):
2121
peaks[i] = {"some": peaks[i]}
2222
return state_obj
2323

24-
2524
def tweak_callback(json_obj):
2625
tweak_sequence_of_options(json_obj['pre_state'])
2726
tweak_sequence_of_options(json_obj['post_state'])
2827
return json_obj
2928

30-
31-
schema = asn1tools.compile_files(get_schema_files() + ["history.asn"], codec="jer")
32-
for path in Path("data").iterdir():
33-
if path.is_file() and path.suffix == ".json":
34-
validate(schema, path, "TestCase", tweak_callback)
29+
validate_group("history", "history.asn", "data", tweak_callback)

0 commit comments

Comments
 (0)