This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/predeployed accounts endpoint (#138)
- Loading branch information
Showing
8 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
from os.path import join, dirname, abspath | ||
from jsonschema import validate, RefResolver | ||
|
||
|
||
def assert_valid_schema(data, schema_file): | ||
"""Checks whether the given data matches the schema""" | ||
|
||
schema = _load_json_schema(schema_file) | ||
schema_dir = join(dirname(__file__), "schemas") | ||
resolver = RefResolver(base_uri="file://" + schema_dir + "/", referrer=schema) | ||
return validate(data, schema, resolver=resolver) | ||
|
||
|
||
def _load_json_schema(filename): | ||
"""Loads the given schema file""" | ||
|
||
relative_path = join("schemas", filename) | ||
absolute_path = join(dirname(__file__), relative_path) | ||
|
||
with open(absolute_path) as schema_file: | ||
return json.loads(schema_file.read()) |
115 changes: 115 additions & 0 deletions
115
test/support/schemas/predeployed_accounts_fixed_seed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Predeployed accounts fixed value response schema", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"address": { | ||
"type": "string", | ||
"enum": [ | ||
"0xc7608a2ba18f3af1a7d95ac07b7772ca5d2e84c6191e1ccb99a74521b4eda4" | ||
] | ||
}, | ||
"initial_balance": { | ||
"type": "number", | ||
"enum": [ | ||
1000 | ||
] | ||
}, | ||
"private_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0xc4da537c1651ddae44867db30d67b366" | ||
] | ||
}, | ||
"public_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0x60dea6c1228f1db4ca1f9db11c01b6e9cce5e627f7181dcaa27d69cbdbe57b5" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"address", | ||
"initial_balance", | ||
"private_key", | ||
"public_key" | ||
], | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"address": { | ||
"type": "string", | ||
"enum": [ | ||
"0x5d13db75ca726e8b45484c7c5692493e41f883e20888baf6cfeb9444938ba89" | ||
] | ||
}, | ||
"initial_balance": { | ||
"type": "number", | ||
"enum": [ | ||
1000 | ||
] | ||
}, | ||
"private_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0xd6a82a951b923e0a443cdef36840ff07" | ||
] | ||
}, | ||
"public_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0x5a91f0ea25312accb20d8041b12260bff31a3490e5730a690b0ec8fe10ffbb" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"address", | ||
"initial_balance", | ||
"private_key", | ||
"public_key" | ||
], | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"address": { | ||
"type": "string", | ||
"enum": [ | ||
"0x14271050ae36fb1a217a5d9a0eb73b76ccaee633c5acc7008ceeace3c18694f" | ||
] | ||
}, | ||
"initial_balance": { | ||
"type": "number", | ||
"enum": [ | ||
1000 | ||
] | ||
}, | ||
"private_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0x610e4ad509c47055dff4948fe6b4f832" | ||
] | ||
}, | ||
"public_key": { | ||
"type": "string", | ||
"enum": [ | ||
"0x2b45af00df833ea1a4895c49a18ebd84309b79d658cae05e274a7b1cac47016" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"address", | ||
"initial_balance", | ||
"private_key", | ||
"public_key" | ||
], | ||
"additionalProperties": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
"""Predeployed account tests""" | ||
|
||
from test.settings import GATEWAY_URL | ||
|
||
import pytest | ||
import requests | ||
|
||
from starkware.starknet.core.os.class_hash import compute_class_hash | ||
|
||
from starknet_devnet.account import Account | ||
from .util import assert_equal | ||
from .util import assert_equal, devnet_in_background | ||
from .support.assertions import assert_valid_schema | ||
|
||
ACCOUNTS_SEED_DEVNET_ARGS = [ | ||
"--accounts", | ||
"3", | ||
"--seed", | ||
"123", | ||
"--gas-price", | ||
"100", | ||
"--initial-balance", | ||
"1_000", | ||
] | ||
|
||
|
||
@pytest.mark.account_predeployed | ||
def test_precomputed_contract_hash(): | ||
"""Test if the precomputed hash of the account contract is correct.""" | ||
recalculated_hash = compute_class_hash(contract_class=Account.get_contract_class()) | ||
assert_equal(recalculated_hash, Account.HASH) | ||
|
||
|
||
@pytest.mark.account_predeployed | ||
@devnet_in_background(*ACCOUNTS_SEED_DEVNET_ARGS) | ||
def test_predeployed_accounts_predefined_values(): | ||
"""Test if --account --seed --initial-balance return exact calculated values""" | ||
response = requests.get(f"{GATEWAY_URL}/predeployed_accounts") | ||
assert response.status_code == 200 | ||
assert_valid_schema(response.json(), "predeployed_accounts_fixed_seed.json") |