Skip to content

Commit 5324160

Browse files
committed
And the rest
1 parent 71d2305 commit 5324160

File tree

8 files changed

+80
-81
lines changed

8 files changed

+80
-81
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
pip install git+https://github.com/davxy/asn1tools.git
2626
- name: Validate vectors
2727
run: |
28-
for v in codec accumulate assurances authorizations; do
28+
for v in codec accumulate assurances authorizations disputes history preimages reports safrole statistics; do
2929
echo "========= Validating $v vectors ========="
3030
./$v/validate.py
3131
done

disputes/validate.py

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

3+
import asn1tools
4+
import glob
35
import os
46
import sys
5-
from pathlib import Path
67

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

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
11+
from utils import get_schema_files, validate # noqa: E402
1112

13+
os.chdir(script_dir)
1214

1315
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1416
def tweak_sequence_of_options(state_obj):
@@ -20,21 +22,16 @@ def tweak_sequence_of_options(state_obj):
2022
items[i] = {"some": items[i]}
2123
return state_obj
2224

23-
2425
def tweak_callback(json_obj):
2526
tweak_sequence_of_options(json_obj['pre_state'])
2627
tweak_sequence_of_options(json_obj['post_state'])
2728
return json_obj
2829

30+
def validate_spec(spec_name):
31+
print(f"[Validating Disputes ({spec_name})]")
32+
schema = asn1tools.compile_files(get_schema_files(spec_name == "full") + ["disputes.asn"], codec="jer")
33+
for json_file in glob.glob(f"{spec_name}/*.json"):
34+
validate(schema, json_file, "TestCase", tweak_callback)
2935

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)
36+
validate_spec("tiny")
37+
validate_spec("full")

history/validate.py

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

3+
import asn1tools
4+
import glob
35
import os
46
import sys
5-
from pathlib import Path
67

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

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
11+
from utils import get_schema_files, validate # noqa: E402
1112

13+
os.chdir(script_dir)
1214

1315
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1416
def tweak_sequence_of_options(state_obj):
@@ -21,14 +23,15 @@ def tweak_sequence_of_options(state_obj):
2123
peaks[i] = {"some": peaks[i]}
2224
return state_obj
2325

24-
2526
def tweak_callback(json_obj):
2627
tweak_sequence_of_options(json_obj['pre_state'])
2728
tweak_sequence_of_options(json_obj['post_state'])
2829
return json_obj
2930

31+
def validate_data():
32+
print("[Validating History]")
33+
schema = asn1tools.compile_files(get_schema_files() + ["history.asn"], codec="jer")
34+
for json_file in glob.glob("data/*.json"):
35+
validate(schema, json_file, "TestCase", tweak_callback)
3036

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)
37+
validate_data()

jam-types-asn/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import re
33
import json
4+
import asn1tools
5+
import glob
46

57

68
def get_schema_files(full = False):
@@ -61,3 +63,10 @@ def validate(schema, path, schema_name = None, json_tweaks_callback = None):
6163
json_str = json.dumps(json_obj, indent = 4)
6264

6365
assert (json_str.rstrip().lower() == json_str_org.rstrip().lower())
66+
67+
def validate_group(group_name, group_schema, spec_name):
68+
print(f"\n[Validating {group_name} ({spec_name})]")
69+
schema = asn1tools.compile_files(get_schema_files(spec_name == "full") + [group_schema], codec="jer")
70+
for json_file in glob.glob(f"{spec_name}/*.json"):
71+
validate(schema, json_file, "TestCase")
72+

preimages/validate.py

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

3+
import asn1tools
4+
import glob
35
import os
46
import sys
5-
from pathlib import Path
67

7-
import asn1tools
8+
script_dir = os.path.dirname(os.path.abspath(__file__))
9+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../jam-types-asn')))
10+
11+
from utils import get_schema_files, validate # noqa: E402
812

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
13+
os.chdir(script_dir)
1114

15+
def validate_data():
16+
print("[Validating Preimages]")
17+
schema = asn1tools.compile_files(get_schema_files() + ["preimages.asn"], codec="jer")
18+
for json_file in glob.glob("data/*.json"):
19+
validate(schema, json_file, "TestCase")
1220

