Skip to content

Commit

Permalink
add minimal set of metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mezrin committed Sep 6, 2024
1 parent 921d7a1 commit 5897411
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# name: Python tests

# on:
# push:
# branches: [ main ]
# pull_request:
# branches: [ main ]
# workflow_dispatch:


# jobs:
# py-linters:
# concurrency:
# group: py-linters-${{ github.ref }}
# cancel-in-progress: true

# runs-on: ubuntu-latest

# strategy:
# matrix:
# python-version: [ "3.12" ]

# steps:
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # pin@v5
# with:
# python-version: ${{ matrix.python-version }}

# - name: Install the package
# run: |
# python3 ./py-traits-validator/scripts/bundle_registry.py
# cd py-traits-validator && pip install -e '.[dev]' --config-settings editable_mode=strict

# - name: Check code with ruff
# run: pip3 install ruff && ruff check --output-format=github

# - name: Check code formatting with ruff
# run: pip3 install ruff && ruff format --check

# - name: Check code with MYPY
# run: cd py-traits-validator && mypy .


# py-tests:
# concurrency:
# group: py-tests-${{ github.ref }}
# cancel-in-progress: true

# runs-on: ubuntu-latest

# strategy:
# matrix:
# python-version: [ "3.12" ]

# steps:
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # pin@v5
# with:
# python-version: ${{ matrix.python-version }}

# - name: Install python dependencies
# run: |
# python3 ./scripts/bundle_registry.py
# cd py-traits-validator && pip install -e '.[dev]' --config-settings editable_mode=strict

# - name: Run unit tests
# run: cd py-traits-validator && python3 -m unittest discover
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.vscode

.venv
env
.env
__pycache__
.mypy_cache
.ruff_cache

