Skip to content

Commit 7a62fba

Browse files
authored
Test Suite Architecture Refactoring (#504)
* refactor: completely redo internal network processing Signed-off-by: Rob Walworth <[email protected]> * refactor: formatting Signed-off-by: Rob Walworth <[email protected]> * refactor: final improvements Signed-off-by: Rob Walworth <[email protected]> * refactor: more improvements Signed-off-by: Rob Walworth <[email protected]> * refactor: static code analysis checks Signed-off-by: Rob Walworth <[email protected]> * refactor: static code analysis comments Signed-off-by: Rob Walworth <[email protected]> * refactor: forgot one Signed-off-by: Rob Walworth <[email protected]> * docs: remove warning and add TODO Signed-off-by: Rob Walworth <[email protected]> * chore: fix codeql warning Signed-off-by: Rob Walworth <[email protected]> * fix: disable network updates during integration tests Signed-off-by: Rob Walworth <[email protected]> * fix: disable automatic network updates for tests Signed-off-by: Rob Walworth <[email protected]> * refactor: all new testing architecture Signed-off-by: Rob Walworth <[email protected]> * docs: remove unnecessary md files Signed-off-by: Rob Walworth <[email protected]> * refactor: formatting Signed-off-by: Rob Walworth <[email protected]> * rmv: unnecessary files Signed-off-by: Rob Walworth <[email protected]> * rmv: old files from package.swift Signed-off-by: Rob Walworth <[email protected]> --------- Signed-off-by: Rob Walworth <[email protected]>
1 parent 6a2adee commit 7a62fba

File tree

532 files changed

+15923
-14705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

532 files changed

+15923
-14705
lines changed

.env.example

Lines changed: 130 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,136 @@
1-
##
2-
# Environment variables for sdk examples
3-
##
4-
# Account that will pay query and transaction fees
5-
OPERATOR_ID=
1+
# =============================================================================
2+
# Hiero SDK Swift - Environment Configuration
3+
# =============================================================================
4+
# Copy this file to .env and fill in your values.
5+
# All HIERO_* variables are used by the test suite.
6+
# OPERATOR_* variables are used by the SDK examples.
67

7-
# Default private key to use to sign for all transactions and queries
8-
OPERATOR_KEY=
8+
# =============================================================================
9+
# SDK Examples Configuration
10+
# =============================================================================
11+
# These variables are used when running the examples in the Examples/ directory.
912

10-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
11-
NETWORK_NAME=
13+
# Account ID that will pay query and transaction fees for examples
14+
# Format: shard.realm.num (e.g., 0.0.1234)
15+
OPERATOR_ID=0.0.1234
1216

13-
##
14-
# Environment variables for integration tests
15-
##
16-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
17-
TEST_OPERATOR_ID=
17+
# Private key to sign transactions and queries for examples
18+
# Format: DER-encoded hex string
19+
OPERATOR_KEY=302e020100300506032b657004220420...
1820

19-
# Default private key to use to sign for all transactions and queries
20-
TEST_OPERATOR_KEY=
21+
# Network to connect to for examples
22+
# Values: localhost, testnet, previewnet, mainnet
23+
NETWORK_NAME=testnet
2124

22-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
23-
TEST_NETWORK_NAME=
25+
# =============================================================================
26+
# Integration Tests - Required Configuration
27+
# =============================================================================
28+
# These variables are required to run integration tests (HieroIntegrationTests).
29+
# Unit tests (HieroUnitTests) do not require any environment configuration.
2430

25-
# Enables non-free transactions when testing
26-
TEST_RUN_NONFREE=1
31+
# Account ID that will pay query and transaction fees for tests
32+
# Format: shard.realm.num (e.g., 0.0.1234)
33+
HIERO_OPERATOR_ID=0.0.1234
34+
35+
# Private key to sign transactions and queries for tests
36+
# Format: DER-encoded hex string
37+
HIERO_OPERATOR_KEY=302e020100300506032b657004220420...
38+
39+
# =============================================================================
40+
# Integration Tests - Network Configuration
41+
# =============================================================================
42+
43+
# Environment type - determines which network to connect to
44+
# Values: unit, local, testnet, previewnet, mainnet, custom
45+
# Default: Determined by HIERO_PROFILE (local profile uses 'local')
46+
HIERO_ENVIRONMENT_TYPE=testnet
47+
48+
# =============================================================================
49+
# Integration Tests - Custom Network Configuration
50+
# =============================================================================
51+
# Only needed when HIERO_ENVIRONMENT_TYPE=custom
52+
53+
# Comma-separated list of consensus node addresses
54+
# Format: host:port,host:port,...
55+
# Example: 127.0.0.1:50211,192.168.1.100:50211
56+
HIERO_CONSENSUS_NODES=
57+
58+
# Comma-separated list of consensus node account IDs (must match HIERO_CONSENSUS_NODES count)
59+
# Format: shard.realm.num,shard.realm.num,...
60+
# Example: 0.0.3,0.0.4
61+
HIERO_CONSENSUS_NODE_ACCOUNT_IDS=
62+
63+
# Comma-separated list of mirror node addresses
64+
# Format: host:port,host:port,...
65+
# Example: 127.0.0.1:5600 or mainnet.mirrornode.hedera.com:443
66+
HIERO_MIRROR_NODES=
67+
68+
# =============================================================================
69+
# Integration Tests - Test Profile
70+
# =============================================================================
71+
72+
# Test profile - provides pre-configured defaults for different scenarios
73+
# Values:
74+
# local - Local development with local node (default)
75+
# ciUnit - CI unit tests (unit environment)
76+
# ciIntegration - CI integration tests (local environment, verbose logging)
77+
# development - Development against remote networks (testnet)
78+
# Default: local
79+
HIERO_PROFILE=local
80+
81+
# =============================================================================
82+
# Integration Tests - Feature Flags
83+
# =============================================================================
84+
85+
# Maximum test duration in seconds before timeout
86+
# Default: 300 (5 minutes)
87+
HIERO_MAX_DURATION=300
88+
89+
# Enable parallel test execution
90+
# Values: 1 (enabled), 0 or unset (disabled)
91+
# Note: Parallel execution is not yet implemented
92+
# Default: disabled
93+
HIERO_PARALLEL=0
94+
95+
# Enable verbose logging during tests
96+
# Values: 1 (enabled), 0 or unset (disabled)
97+
# Default: disabled
98+
HIERO_VERBOSE=0
99+
100+
# =============================================================================
101+
# Integration Tests - Cleanup Policy
102+
# =============================================================================
103+
# Controls automatic cleanup of test resources after tests complete.
104+
# Cleanup economics:
105+
# - Accounts/Contracts: Cleanup RECOVERS HBAR (recommended)
106+
# - Tokens/Files/Topics: Cleanup COSTS HBAR (optional)
107+
108+
# Master cleanup switch - overrides all individual settings
109+
# Values: 1 (enable all cleanup), 0 (disable all cleanup), unset (use individual settings)
110+
# When set, ignores all HIERO_CLEANUP_* individual settings
111+
HIERO_ENABLE_CLEANUP=
112+
113+
# Clean up test accounts after tests (recovers locked HBAR)
114+
# Values: 1 (enabled), 0 (disabled)
115+
# Default: 1 (enabled) - Recommended
116+
HIERO_CLEANUP_ACCOUNTS=1
117+
118+
# Clean up test contracts after tests (can recover HBAR)
119+
# Values: 1 (enabled), 0 (disabled)
120+
# Default: 1 (enabled) - Recommended
121+
HIERO_CLEANUP_CONTRACTS=1
122+
123+
# Clean up test tokens after tests (costs HBAR, no recovery)
124+
# Values: 1 (enabled), 0 (disabled)
125+
# Default: 0 (disabled)
126+
HIERO_CLEANUP_TOKENS=0
127+
128+
# Clean up test files after tests (costs HBAR, no recovery)
129+
# Values: 1 (enabled), 0 (disabled)
130+
# Default: 0 (disabled)
131+
HIERO_CLEANUP_FILES=0
132+
133+
# Clean up test topics after tests (costs HBAR, no recovery)
134+
# Values: 1 (enabled), 0 (disabled)
135+
# Default: 0 (disabled)
136+
HIERO_CLEANUP_TOPICS=0

.github/workflows/swift-ci.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ jobs:
107107
run: |
108108
swift build
109109
110-
- name: Run unit tests (HieroTests)
111-
run: swift test --filter HieroTests
110+
- name: Run unit tests (HieroUnitTests)
111+
env:
112+
HIERO_PROFILE: ciUnit
113+
run: swift test --filter HieroUnitTests
112114

113115
- name: Prepare Hiero Solo
114116
id: solo
@@ -117,17 +119,10 @@ jobs:
117119
installMirrorNode: true
118120
mirrorNodeVersion: v0.142.0
119121
hieroVersion: v0.68.0
120-
121-
- name: Write .env for tests
122-
run: |
123-
umask 077
124-
{
125-
echo "TEST_NETWORK_NAME=localhost"
126-
echo "TEST_RUN_NONFREE=1"
127-
echo "TEST_OPERATOR_ID=0.0.2"
128-
echo "TEST_OPERATOR_KEY=302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"
129-
} > .env
130-
cat .env
131122

132-
- name: Run integration tests (HieroE2ETests)
133-
run: swift test --filter HieroE2ETests
123+
- name: Run integration tests (HieroIntegrationTests)
124+
env:
125+
HIERO_PROFILE: ciIntegration
126+
HIERO_OPERATOR_ID: 0.0.2
127+
HIERO_OPERATOR_KEY: 302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137
128+
run: swift test --filter HieroIntegrationTests

Examples/ConsensusPubSubChunked/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal enum Program {
3131
try await Task.sleep(nanoseconds: 1_000_000_000 * 10)
3232

3333
_ = Task {
34-
let bigContents = try await HieroExampleUtilities.Resources.bigContents
34+
let bigContents = HieroExampleUtilities.Resources.bigContents
3535

3636
print(
3737
"about to prepare a transaction to send a message of \(bigContents.count) bytes"

Examples/CreateSimpleContract/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal enum Program {
1212

1313
client.setOperator(env.operatorAccountId, env.operatorKey)
1414

15-
let bytecode = try await HieroExampleUtilities.Resources.simpleContract
15+
let bytecode = HieroExampleUtilities.Resources.simpleContract
1616

1717
// create the contract's bytecode file
1818
let fileTransactionResponse = try await FileCreateTransaction()

Examples/CreateStatefulContract/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal enum Program {
1212

1313
client.setOperator(env.operatorAccountId, env.operatorKey)
1414

15-
let bytecode = try await HieroExampleUtilities.Resources.statefulContract
15+
let bytecode = HieroExampleUtilities.Resources.statefulContract
1616

1717
// create the contract's bytecode file
1818
let fileTransactionResponse = try await FileCreateTransaction()

Examples/FileAppendChunked/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftDotenv
55
@main
66
internal enum Program {
77
internal static func main() async throws {
8-
async let bigContents = HieroExampleUtilities.Resources.bigContents
8+
let bigContents = HieroExampleUtilities.Resources.bigContents
99
let env = try Dotenv.load()
1010
let client = try Client.forName(env.networkName)
1111

Examples/MirrorNodeContractQuery/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal enum Program {
1515
client.setOperator(env.operatorAccountId, env.operatorKey)
1616

1717
/// Grab the contract bytecode.
18-
let bytecode = try await HieroExampleUtilities.Resources.simpleContract
18+
let bytecode = HieroExampleUtilities.Resources.simpleContract
1919

2020
// Create the contract's bytecode file.
2121
var txResponse = try await FileCreateTransaction()

Package.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,32 @@ let package = Package(
158158
]
159159
),
160160
.testTarget(
161-
name: "HieroTests",
161+
name: "HieroTestSupport",
162162
dependencies: [
163163
"Hiero",
164+
"HieroProtobufs",
165+
.product(name: "SwiftDotenv", package: "swift-dotenv"),
166+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
167+
],
168+
path: "Tests/HieroTestSupport"
169+
),
170+
.testTarget(
171+
name: "HieroUnitTests",
172+
dependencies: [
173+
"Hiero",
174+
"HieroTestSupport",
164175
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
165176
],
166177
exclude: ["__Snapshots__"]
167178
),
168179
.testTarget(
169-
name: "HieroE2ETests",
180+
name: "HieroIntegrationTests",
170181
dependencies: [
171182
"Hiero",
183+
"HieroTestSupport",
172184
.product(name: "SwiftDotenv", package: "swift-dotenv"),
173-
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
174185
"HieroExampleUtilities",
175-
],
176-
exclude: ["File/__Snapshots__"]
186+
]
177187
),
178188
] + exampleTargets
179189
)

README.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,50 +84,45 @@ $ task example name=CreateAccount
8484
```
8585

8686
### Testing
87-
See [HieroTests](./Tests/HieroTests) and [HieroE2ETests](./Tests/HieroE2ETests)
8887

89-
Before running the integration tests (e2e)– an operator key, operator account id, and a network name must be set in an `.env` file. Unit tests do not require `.env` to be executed.
88+
See [Tests/README.md](./Tests/README.md) for comprehensive testing documentation.
9089

91-
```bash
92-
# Account that will pay query and transaction fees
93-
TEST_OPERATOR_ID=
94-
# Default private key to use to sign for all transactions and queries
95-
TEST_OPERATOR_KEY=
96-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
97-
TEST_NETWORK_NAME=
98-
```
90+
**Quick Start:**
9991

10092
```bash
101-
# Run all unit and e2e tests
102-
$ swift test
93+
# Unit tests (no network required)
94+
swift test --filter HieroUnitTests
10395

104-
# Run specific tests
105-
$ swift test --filter <subclass>/<testMethod>
96+
# Integration tests (requires .env configuration)
97+
swift test --filter HieroIntegrationTests
10698

107-
# e.g. AccountCreateTransactionTests/testSerialize (unit test)
108-
$ swift test --filter AccountCreateTransactionTests/testSerialize
99+
# All tests
100+
swift test
109101

110-
# e.g. AccountCreate/testInitialBalanceAndKey (e2e test)
111-
$ swift test --filter AccountCreate/testInitialBalanceAndKey
102+
# Specific test
103+
swift test --filter AccountCreateTransactionUnitTests/test_Serialize
112104
```
113105

114-
The networks testnet, previewnet, and mainnet are the related and publicly available [Hedera networks](https://docs.hedera.com/hedera/networks).
106+
**Environment Setup for Integration Tests:**
107+
108+
Create a `.env` file in the project root:
115109

110+
```bash
111+
HIERO_OPERATOR_ID=0.0.1234
112+
HIERO_OPERATOR_KEY=302e020100300506032b657004220420...
113+
HIERO_ENVIRONMENT_TYPE=testnet
114+
```
116115

117-
### Local Environment Testing
116+
**Local Node Testing:**
118117

119-
You can run tests through your localhost using the `hiero-local-node` service.
120-
For instructions on how to set up and run local node, follow the steps in the [git repository](https://github.com/hiero-ledger/hiero-local-node).
121-
Once the local node is running in Docker, the appropriate `.env` values must be set:
118+
For testing against [hiero-local-node](https://github.com/hiero-ledger/hiero-local-node):
122119

123120
```bash
124-
TEST_OPERATOR_ID=0.0.2
125-
TEST_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
126-
TEST_NETWORK_NAME=localhost
121+
HIERO_OPERATOR_ID=0.0.2
122+
HIERO_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
123+
HIERO_ENVIRONMENT_TYPE=local
127124
```
128125

129-
Lastly, run the tests using `swift test`
130-
131126
## Contribute
132127

133128
- To contribute, please refer to the **[Hiero-Ledger's contribution guidelines](https://github.com/hiero-ledger/.github/blob/main/CONTRIBUTING.md)**

Sources/Hiero/Contract/ContractCreateFlow.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ public final class ContractCreateFlow {
430430
}
431431

432432
private static func splitBytecode(_ bytecode: Data) -> (fileCreate: Data, fileAppend: Data?) {
433-
let bytecode = bytecode.hexStringEncoded().data(using: .utf8)!
434433
guard bytecode.count > maxFileCreateDataBytes else {
435434
return (bytecode, nil)
436435
}

0 commit comments

Comments
 (0)