Skip to content

Commit d4fe107

Browse files
committed
Finished TCK support, Added readme
Signed-off-by: LukeBair <[email protected]>
1 parent b024705 commit d4fe107

File tree

6 files changed

+89
-41
lines changed

6 files changed

+89
-41
lines changed

tck/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Testing Compatibility Toolkit (TCK) Guide
2+
3+
This document describes how to run Hiero TCK tests for the Python SDK.
4+
## Setup
5+
1. **Set up the Python SDK**
6+
7+
Follow the steps in the [Hiero TCK README](https://github.com/hiero-ledger/hiero-sdk-tck) to clone the repository and set it up on your local machine.
8+
9+
10+
2. **Environment Variables**
11+
12+
Ensure that the environment variables in the `.env` file for both the TCK and the Python SDK are identical, to make sure that they run in the same configuration.
13+
14+
## Running the TCK Tests
15+
16+
1. **Navigate to the TCK Directory in the Python SDK**
17+
18+
Change directory to the location of the TCK within the Python SDK. For example:
19+
20+
```shell script
21+
cd hiero-python-sdk/tck
22+
```
23+
24+
2. **Start the TCK Server**
25+
26+
Launch the TCK server by running:
27+
28+
```shell script
29+
python3 server.py
30+
```
31+
32+
3. **Execute TCK Tests**
33+
34+
With the TCK server running, you can now execute tests either from the command line or directly via your IDE. Refer to the TCK's README for more information.
35+
36+
37+
## Troubleshooting
38+
39+
- **Environment Variables Not Set Correctly:**
40+
Double-check your `.env` files for typos or mismatched variables between the TCK and Python SDK.
41+
42+
- **Server Issues:**
43+
Ensure no other application is using the port required by the TCK server. Check server logs for further details if the server does not start as expected.
44+
45+
- **Test Failures:**
46+
Review the output for any error messages. They can give insights into configuration issues or missing dependencies.
47+
48+
- **Enable Logging:**
49+
In the server.py file, uncomment `logging.basicConfig(level=logging.DEBUG)` to enable logging, and better debug what is happening.
50+
51+
52+
## Contributing
53+
54+
Contributions are welcome! Please follow these steps:
55+
56+
1. Fork this repository.
57+
2. Create a new branch with your feature or fix.
58+
3. Make your changes and ensure the tests pass.
59+
3. Submit a pull request.
60+
61+
Please ensure all new code is covered by unit tests.
62+
63+
## License
64+
65+
This project is licensed under the MIT License.

tck/account_create.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
55
from key_identifier import KeyIdentifier
66

7-
# NOTE: The problem is I need to use a string to identify whether or not a key is ecdsa, ed25519, public or private
8-
# The PrivateKey class has a 'from_string' class which I can take advantage of easily
9-
# The PublicKey doesnt have anything helpful, once you have a reference to it you can check if it is ed25519 or ecdsa
10-
# So I will likely have to add a way to check for the public key, this can be done outside of the PublicKey class,
11-
# but to keep consistency with the PrivateKey class it would be really nice to have a 'from_string' class in there
12-
# Ill take a look into it rn to see if it is something I am capable of doing well (I know a way I could but its dookie)
13-
# It doesnt look like something that I really have any right doing, Im not really sure where to start with the ec key,
14-
# I'll look into it again
15-
# Ignoring KeyLists right now
16-
# The """...""" block is taken directly from the tck AccountCreateTransaction.md & combined with the intellij
17-
# autogenerated """...""" block
187
@method
198
def createAccount(key: str = None, initialBalance: str = None, receiverSignatureRequired: bool = None, autoRenewPeriod: str = None,
209
memo: str = None, maxAutoTokenAssociations: int = None, stakedAccountId: str = None, stakedNodeId: str = None,
@@ -46,15 +35,17 @@ def createAccount(key: str = None, initialBalance: str = None, receiverSignature
4635
transaction = (
4736
AccountCreateTransaction()
4837
.set_key(public_key)
38+
# .set_initial_balance(int(initialBalance))
39+
.set_receiver_signature_required(receiverSignatureRequired)
40+
# .set_auto_renew_period(0, int(autoRenewPeriod))
4941
.set_account_memo(memo)
5042
.freeze_with(utils.__client)
5143
)
52-
# WARNING: I believe that this is right, but im not sure what the case is if the key parameter is a Private Key
53-
# why the heck are they giving me a private key anyways...
44+
5445
transaction.sign(utils.__operatorPrivateKey)
5546
receipt = transaction.execute(utils.__client)
5647

5748
return Success({
58-
"accountId": receipt.accountId,
59-
"status": receipt.status,
49+
"accountId": str(receipt.accountId),
50+
"status": str(receipt.status),
6051
})

tck/key_identifier.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
from cryptography.hazmat.primitives.asymmetric import ed25519, ec
21
from hiero_sdk_python import PublicKey, PrivateKey
32

43
class KeyIdentifier:
54

6-
# NOTE: after having AI try and fail to write this code for a couple tries Im going to give it a crack
7-
# to prove that AI isnt better than a 19 year old bum. Also cause they cant do it and im cocky.
8-
# So this method will have to do a couple things, it will need to be able to identify from bytes and a string.
9-
# Hedera's DER keys seem to be in a hex format
10-
# TODO: The fact that identify() and is_public() have super similar code is disgusting
11-
# NOTE: You can probably take some of this code and use it for importing an existing key: https://docs.hedera.com/hedera/sdks-and-apis/sdks/keys/import-an-existing-key
12-
135
@classmethod
146
def identify(cls, key: str) -> tuple[None | PublicKey | PrivateKey, bool | None]:
157
"""

tck/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import account_create
44
from jsonrpcserver import serve, method
55

6-
logging.basicConfig(level=logging.DEBUG)
6+
# NOTE: enable if you want to see the logs
7+
# logging.basicConfig(level=logging.DEBUG)
78

89
if __name__ == '__main__':
910
serve(port=8545) # Specify your desired port here

tck/utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
from hiero_sdk_python import Network
12
from hiero_sdk_python.account.account_id import AccountId
23
from hiero_sdk_python.client.client import Client
34
from jsonrpcserver import Success, method, InvalidParams
45
from hiero_sdk_python.crypto.private_key import PrivateKey
56

67
__operatorAccountId: AccountId
78
__operatorPrivateKey: PrivateKey
8-
__client: Client = Client()
9+
__client: Client = Client(Network(network='testnet'))
910

1011
@method
1112
def setup(operatorAccountId: str=None, operatorPrivateKey: str=None, nodeIp: str=None, nodeAccountId: str=None, mirrorNetworkIp: str=None):
1213
global __client, __operatorAccountId, __operatorPrivateKey
1314
__operatorAccountId = AccountId.from_string(operatorAccountId)
14-
__operatorPrivateKey = PrivateKey.from_string(operatorPrivateKey[2:])
15+
__operatorPrivateKey = PrivateKey.from_string(operatorPrivateKey)
1516
__client.set_operator(__operatorAccountId, __operatorPrivateKey)
1617

1718
return Success({
@@ -22,10 +23,9 @@ def setup(operatorAccountId: str=None, operatorPrivateKey: str=None, nodeIp: str
2223
@method
2324
def reset():
2425
global __operatorAccountId, __operatorPrivateKey, __client
25-
2626
__operatorAccountId = None
2727
__operatorPrivateKey = None
28-
__client = Client()
28+
__client = Client(Network(network='testnet'))
2929

3030
return Success({
3131
"message":"Successfully reset client.",
@@ -35,14 +35,20 @@ def reset():
3535
@method
3636
def generateKey(type: str=None, fromKey: str=None, threshold: int=None, keys: list=None):
3737
if type == "ed25519PublicKey":
38-
new_account_private_key = PrivateKey.from_string(fromKey)
39-
new_account_public_key = new_account_private_key.public_key()
40-
return Success({"key": new_account_public_key.to_string_raw()})
38+
if fromKey is None:
39+
return Success({"key": PrivateKey.generate_ed25519().public_key().to_string_raw()})
40+
else:
41+
new_account_private_key = PrivateKey.from_string(fromKey)
42+
new_account_public_key = new_account_private_key.public_key()
43+
return Success({"key": new_account_public_key.to_string_raw()})
4144

4245
elif type == "ecdsaSecp256k1PublicKey":
43-
new_account_private_key = PrivateKey.from_string(fromKey)
44-
new_account_public_key = new_account_private_key.public_key()
45-
return Success({"key": new_account_public_key.to_string_raw()})
46+
if fromKey is None:
47+
return Success({"key": PrivateKey.generate_ecdsa().public_key().to_string_raw()})
48+
else:
49+
new_account_private_key = PrivateKey.from_string(fromKey)
50+
new_account_public_key = new_account_private_key.public_key()
51+
return Success({"key": new_account_public_key.to_string_raw()})
4652

4753
elif type == "ed25519PrivateKey":
4854
new_account_private_key = PrivateKey.generate()

tests/key_identifier_tester.py

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

0 commit comments

Comments
 (0)