From 949a0b8981c3e409a532696bcb2afe7e331aedc7 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:24:10 +0000 Subject: [PATCH 01/26] added solo actions pipeline --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..55075ec --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Hedera Solo Integration Tests + +on: + push: + branches: + - main + pull_request: + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Setup Hedera Solo + uses: OpenElements/hedera-solo-action@v0.1 + id: solo + + - name: Set environment variables + run: | + echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" >> $GITHUB_ENV + echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" >> $GITHUB_ENV + echo "PUBLIC_KEY"${{ steps.solo.outputs.publicKey }}" >> $GITHUB_ENV + + - name: Run tests + run: python test.py From 163bb9169195e93b18513f08190f3516b2e69fe6 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:29:33 +0000 Subject: [PATCH 02/26] changing on push --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55075ec..c9f1db6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Hedera Solo Integration Tests on: push: branches: - - main + - '**' pull_request: jobs: From b3370a7843e83e0ffd7d4be25b663a36142ebb41 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:40:21 +0000 Subject: [PATCH 03/26] using new solo version --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9f1db6..652288f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,9 +22,9 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - - name: Setup Hedera Solo - uses: OpenElements/hedera-solo-action@v0.1 + - name: Prepare Hedera Solo id: solo + uses: OpenElements/hedera-solo-action@v0.3 - name: Set environment variables run: | From 1b554ce94ac77c82f21f05dce6ad42b13add4ebc Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:43:52 +0000 Subject: [PATCH 04/26] using v0.4 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 652288f..c9455ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - name: Prepare Hedera Solo id: solo - uses: OpenElements/hedera-solo-action@v0.3 + uses: OpenElements/hedera-solo-action@v0.4 - name: Set environment variables run: | From 33d3688d0aa74ba6d23cb03f3c03badd5f33181b Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:46:07 +0000 Subject: [PATCH 05/26] syntax change for env vars --- .github/workflows/test.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9455ce..abc091d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,9 +28,14 @@ jobs: - name: Set environment variables run: | - echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" >> $GITHUB_ENV - echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" >> $GITHUB_ENV - echo "PUBLIC_KEY"${{ steps.solo.outputs.publicKey }}" >> $GITHUB_ENV + echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" + echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" + echo "PUBLIC_KEY"${{ steps.solo.outputs.publicKey }}" - name: Run tests + env: + OPERATOR_ID: ${{ steps.solo.outputs.accountId }} + OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} + PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} run: python test.py + From dad3d9863301a2feb28e784899f1d6b57f3cd091 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:46:16 +0000 Subject: [PATCH 06/26] spacing --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index abc091d..e953d27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: - name: Set environment variables run: | echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" - echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" + echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" echo "PUBLIC_KEY"${{ steps.solo.outputs.publicKey }}" - name: Run tests From f18f4476baac2f0d4f41e2e55694eeab5e5420bb Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 12:50:56 +0000 Subject: [PATCH 07/26] typo --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e953d27..9289b89 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: run: | echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" - echo "PUBLIC_KEY"${{ steps.solo.outputs.publicKey }}" + echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}" - name: Run tests env: From 1f83fb5d3345fb0a237d1906dd871b584be3d30a Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 13:16:26 +0000 Subject: [PATCH 08/26] changing env load setup --- .github/workflows/test.yml | 1 + src/client/network.py | 4 ++++ test.py | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9289b89..415186a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,5 +37,6 @@ jobs: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} + NETWORK: solo run: python test.py diff --git a/src/client/network.py b/src/client/network.py index 1d28c82..c50e93a 100644 --- a/src/client/network.py +++ b/src/client/network.py @@ -11,6 +11,7 @@ class Network: 'mainnet': 'https://mainnet-public.mirrornode.hedera.com', 'testnet': 'https://testnet.mirrornode.hedera.com', 'previewnet': 'https://previewnet.mirrornode.hedera.com', + 'solo': 'localhost:8080' } DEFAULT_NODES = { @@ -40,6 +41,9 @@ class Network: ("2.previewnet.hedera.com:50211", AccountId(0, 0, 5)), ("3.previewnet.hedera.com:50211", AccountId(0, 0, 6)), ], + 'solo': [ + ("localhost:50211", AccountId(0, 0, 3)) + ], } def __init__(self, network='testnet'): diff --git a/test.py b/test.py index 24e062f..95c3ec0 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,5 @@ import os import sys -from dotenv import load_dotenv from src.client.network import Network from src.client.client import Client from src.account.account_id import AccountId @@ -11,8 +10,9 @@ from src.transaction.transfer_transaction import TransferTransaction from src.response_code import ResponseCode -# Load environment variables -load_dotenv() +# uncomment next two lines if running script manually to load .env file: +# from dotenv import load_dotenv +# load_dotenv() def load_operator_credentials(): """Load operator credentials from environment variables.""" @@ -127,7 +127,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network = Network() + network = Network(os.getenv('NETWORK')) client = Client(network) client.set_operator(operator_id, operator_key) From caddd79cb89ef2edb24dab3b4c50b7d77f100270 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 13:22:42 +0000 Subject: [PATCH 09/26] adding requests to requirements --- .github/workflows/test.yml | 2 +- requirements.txt | 3 ++- test.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 415186a..3dda03b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,6 @@ jobs: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - NETWORK: solo + NETWORK: 'solo' run: python test.py diff --git a/requirements.txt b/requirements.txt index 1267db6..59c3b62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ protobuf==5.27.2 grpcio grpcio-tools cryptography -python-dotenv \ No newline at end of file +python-dotenv +requests \ No newline at end of file diff --git a/test.py b/test.py index 95c3ec0..c41a04d 100644 --- a/test.py +++ b/test.py @@ -127,7 +127,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network = Network(os.getenv('NETWORK')) + network = Network(os.getenv('NETWORK', 'solo')) client = Client(network) client.set_operator(operator_id, operator_key) From 9308a48b7b0bd633424f507c68abfcae02b5aeb5 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 13:29:31 +0000 Subject: [PATCH 10/26] try installing package --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3dda03b..d54c4c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,11 +32,15 @@ jobs: echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}" + - name: Install your package + run: pip install -e . + - name: Run tests env: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} NETWORK: 'solo' + PYTHONPATH: ${{ github.workspace }}/src run: python test.py From ff69a08096e5813af040201b20b36857dc01afb1 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 13:40:25 +0000 Subject: [PATCH 11/26] hardcoding to test this --- .github/workflows/test.yml | 3 +-- setup.py | 3 ++- src/client/network.py | 22 +++++++++++----------- test.py | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d54c4c9..2c1335f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,6 @@ jobs: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - NETWORK: 'solo' - PYTHONPATH: ${{ github.workspace }}/src + NETWORK: run: python test.py diff --git a/setup.py b/setup.py index 344cb7e..11e8648 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ 'cryptography', 'protobuf==5.27.2', 'cryptography', - 'python-dotenv' + 'python-dotenv', + 'requests' ], ) diff --git a/src/client/network.py b/src/client/network.py index c50e93a..15709d8 100644 --- a/src/client/network.py +++ b/src/client/network.py @@ -46,24 +46,24 @@ class Network: ], } - def __init__(self, network='testnet'): + def __init__(self, node_address=None, node_account_id=None, network='testnet'): """ Initializes the Network with the specified network name. Args: network (str): The network to connect to ('mainnet', 'testnet', 'previewnet'). """ - if network not in ('mainnet', 'testnet', 'previewnet'): - raise ValueError("Network must be 'mainnet', 'testnet', or 'previewnet'.") + if node_address and node_account_id: + self.nodes = [(node_address, node_account_id)] + else: + self.network = network + self.nodes = self._fetch_nodes_from_mirror_node() + + if not self.nodes: + # default nodes if fetching from the mirror node API fails + self.nodes = self.DEFAULT_NODES[self.network] - self.network = network - self.nodes = self._fetch_nodes_from_mirror_node() - - if not self.nodes: - # default nodes if fetching from the mirror node API fails - self.nodes = self.DEFAULT_NODES[self.network] - - self.select_node() + self.select_node() def _fetch_nodes_from_mirror_node(self): """ diff --git a/test.py b/test.py index c41a04d..20bcf7a 100644 --- a/test.py +++ b/test.py @@ -127,7 +127,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network = Network(os.getenv('NETWORK', 'solo')) + network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) client = Client(network) client.set_operator(operator_id, operator_key) From 9e003e77d0ccd2355706b8bddd6d00f802e755b3 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 13:55:39 +0000 Subject: [PATCH 12/26] catering for manual run of script as well as pipeline run --- .github/workflows/test.yml | 14 ++++---------- test.py | 7 ++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c1335f..9ef32bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,10 +17,8 @@ jobs: with: python-version: '3.9' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt + - name: Install package with dependencies + run: pip install -e . - name: Prepare Hedera Solo id: solo @@ -32,14 +30,10 @@ jobs: echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}" - - name: Install your package - run: pip install -e . - - name: Run tests env: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - NETWORK: - run: python test.py - + NETWORK: 'solo' + run: python test.py \ No newline at end of file diff --git a/test.py b/test.py index 20bcf7a..210cfcf 100644 --- a/test.py +++ b/test.py @@ -127,7 +127,12 @@ 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', 'testnet') + if network_type == 'solo': + network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) + else: + network = Network(network=network_type) + client = Client(network) client.set_operator(operator_id, operator_key) From 9c4d6dbf9fb9944f312553c37336d2f433d3e7a7 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 14:04:00 +0000 Subject: [PATCH 13/26] catering for manual run of script as well as pipeline run --- .github/workflows/test.yml | 12 +++++++++--- test.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ef32bd..b96041c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,9 +17,14 @@ jobs: with: python-version: '3.9' - - name: Install package with dependencies - run: pip install -e . + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Install your package + run: pip install -e . + - name: Prepare Hedera Solo id: solo uses: OpenElements/hedera-solo-action@v0.4 @@ -36,4 +41,5 @@ jobs: OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} NETWORK: 'solo' - run: python test.py \ No newline at end of file + run: python test.py + diff --git a/test.py b/test.py index 210cfcf..8a485cb 100644 --- a/test.py +++ b/test.py @@ -127,7 +127,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network_type = os.getenv('NETWORK', 'testnet') + network_type = os.getenv('NETWORK') if network_type == 'solo': network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) else: From 5a52da81b5cc5d766e648a7b5326d1ae93d56f6d Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 14:10:35 +0000 Subject: [PATCH 14/26] revert to hardcoding --- .github/workflows/test.yml | 1 - test.py | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b96041c..8da1741 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,5 @@ jobs: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - NETWORK: 'solo' run: python test.py diff --git a/test.py b/test.py index 8a485cb..20bcf7a 100644 --- a/test.py +++ b/test.py @@ -127,12 +127,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network_type = os.getenv('NETWORK') - if network_type == 'solo': - network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) - else: - network = Network(network=network_type) - + network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) client = Client(network) client.set_operator(operator_id, operator_key) From a53048219da79b5e06c2bf1bf225e007c2ce4d52 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 14:19:52 +0000 Subject: [PATCH 15/26] reverting to v1 --- .github/workflows/test.yml | 10 +++++----- test.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8da1741..1ae3afd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,9 +22,6 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - - name: Install your package - run: pip install -e . - - name: Prepare Hedera Solo id: solo uses: OpenElements/hedera-solo-action@v0.4 @@ -35,10 +32,13 @@ jobs: echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}" + - name: Install your package + run: pip install -e . + - name: Run tests env: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - run: python test.py - + NETWORK: + run: python test.py \ No newline at end of file diff --git a/test.py b/test.py index 20bcf7a..3e447be 100644 --- a/test.py +++ b/test.py @@ -137,4 +137,4 @@ def main(): transfer_token(client, recipient_id, token_id) if __name__ == "__main__": - main() + main() \ No newline at end of file From fe5d3590fd95b958d4bc3f755b830b7e9e2e2e69 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 15:57:45 +0000 Subject: [PATCH 16/26] next test --- test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test.py b/test.py index 2b13c15..56a6434 100644 --- a/test.py +++ b/test.py @@ -10,9 +10,6 @@ from src.transaction.transfer_transaction import TransferTransaction from src.response_code import ResponseCode -# uncomment next two lines if running script manually to load .env file: -# from dotenv import load_dotenv -# load_dotenv() def load_operator_credentials(): """Load operator credentials from environment variables.""" @@ -127,7 +124,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network_type = os.getenv('NETWORK', 'testnet') + network_type = os.getenv('NETWORK') if network_type == 'solo': network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) else: From 80ad6476a38c4bef5ac9e05a2c5bdf3015c0ba67 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 16:04:16 +0000 Subject: [PATCH 17/26] pyenv back in test file --- .env.example | 3 ++- test.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 2b7ba11..0f7b23e 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,5 @@ RECIPIENT_ID= RECIPIENT_KEY= TOKEN_ID= TOKEN_NAME= -TOKEN_SYMBOL= \ No newline at end of file +TOKEN_SYMBOL= +NETWORK= \ No newline at end of file diff --git a/test.py b/test.py index 56a6434..ff145ef 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,6 @@ import os import sys +from dotenv import load_dotenv from src.client.network import Network from src.client.client import Client from src.account.account_id import AccountId @@ -10,6 +11,7 @@ from src.transaction.transfer_transaction import TransferTransaction from src.response_code import ResponseCode +load_dotenv() def load_operator_credentials(): """Load operator credentials from environment variables.""" From ed1d69474185dc80ca97b80c0f1ee57fb51fbbbd Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 16:08:55 +0000 Subject: [PATCH 18/26] rm double dependency installation --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26d3230..eb027ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,11 +17,6 @@ jobs: with: python-version: '3.9' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Prepare Hedera Solo id: solo uses: OpenElements/hedera-solo-action@v0.4 From ed4db87cb5a2f440798db80ed91cf6da816412ff Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 26 Nov 2024 16:14:10 +0000 Subject: [PATCH 19/26] and last refactor --- test.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test.py b/test.py index ff145ef..fbe675d 100644 --- a/test.py +++ b/test.py @@ -126,11 +126,7 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network_type = os.getenv('NETWORK') - if network_type == 'solo': - network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) - else: - network = Network(network=network_type) + network = Network(os.getenv('NETWORK')) client = Client(network) client.set_operator(operator_id, operator_key) From 29fa9b65b9f6b487781dbc9979c22fa4db611afa Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Sat, 14 Dec 2024 09:13:07 +0000 Subject: [PATCH 20/26] added env vars Signed-off-by: nadine.loepfe --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index 0f7b23e..1c7169f 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ OPERATOR_ID= OPERATOR_KEY= RECIPIENT_ID= RECIPIENT_KEY= +ADMIN_KEY= TOKEN_ID= TOKEN_NAME= TOKEN_SYMBOL= From 39e817f139a3691d0b4859a87d038663fec1ba80 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 10:51:59 +0100 Subject: [PATCH 21/26] added admin key --- .github/workflows/test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb027ae..0082a40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,11 @@ jobs: with: python-version: '3.9' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Prepare Hedera Solo id: solo uses: OpenElements/hedera-solo-action@v0.4 @@ -25,6 +30,7 @@ jobs: run: | echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}" echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}" + echo "ADMIN_KEY=${{ steps.solo.outputs.privateKey }}" echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}" - name: Install your package @@ -34,6 +40,7 @@ jobs: env: OPERATOR_ID: ${{ steps.solo.outputs.accountId }} OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }} + ADMIN_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} - NETWORK: 'solo' + NETWORK: solo run: python test.py \ No newline at end of file From 461f6e480c85fc13a057e2d17c00d8da0c3374dc Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 11:00:41 +0100 Subject: [PATCH 22/26] added admin key --- test.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test.py b/test.py index fbe675d..910bc09 100644 --- a/test.py +++ b/test.py @@ -56,6 +56,10 @@ 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") @@ -63,8 +67,10 @@ def create_token(client, operator_id): .set_decimals(2) .set_initial_supply(1000) .set_treasury_account_id(operator_id) + .set_admin_key(admin_public_key) .freeze_with(client) ) + transaction.sign(client.operator_private_key) try: @@ -78,9 +84,10 @@ def create_token(client, operator_id): sys.exit(1) token_id = receipt.tokenId - print(f"Token creation successful. Token ID: {token_id}") + print(f"Token creation successful. Token ID: {token_id}, Admin Key: {admin_key.to_string()}") + + return token_id, admin_key - return token_id def associate_token(client, recipient_id, recipient_private_key, token_id): """Associate the specified token with the recipient account.""" @@ -126,13 +133,14 @@ def transfer_token(client, recipient_id, token_id): def main(): operator_id, operator_key = load_operator_credentials() - network = Network(os.getenv('NETWORK')) + network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) + # 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 = create_token(client, operator_id) + token_id, admin_key = create_token(client, operator_id) associate_token(client, recipient_id, recipient_private_key, token_id) transfer_token(client, recipient_id, token_id) From b5b3cc8c28c86080c65334d51486821bf6432ea0 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 11:05:18 +0100 Subject: [PATCH 23/26] rm admin ket --- test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test.py b/test.py index 910bc09..30de211 100644 --- a/test.py +++ b/test.py @@ -67,7 +67,6 @@ def create_token(client, operator_id): .set_decimals(2) .set_initial_supply(1000) .set_treasury_account_id(operator_id) - .set_admin_key(admin_public_key) .freeze_with(client) ) From d7bab0370321f57d3affeeadd9547fed0af88466 Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 11:14:22 +0100 Subject: [PATCH 24/26] debug nework --- .github/workflows/test.yml | 4 +++- test.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0082a40..888465d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,4 +43,6 @@ jobs: ADMIN_KEY: ${{ steps.solo.outputs.privateKey }} PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} NETWORK: solo - run: python test.py \ No newline at end of file + run: | + echo $NETWORK + python test.py \ No newline at end of file diff --git a/test.py b/test.py index 30de211..b56347c 100644 --- a/test.py +++ b/test.py @@ -132,8 +132,9 @@ 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 = Network(network_type) + # network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3)) + network_type = os.getenv('NETWORK') + network = Network(network_type) client = Client(network) client.set_operator(operator_id, operator_key) From 79079ac0d895a9cfe26422c69cf91fb683f9124d Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 11:22:37 +0100 Subject: [PATCH 25/26] debug nework --- .github/workflows/test.yml | 1 - test.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 888465d..042dedb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,5 +44,4 @@ jobs: PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} NETWORK: solo run: | - echo $NETWORK python test.py \ No newline at end of file diff --git a/test.py b/test.py index b56347c..a3c3264 100644 --- a/test.py +++ b/test.py @@ -133,8 +133,8 @@ 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') - network = Network(network_type) + network_type = os.getenv('NETWORK') # 'solo' + network = Network(network=network_type) client = Client(network) client.set_operator(operator_id, operator_key) From 2d87524f47db38a17b1fcb1bd2d223cd0e75c0af Mon Sep 17 00:00:00 2001 From: "nadine.loepfe" Date: Tue, 17 Dec 2024 11:43:23 +0100 Subject: [PATCH 26/26] local run test script working --- test.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/test.py b/test.py index a3c3264..2ed82fa 100644 --- a/test.py +++ b/test.py @@ -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 @@ -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") @@ -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.""" @@ -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) @@ -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() \ No newline at end of file + main()