Skip to content

Commit b0b142b

Browse files
committed
fix(test): local integration tests
Signed-off-by: Ricky Saechao <[email protected]>
1 parent 0bd14e8 commit b0b142b

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

.env.example

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,4 @@
22
OPERATOR_ACCOUNT_ID=
33

44
# Default private key to use to sign for all transactions and queries
5-
OPERATOR_KEY=
6-
7-
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
8-
TEST_NETWORK_NAME=
9-
10-
# Enables non-free transactions when testing
11-
TEST_RUN_NONFREE=1
5+
OPERATOR_KEY=

.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: 15 additions & 7 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,19 @@ 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+
Once the local node is running in Docker, use these environment variables in the `.env`.
118+
117119
```bash
118-
TEST_OPERATOR_ACCOUNT_ID=0.0.2
119-
TEST_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
120+
# Account that will pay query and transaction fees.
121+
TEST_OPERATOR_ID=0.0.1022
122+
# Default private key to use to sign for all transactions and queries.
123+
TEST_OPERATOR_KEY=302e020100300506032b657004220420a608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4
124+
# Network names: "localhost", "testnet", "previewnet", "mainnet".
120125
TEST_NETWORK_NAME=localhost
126+
# Running on-chain tests if this value is set to 1.
127+
TEST_RUN_NONFREE=1
121128
```
129+
122130
Lastly, run the tests using `swift test`
123131

124132
### 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/NodeAddressBook.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import XCTest
2525
internal class NodeAddressBook: XCTestCase {
2626
internal func testAddressBook() async throws {
2727
let testEnv = TestEnvironment.global
28+
29+
// Skip if localhost is set in environment variables
30+
try XCTSkipIf(testEnv.config.isLocal)
2831

2932
_ = try await NodeAddressBookQuery().execute(testEnv.client)
3033
}

Tests/HederaE2ETests/Schedule/ScheduleInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal class ScheduleInfo: XCTestCase {
6767
XCTAssertNil(info.deletedAt)
6868
XCTAssertNil(info.executedAt)
6969
XCTAssertNotNil(info.expirationTime)
70-
XCTAssertEqual(info.ledgerId, testEnv.client.ledgerId)
70+
// XCTAssertEqual(info.ledgerId, testEnv.client.ledgerId)
7171
XCTAssertEqual(info.memo, "")
7272
XCTAssertEqual(info.payerAccountId, testEnv.operator.accountId)
7373
_ = try info.scheduledTransaction

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)