Skip to content

Commit

Permalink
local run test script working
Browse files Browse the repository at this point in the history
  • Loading branch information
nadineloepfe committed Dec 17, 2024
1 parent 79079ac commit 2d87524
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from src.crypto.private_key import PrivateKey
from src.tokens.token_create_transaction import TokenCreateTransaction
from src.tokens.token_associate_transaction import TokenAssociateTransaction
from src.tokens.token_id import TokenId
from src.transaction.transfer_transaction import TransferTransaction
from src.response_code import ResponseCode

Expand Down Expand Up @@ -57,9 +58,6 @@ def create_new_account(client, initial_balance=100000000):
def create_token(client, operator_id):
"""Create a new token and return its TokenId instance."""

admin_key = PrivateKey.generate()
admin_public_key = admin_key.public_key()

transaction = (
TokenCreateTransaction()
.set_token_name("ExampleToken")
Expand All @@ -83,10 +81,9 @@ def create_token(client, operator_id):
sys.exit(1)

token_id = receipt.tokenId
print(f"Token creation successful. Token ID: {token_id}, Admin Key: {admin_key.to_string()}")

return token_id, admin_key
print(f"Token creation successful. Token ID: {token_id}")

return token_id

def associate_token(client, recipient_id, recipient_private_key, token_id):
"""Associate the specified token with the recipient account."""
Expand All @@ -97,7 +94,7 @@ def associate_token(client, recipient_id, recipient_private_key, token_id):
.freeze_with(client)
)
transaction.sign(client.operator_private_key) # sign with operator's key (payer)
transaction.sign(recipient_private_key) # sign with newly created accounts key (recipient)
transaction.sign(recipient_private_key) # sign with newly created account's key (recipient)

try:
receipt = transaction.execute(client)
Expand Down Expand Up @@ -132,17 +129,16 @@ def transfer_token(client, recipient_id, token_id):
def main():
operator_id, operator_key = load_operator_credentials()

# network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3))
network_type = os.getenv('NETWORK') # 'solo'
network_type = os.getenv('NETWORK')
network = Network(network=network_type)

client = Client(network)
client.set_operator(operator_id, operator_key)

recipient_id, recipient_private_key = create_new_account(client)
token_id, admin_key = create_token(client, operator_id)
token_id = create_token(client, operator_id)
associate_token(client, recipient_id, recipient_private_key, token_id)
transfer_token(client, recipient_id, token_id)

if __name__ == "__main__":
main()
main()

0 comments on commit 2d87524

Please sign in to comment.