Skip to content

Commit 4fb8d6f

Browse files
authored
Merge pull request #75 from davxy/reorg-stf-vectors
STF vectors reorg
2 parents 1f38ba1 + 1585b14 commit 4fb8d6f

File tree

605 files changed

+872
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

605 files changed

+872
-36
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
validator: [codec, accumulate, assurances, authorizations, disputes, history, preimages, reports, safrole, statistics]
18+
validator:
19+
- codec
20+
- stf/accumulate
21+
- stf/assurances
22+
- stf/authorizations
23+
- stf/disputes
24+
- stf/history
25+
- stf/preimages
26+
- stf/reports
27+
- stf/safrole
28+
- stf/statistics
1929
steps:
2030
- name: Checkout
2131
uses: actions/checkout@v2
@@ -28,3 +38,4 @@ jobs:
2838
pip install git+https://github.com/davxy/asn1tools.git
2939
- name: Validate ${{ matrix.validator }}
3040
run: ./${{ matrix.validator }}/validate.py
41+

CHANGELOG.md

Lines changed: 4 additions & 1 deletion

README.md

Lines changed: 9 additions & 9 deletions

codec/convert.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
3+
import glob
4+
import os
5+
import re
6+
import sys
7+
from jam_types import (
8+
AssurancesXt,
9+
Block,
10+
Culprit,
11+
DisputesXt,
12+
Extrinsics,
13+
Fault,
14+
GuaranteesXt,
15+
Header,
16+
PreimagesXt,
17+
RefineContext,
18+
TicketsXt,
19+
Verdict,
20+
WorkItem,
21+
WorkPackage,
22+
WorkPackageAvailSpec,
23+
WorkReport,
24+
WorkResult,
25+
spec
26+
)
27+
28+
script_dir = os.path.dirname(os.path.abspath(__file__))
29+
sys.path.append(os.path.abspath(os.path.join(script_dir, '../lib')))
30+
from bin_to_json import convert_to_json # noqa: E402
31+
32+
os.chdir(script_dir)
33+
34+
# Map the subsystem's parameter to the corresponding dump class
35+
dump_classes = {
36+
"refine_context": RefineContext,
37+
"work_item": WorkItem,
38+
"work_package": WorkPackage,
39+
"work_package_avail_spec": WorkPackageAvailSpec,
40+
"work_result": WorkResult,
41+
"work_report": WorkReport,
42+
"header": Header,
43+
"verdict": Verdict,
44+
"culprit": Culprit,
45+
"fault": Fault,
46+
"tickets_extrinsic": TicketsXt,
47+
"disputes_extrinsic": DisputesXt,
48+
"preimages_extrinsic": PreimagesXt,
49+
"assurances_extrinsic": AssurancesXt,
50+
"guarantees_extrinsic": GuaranteesXt,
51+
"extrinsic": Extrinsics,
52+
"block": Block,
53+
}
54+
55+
56+
def convert(spec_name):
57+
print(f"\n[Converting codec ({spec_name})]")
58+
spec.set_spec(spec_name)
59+
for filename in glob.glob(f"{spec_name}/*.bin"):
60+
print("Converting ", filename)
61+
basename = os.path.splitext(os.path.basename(filename))[0]
62+
basename = re.sub(r'_\d+$', '', basename)
63+
class_type = dump_classes[basename]
64+
convert_to_json(filename, class_type)
65+
66+
for spec_name in ["tiny", "full"]:
67+
convert(spec_name)

codec/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import sys
55

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

9-
from utils import validate_group # noqa: E402
9+
from validate_asn1 import validate_group # noqa: E402
1010

1111
os.chdir(script_dir)
1212

jam-types-asn/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/README.md

Lines changed: 6 additions & 0 deletions

lib/bin_to_json.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Binary to JSON conversion support utilities.
2+
#
3+
# Depends on [`jam_types`](https://github.com/davxy/jam-types)
4+
5+
import json
6+
import glob
7+
from jam_types import Struct, ScaleBytes, spec
8+
9+
class StfTestVector(Struct):
10+
state_class = None
11+
input_class = None
12+
output_class = None
13+
errno_map = None
14+
15+
def __init__(self, data):
16+
self.type_mapping = [
17+
('input', self.input_class),
18+
('pre_state', self.state_class),
19+
('output', self.output_class),
20+
('post_state', self.state_class)
21+
]
22+
super().__init__(data)
23+
24+
def decode(self):
25+
decoded = super().decode()
26+
output = decoded['output']
27+
if isinstance(output, dict):
28+
errno = output.get('err')
29+
if errno is not None and self.errno_map is not None:
30+
decoded['output']['err'] = self.errno_map.get(errno, "other_error")
31+
return decoded
32+
33+
34+
def convert_to_json(filename, subsystem_type):
35+
with open(filename, 'rb') as file:
36+
blob = file.read()
37+
scale_bytes = ScaleBytes(blob)
38+
dump = subsystem_type(data=scale_bytes)
39+
decoded = dump.decode()
40+
json_filename = filename.replace('.bin', '.json')
41+
with open(json_filename, 'w') as json_file:
42+
json.dump(decoded, json_file, indent=4)
43+
json_file.write('\n')
44+
45+
def convert_group(group_name, spec_name, subsystem_type):
46+
if spec_name in ("tiny", "full"):
47+
spec.set_spec(spec_name)
48+
print(f"\n[Converting {group_name} ({spec_name})]")
49+
for file in glob.glob(f"{spec_name}/*.bin"):
50+
print("* Converting:", file)
51+
convert_to_json(file, subsystem_type)

0 commit comments

Comments
 (0)