*.egg-info/
13 changes: 13 additions & 0 deletions aws_s3_assets/game-a/app-agent-a/app-agent-a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"metadata_id": "demo-app-agent-a",
"title": "Metadata of the demo AppAgent that represents the game Eclipse Legends.",
"description": "Metadata of the demo AppAgent that represents the game Eclipse Legends.",
"traits": {
"named": {
"name": "Eclipse Legends"
},
"tech.trait.wallet.square_icon": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
}
}
}
3 changes: 3 additions & 0 deletions aws_s3_assets/game-a/app-agent-a/app-agent-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions aws_s3_assets/game-a/fungible-a-a/fungible-a-a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"metadata_id": "demo-fungible-a-a",
"title": "Metadata of the demo fungible token for the game Eclipse Legends.",
"description": "Metadata of the demo fungible token for the game Eclipse Legends.",
"traits": {
"named": {
"name": "Luminaras"
},
"fungible": {
"symbol": "Lux",
"decimals": 12
},
"tech.trait.wallet.square_icon": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
}
}
}
3 changes: 3 additions & 0 deletions aws_s3_assets/game-a/fungible-a-a/fungible-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"metadata_id": "demo-nft-collection-a-a",
"title": "Metadata of the demo NFT collection for the game Eclipse Legends.",
"description": "Metadata of the demo NFT collection for the game Eclipse Legends.",
"traits": {
"named": {
"name": "Swords"
},
"tech.trait.wallet.square_icon": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
},
"tech.trait.wallet.nft_collection_listing_image": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"metadata_id": "demo-nft-token-a-a-a",
"title": "Metadata of the demo NFT token for the game Eclipse Legends.",
"description": "Metadata of the demo NFT token for the game Eclipse Legends.",
"traits": {
"named": {
"name": "Long Sword"
},
"tech.trait.wallet.square_icon": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
},
"tech.trait.wallet.nft_token_listing_image": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
},
"tech.trait.wallet.nft_token_cover_image": {
"image_uri": "https://s3.us-east-2.amazonaws.com/"
},
"tech.trait.wallet.nft_token_description": {
"nft_token_description": "A very long sword with strong attack."
},
"tech.trait.wallet.nft_token_attributes": {
"attributes": [
{
"name": "Number attribute",
"display_type": "number",
"value": 123
},
{
"name": "Percentage attribute",
"display_type": "percentage",
"value": -17
},
{
"name": "String attribute",
"display_type": "string",
"value": "Some string"
},
{
"name": "Boolean attribute",
"display_type": "boolean",
"value": true
},
{
"name": "Date attribute 1",
"display_type": "date",
"value": "2018-11-13T20:20:39+00:00"
},
{
"name": "Date attribute 2",
"display_type": "date",
"value": "2018-11-13"
},
{
"name": "Date attribute 3",
"display_type": "date",
"value": "20:20:39+00:00"
},
{
"name": "Duration attribute",
"display_type": "duration",
"value": "P3D"
}
]
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added py-tests/__init__.py
Empty file.
104 changes: 104 additions & 0 deletions py-tests/test_consistency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import json
import unittest
from pathlib import Path

from traitsvalidator import TraitsValidator


class TestConfig:
GIT_REPO_ROOT: Path = Path(__file__).parent.parent
AWS_S3_ASSETS_DIR: Path = GIT_REPO_ROOT / "aws_s3_assets"


class TestRegistry(unittest.TestCase):
def test_validation_of_traits(self: "TestRegistry") -> None:
"""
Validate metadata of on-chain assets with traits schema.
This function iterates over all metadata files in the AWS S3 dir,
validates their traits.
"""
validator = TraitsValidator()

# Collect list of all metadata files
meta_app_agents = []
meta_fungibles = []
meta_nft_collections = []
meta_nft_tokens = []

# Find all files from directory
# Iterate over files in directory
for filename in Path(TestConfig.AWS_S3_ASSETS_DIR).rglob("*.json"):
print(filename)
if filename.is_file() and filename.name.endswith(".json"):
if "app-agent" in filename.name:
meta_app_agents.append(filename)
elif "fungible" in filename.name:
meta_fungibles.append(filename)
elif "nft-collection" in filename.name:
meta_nft_collections.append(filename)
elif "nft-token" in filename.name:
meta_nft_tokens.append(filename)
else:
msg = f"Unknown metadata file: {filename}"
raise ValueError(msg)

print(meta_app_agents)
print(meta_fungibles)
print(meta_nft_collections)
print(meta_nft_tokens)

# Validate AppAgent metadata
for meta_path in meta_app_agents:
with meta_path.open() as fp:
appagent_meta = json.load(fp)
available_traits = validator.validate_metadata(appagent_meta)
self.assertEqual(
available_traits,
["named", "tech.trait.wallet.square_icon"],
f"Unexpected set of traits in the file {meta_path}",
)

# Validate metadata of fungible token
for meta_path in meta_fungibles:
with meta_path.open() as fp:
fungible_meta = json.load(fp)
available_traits = validator.validate_metadata(fungible_meta)
self.assertEqual(
available_traits,
["named", "fungible", "tech.trait.wallet.square_icon"],
f"Unexpected set of traits in the file {meta_path}",
)

# Validate metadata of nft collection
for meta_path in meta_nft_collections:
with meta_path.open() as fp:
nft_collection_meta = json.load(fp)
available_traits = validator.validate_metadata(nft_collection_meta)
self.assertEqual(
available_traits,
[
"named",
"tech.trait.wallet.square_icon",
"tech.trait.wallet.nft_collection_listing_image",
],
f"Unexpected set of traits in the file {meta_path}",
)

# Validate metadata of nft token
for meta_path in meta_nft_tokens:
with meta_path.open() as fp:
nft_token_meta = json.load(fp)
available_traits = validator.validate_metadata(nft_token_meta)
self.assertEqual(
available_traits,
[
"named",
"tech.trait.wallet.square_icon",
"tech.trait.wallet.nft_token_listing_image",
"tech.trait.wallet.nft_token_cover_image",
"tech.trait.wallet.nft_token_description",
"tech.trait.wallet.nft_token_attributes",
],
f"Unexpected set of traits in the file {meta_path}",
)

0 comments on commit 5897411

Please sign in to comment.