13-
# Validate tiny/full
14-
schema = asn1tools.compile_files(get_schema_files() + ["preimages.asn"], codec="jer")
15-
for path in Path("data").iterdir():
16-
if path.is_file() and path.suffix == ".json":
17-
validate(schema, path, "TestCase")
21+
validate_data()

reports/validate.py

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

3+
import asn1tools
4+
import glob
35
import os
46
import sys
5-
from pathlib import Path
67

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

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
11+
from utils import get_schema_files, validate # noqa: E402
1112

13+
os.chdir(script_dir)
1214

1315
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
1416
def tweak_assignments_sequence_of_options(state_obj):
@@ -19,7 +21,6 @@ def tweak_assignments_sequence_of_options(state_obj):
1921
else:
2022
items[i] = {"some": items[i]}
2123

22-
2324
# Makes the SEQUENCE of OPTIONAL values ASN.1 compliant (using CHOICE)
2425
def tweak_mmr_sequence_of_options(state_obj):
2526
for entry in state_obj['recent_blocks']:
@@ -31,23 +32,18 @@ def tweak_mmr_sequence_of_options(state_obj):
3132
peaks[i] = {"some": peaks[i]}
3233
return state_obj
3334

34-
3535
def tweak_callback(json_obj):
3636
tweak_assignments_sequence_of_options(json_obj['pre_state'])
3737
tweak_mmr_sequence_of_options(json_obj['pre_state'])
3838
tweak_assignments_sequence_of_options(json_obj['post_state'])
3939
tweak_mmr_sequence_of_options(json_obj['post_state'])
4040
return json_obj
4141

42+
def validate_spec(spec_name):
43+
print(f"[Validating Reports ({spec_name})]")
44+
schema = asn1tools.compile_files(get_schema_files(spec_name == "full") + ["reports.asn"], codec="jer")
45+
for json_file in glob.glob(f"{spec_name}/*.json"):
46+
validate(schema, json_file, "TestCase", tweak_callback)
4247

43-
# Validate tiny
44-
schema = asn1tools.compile_files(get_schema_files(False) + ["reports.asn"], codec="jer")
45-
for path in Path("tiny").iterdir():
46-
if path.is_file() and path.suffix == ".json":
47-
validate(schema, path, "TestCase", tweak_callback)
48-
49-
# Validate full
50-
schema = asn1tools.compile_files(get_schema_files(True) + ["reports.asn"], codec="jer")
51-
for path in Path("full").iterdir():
52-
if path.is_file() and path.suffix == ".json":
53-
validate(schema, path, "TestCase", tweak_callback)
48+
validate_spec("tiny")
49+
validate_spec("full")

safrole/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) + ["safrole.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) + ["safrole.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+
validate_group("safrole", "safrole.asn", "tiny")
14+
validate_group("safrole", "safrole.asn", "full")

statistics/validate.py

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

3+
import asn1tools
4+
import glob
35
import os
46
import sys
5-
from pathlib import Path
67

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

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
11+
from utils import get_schema_files, validate # noqa: E402
1112

13+
os.chdir(script_dir)
1214

13-
# Validate tiny
14-
schema = asn1tools.compile_files(get_schema_files(False) + ["statistics.asn"], codec="jer")
15-
for path in Path("tiny").iterdir():
16-
if path.is_file() and path.suffix == ".json":
17-
validate(schema, path, "TestCase")
15+
def validate_spec(spec_name):
16+
print(f"[Validating '{spec_name}' spec]")
17+
schema = asn1tools.compile_files(get_schema_files(spec_name == "full") + ["statistics.asn"], codec="jer")
18+
for json_file in glob.glob(f"{spec_name}/*.json"):
19+
validate(schema, json_file, "TestCase")
1820

19-
# Validate full
20-
schema = asn1tools.compile_files(get_schema_files(True) + ["statistics.asn"], codec="jer")
21-
for path in Path("full").iterdir():
22-
if path.is_file() and path.suffix == ".json":
23-
validate(schema, path, "TestCase")
21+
validate_spec("tiny")
22+
validate_spec("full")

0 commit comments

Comments
 (0)