Skip to content

Commit

Permalink
Finished TCK support, Added readme
Browse files Browse the repository at this point in the history
Signed-off-by: LukeBair <[email protected]>
  • Loading branch information
LukeBair committed Feb 12, 2025
1 parent b024705 commit d4fe107
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 41 deletions.
65 changes: 65 additions & 0 deletions tck/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Testing Compatibility Toolkit (TCK) Guide

This document describes how to run Hiero TCK tests for the Python SDK.
## Setup
1. **Set up the Python SDK**

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.


2. **Environment Variables**

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.

## Running the TCK Tests

1. **Navigate to the TCK Directory in the Python SDK**

Change directory to the location of the TCK within the Python SDK. For example:

```shell script
cd hiero-python-sdk/tck
```

2. **Start the TCK Server**

Launch the TCK server by running:

```shell script
python3 server.py
```

3. **Execute TCK Tests**

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.


## Troubleshooting

- **Environment Variables Not Set Correctly:**
Double-check your `.env` files for typos or mismatched variables between the TCK and Python SDK.

- **Server Issues:**
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.

- **Test Failures:**
Review the output for any error messages. They can give insights into configuration issues or missing dependencies.

- **Enable Logging:**
In the server.py file, uncomment `logging.basicConfig(level=logging.DEBUG)` to enable logging, and better debug what is happening.


## Contributing

Contributions are welcome! Please follow these steps:

1. Fork this repository.
2. Create a new branch with your feature or fix.
3. Make your changes and ensure the tests pass.
3. Submit a pull request.

Please ensure all new code is covered by unit tests.

## License

This project is licensed under the MIT License.
21 changes: 6 additions & 15 deletions tck/account_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
from hiero_sdk_python.account.account_create_transaction import AccountCreateTransaction
from key_identifier import KeyIdentifier

# NOTE: The problem is I need to use a string to identify whether or not a key is ecdsa, ed25519, public or private
# The PrivateKey class has a 'from_string' class which I can take advantage of easily
# The PublicKey doesnt have anything helpful, once you have a reference to it you can check if it is ed25519 or ecdsa
# So I will likely have to add a way to check for the public key, this can be done outside of the PublicKey class,
# but to keep consistency with the PrivateKey class it would be really nice to have a 'from_string' class in there
# 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)
# It doesnt look like something that I really have any right doing, Im not really sure where to start with the ec key,
# I'll look into it again
# Ignoring KeyLists right now
# The """...""" block is taken directly from the tck AccountCreateTransaction.md & combined with the intellij
# autogenerated """...""" block
@method
def createAccount(key: str = None, initialBalance: str = None, receiverSignatureRequired: bool = None, autoRenewPeriod: str = None,
memo: str = None, maxAutoTokenAssociations: int = None, stakedAccountId: str = None, stakedNodeId: str = None,
Expand Down Expand Up @@ -46,15 +35,17 @@ def createAccount(key: str = None, initialBalance: str = None, receiverSignature
transaction = (
AccountCreateTransaction()
.set_key(public_key)
# .set_initial_balance(int(initialBalance))
.set_receiver_signature_required(receiverSignatureRequired)
# .set_auto_renew_period(0, int(autoRenewPeriod))
.set_account_memo(memo)
.freeze_with(utils.__client)
)
# WARNING: I believe that this is right, but im not sure what the case is if the key parameter is a Private Key
# why the heck are they giving me a private key anyways...

transaction.sign(utils.__operatorPrivateKey)
receipt = transaction.execute(utils.__client)

return Success({
"accountId": receipt.accountId,
"status": receipt.status,
"accountId": str(receipt.accountId),
"status": str(receipt.status),
})
8 changes: 0 additions & 8 deletions tck/key_identifier.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
from cryptography.hazmat.primitives.asymmetric import ed25519, ec
from hiero_sdk_python import PublicKey, PrivateKey

class KeyIdentifier:

# NOTE: after having AI try and fail to write this code for a couple tries Im going to give it a crack
# to prove that AI isnt better than a 19 year old bum. Also cause they cant do it and im cocky.
# So this method will have to do a couple things, it will need to be able to identify from bytes and a string.
# Hedera's DER keys seem to be in a hex format
# TODO: The fact that identify() and is_public() have super similar code is disgusting
# 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

@classmethod
def identify(cls, key: str) -> tuple[None | PublicKey | PrivateKey, bool | None]:
"""
Expand Down
3 changes: 2 additions & 1 deletion tck/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import account_create
from jsonrpcserver import serve, method

logging.basicConfig(level=logging.DEBUG)
# NOTE: enable if you want to see the logs
# logging.basicConfig(level=logging.DEBUG)

if __name__ == '__main__':
serve(port=8545) # Specify your desired port here
26 changes: 16 additions & 10 deletions tck/utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from hiero_sdk_python import Network
from hiero_sdk_python.account.account_id import AccountId
from hiero_sdk_python.client.client import Client
from jsonrpcserver import Success, method, InvalidParams
from hiero_sdk_python.crypto.private_key import PrivateKey

__operatorAccountId: AccountId
__operatorPrivateKey: PrivateKey
__client: Client = Client()
__client: Client = Client(Network(network='testnet'))

@method
def setup(operatorAccountId: str=None, operatorPrivateKey: str=None, nodeIp: str=None, nodeAccountId: str=None, mirrorNetworkIp: str=None):
global __client, __operatorAccountId, __operatorPrivateKey
__operatorAccountId = AccountId.from_string(operatorAccountId)
__operatorPrivateKey = PrivateKey.from_string(operatorPrivateKey[2:])
__operatorPrivateKey = PrivateKey.from_string(operatorPrivateKey)
__client.set_operator(__operatorAccountId, __operatorPrivateKey)

return Success({
Expand All @@ -22,10 +23,9 @@ def setup(operatorAccountId: str=None, operatorPrivateKey: str=None, nodeIp: str
@method
def reset():
global __operatorAccountId, __operatorPrivateKey, __client

__operatorAccountId = None
__operatorPrivateKey = None
__client = Client()
__client = Client(Network(network='testnet'))

return Success({
"message":"Successfully reset client.",
Expand All @@ -35,14 +35,20 @@ def reset():
@method
def generateKey(type: str=None, fromKey: str=None, threshold: int=None, keys: list=None):
if type == "ed25519PublicKey":
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})
if fromKey is None:
return Success({"key": PrivateKey.generate_ed25519().public_key().to_string_raw()})
else:
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})

elif type == "ecdsaSecp256k1PublicKey":
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})
if fromKey is None:
return Success({"key": PrivateKey.generate_ecdsa().public_key().to_string_raw()})
else:
new_account_private_key = PrivateKey.from_string(fromKey)
new_account_public_key = new_account_private_key.public_key()
return Success({"key": new_account_public_key.to_string_raw()})

elif type == "ed25519PrivateKey":
new_account_private_key = PrivateKey.generate()
Expand Down
7 changes: 0 additions & 7 deletions tests/key_identifier_tester.py

This file was deleted.

0 comments on commit d4fe107

Please sign in to comment.