Skip to content

Commit 043c5ca

Browse files
committed
fix(test): replace local test operator
Signed-off-by: Ricky Saechao <[email protected]>
1 parent 0bd14e8 commit 043c5ca

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Account that will pay query and transaction fees
2-
OPERATOR_ACCOUNT_ID=
2+
TEST_OPERATOR_ID=0.0.1022
33

44
# Default private key to use to sign for all transactions and queries
5-
OPERATOR_KEY=
5+
TEST_OPERATOR_KEY=302e020100300506032b657004220420a608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4
66

77
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
8-
TEST_NETWORK_NAME=
8+
TEST_NETWORK_NAME=localhost
99

1010
# Enables non-free transactions when testing
1111
TEST_RUN_NONFREE=1

.github/workflows/swift-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ jobs:
6262
- name: "Create env file"
6363
run: |
6464
touch .env
65-
echo TEST_OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137" >> .env
66-
echo TEST_OPERATOR_ID="0.0.2" >> .env
67-
echo TEST_HEDERA_NETWORK="localhost" >> .env
65+
echo TEST_OPERATOR_KEY="302e020100300506032b657004220420a608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4" >> .env
66+
echo TEST_OPERATOR_ID="0.0.1022" >> .env
67+
echo TEST_NETWORK_NAME="localhost" >> .env
6868
echo TEST_RUN_NONFREE="1" >> .env
6969
cat .env
7070

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ protoc --grpc-swift_opt=Visibility=Public,FileNaming=PathToUnderscores,Server=fa
9595
### Integration Tests
9696
Before running the integration tests, an operator key, operator account id, and a network name must be set in an `.env` file.
9797
```bash
98-
# Account that will pay query and transaction fees
99-
TEST_OPERATOR_ACCOUNT_ID=
100-
# Default private key to use to sign for all transactions and queries
98+
TEST_OPERATOR_ID=
99+
# Default private key to use to sign for all transactions and queries.
101100
TEST_OPERATOR_KEY=
102-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
101+
# Network names: "localhost", "testnet", "previewnet", "mainnet".
103102
TEST_NETWORK_NAME=
103+
# Running on-chain tests if this value is set to 1.
104+
TEST_RUN_NONFREE=
104105
```
105106
```bash
106107
# Run tests
@@ -113,12 +114,8 @@ Hedera offers a way to run tests through your localhost using the `hedera-local-
113114
For instructions on how to set up and run local node, follow the steps in the git repository:
114115
https://github.com/hashgraph/hedera-local-node
115116

116-
Once the local node is running in Docker, the appropriate `.env` values must be set:
117-
```bash
118-
TEST_OPERATOR_ACCOUNT_ID=0.0.2
119-
TEST_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
120-
TEST_NETWORK_NAME=localhost
121-
```
117+
Once the local node is running in Docker, use the environment variable values from the `.env.example` in the `.env` file.
118+
122119
Lastly, run the tests using `swift test`
123120

124121
### Generate SDK

Tests/HederaE2ETests/Config.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ internal struct TestEnvironment {
119119

120120
`operator` = .init(env: env)
121121

122+
if network == "localhost" {
123+
self.isLocal = true
124+
} else {
125+
self.isLocal = false
126+
}
127+
122128
if `operator` == nil && runNonfree {
123129
print("warn: forcing `runNonfree` to false because operator is nil", stderr)
124130
self.runNonfreeTests = false
@@ -130,6 +136,7 @@ internal struct TestEnvironment {
130136
internal let network: String
131137
internal let `operator`: TestEnvironment.Operator?
132138
internal let runNonfreeTests: Bool
139+
internal let isLocal: Bool
133140
}
134141

135142
internal struct Operator {
@@ -172,7 +179,7 @@ internal struct TestEnvironment {
172179
private enum Keys {
173180
fileprivate static let network = "TEST_NETWORK_NAME"
174181
fileprivate static let operatorKey = "TEST_OPERATOR_KEY"
175-
fileprivate static let operatorAccountId = "TEST_OPERATOR_ACCOUNT_ID"
182+
fileprivate static let operatorAccountId = "TEST_OPERATOR_ID"
176183
fileprivate static let runNonfree = "TEST_RUN_NONFREE"
177184
}
178185

@@ -239,10 +246,12 @@ internal struct NonfreeTestEnvironment {
239246

240247
self.operator = base.`operator`!
241248
self.network = base.network
249+
self.isLocal = base.isLocal
242250
}
243251

244252
internal let network: String
245253
internal let `operator`: TestEnvironment.Operator
254+
internal let isLocal: Bool
246255
}
247256

248257
private init?(_ env: TestEnvironment) {

Tests/HederaE2ETests/Topic/TopicMessage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ internal class TopicMessage: XCTestCase {
2727
internal func testBasic() async throws {
2828
let testEnv = try TestEnvironment.nonFree
2929

30+
try XCTSkipIf(testEnv.config.isLocal)
31+
3032
let topic = try await Topic.create(testEnv)
3133

3234
addTeardownBlock {
@@ -85,6 +87,8 @@ internal class TopicMessage: XCTestCase {
8587

8688
internal func testLarge() async throws {
8789
let testEnv = try TestEnvironment.nonFree
90+
try XCTSkipIf(testEnv.config.isLocal)
91+
8892
async let bigContentsFut = Resources.bigContents.data(using: .utf8)!
8993

9094
let topic = try await Topic.create(testEnv)

0 commit comments

Comments
 (0)