Skip to content

Commit 7d38122

Browse files
committed
removed swiftlint issues
1 parent 48716c8 commit 7d38122

File tree

4 files changed

+78
-108
lines changed

4 files changed

+78
-108
lines changed

Sources/Web3Core/KeystoreManager/BIP44.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import Foundation
77

88
public protocol BIP44 {
99
/**
10-
Derive an `HDNode` based on the provided `path`. The function will throws `BIP44Error.warning` if it was invoked with `warns` as true and the root key doesn't have a previous child with at least one transaction, using false the child node will be derived directly not throwing. This function needs to query the blockchain history when `warns`is true, so it can throw network errors.
11-
- Parameter path: valid BIP32 path.
12-
- Parameter warns: true to be warned about following BIP44 standard, false otherwise.
13-
- Throws: `BIP44Error.warning` if the child key shouldn't be used according to BIP44 standard.
14-
- Returns: an HDNode child key for the provided `path` if it can be created, otherwise nil
15-
*/
10+
Derive an `HDNode` based on the provided `path`. The function will throws `BIP44Error.warning` if it was invoked with `warns` as true and the root key doesn't have a previous child with at least one transaction, using false the child node will be derived directly not throwing. This function needs to query the blockchain history when `warns`is true, so it can throw network errors.
11+
- Parameter path: valid BIP32 path.
12+
- Parameter warns: true to be warned about following BIP44 standard, false otherwise.
13+
- Throws: `BIP44Error.warning` if the child key shouldn't be used according to BIP44 standard.
14+
- Returns: an HDNode child key for the provided `path` if it can be created, otherwise nil
15+
*/
1616
func derive(path: String, warns: Bool, transactionChecker: TransactionChecker) async throws -> HDNode?
1717
}
1818

@@ -23,11 +23,11 @@ public enum BIP44Error: Error, Equatable {
2323

2424
public protocol TransactionChecker {
2525
/**
26-
It verifies if the provided `address` has at least one transaction
27-
- Parameter address: to be queried
28-
- Throws: any error related to query the blockchain provider
29-
- Returns: true if the `address` has at least one transaction, false otherwise
30-
*/
26+
It verifies if the provided `address` has at least one transaction
27+
- Parameter address: to be queried
28+
- Throws: any error related to query the blockchain provider
29+
- Returns: true if the `address` has at least one transaction, false otherwise
30+
*/
3131
func hasTransactions(address: String) async throws -> Bool
3232
}
3333

@@ -45,8 +45,8 @@ extension HDNode: BIP44 {
4545
var hasTransactions = false
4646
for searchAddressIndex in 0..<maxUnusedAddressIndexes {
4747
if let searchPath = path.newPath(account: searchAccount, addressIndex: searchAddressIndex),
48-
let childNode = derive(path: searchPath, derivePrivateKey: true),
49-
let ethAddress = Utilities.publicToAddress(childNode.publicKey) {
48+
let childNode = derive(path: searchPath, derivePrivateKey: true),
49+
let ethAddress = Utilities.publicToAddress(childNode.publicKey) {
5050
hasTransactions = try await transactionChecker.hasTransactions(address: ethAddress.address)
5151
if hasTransactions {
5252
break
@@ -93,10 +93,10 @@ extension String {
9393
}
9494

9595
/**
96-
Transforms a bip44 path into a new one changing `account` & `index`. The resulting one will have the change value equal to `0` to represent external chain. Format `m/44'/coin_type'/account'/change/address_index`
97-
- Parameter account: the new `account` to use
98-
- Parameter addressIndex: the new `addressIndex` to use
99-
- Returns: a valid bip44 path with the provided `account`, `addressIndex`and external `change` or nil otherwise
96+
Transforms a bip44 path into a new one changing `account` & `index`. The resulting one will have the change value equal to `0` to represent external chain. Format `m/44'/coin_type'/account'/change/address_index`
97+
- Parameter account: the new `account` to use
98+
- Parameter addressIndex: the new `addressIndex` to use
99+
- Returns: a valid bip44 path with the provided `account`, `addressIndex`and external `change` or nil otherwise
100100
*/
101101
func newPath(account: Int, addressIndex: Int) -> String? {
102102
guard isBip44Path else {

Tests/web3swiftTests/localTests/BIP44Tests.swift

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ import Web3Core
88
@testable import web3swift
99

1010
final class BIP44Tests: XCTestCase {
11-
private var accountZeroScannedAddresses: [String]!
12-
private var accountZeroAndOneScannedAddresses: [String]!
13-
private var mockTransactionChecker: MockTransactionChecker!
14-
15-
override func setUpWithError() throws {
16-
try super.setUpWithError()
17-
mockTransactionChecker = MockTransactionChecker()
18-
accountZeroScannedAddresses = [
11+
private var accountZeroScannedAddresses: [String] {
12+
[
1913
"0x31a4aD7593D06D049b3Cc07aB5430264Bf7e069f",
2014
"0x2b4fb04d485446ade5889e77b0cbC2c71075209c",
2115
"0x93DDC6583D4BF6e9b309cfBdC681A78F8B5f37Ff",
@@ -36,7 +30,9 @@ final class BIP44Tests: XCTestCase {
3630
"0xd521A57ea2bAA6396AE916aD2bC4972a9b3635EB",
3731
"0x561192570145C499f0951dEc0a4Df80D0D0A96bb",
3832
"0x4DdBe17BB1b0056941A1425739978e44D462D7DD"]
39-
accountZeroAndOneScannedAddresses = [
33+
}
34+
private var accountZeroAndOneScannedAddresses: [String] {
35+
[
4036
"0x31a4aD7593D06D049b3Cc07aB5430264Bf7e069f",
4137
"0x3C7b0FadC415d0be5EBa971DC7Dcc39DdDcd4AF7",
4238
"0x73C13e421eF367c4F55BBC02a8e2a2b12e82f717",
@@ -59,13 +55,7 @@ final class BIP44Tests: XCTestCase {
5955
"0x111FbB56b0B5c97F2896Ee722A917b261bCC77fC",
6056
"0xF3F66e5C119620eBDbD7Fb48B4b5d365De5c9750"]
6157
}
62-
63-
override func tearDownWithError() throws {
64-
try super.tearDownWithError()
65-
mockTransactionChecker = nil
66-
accountZeroScannedAddresses = nil
67-
accountZeroAndOneScannedAddresses = nil
68-
}
58+
private var mockTransactionChecker: MockTransactionChecker = .init()
6959

7060
func testDeriveNoWarn() async throws {
7161
let rootNode = try rootNode()

Tests/web3swiftTests/localTests/StringBIP44Tests.swift

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,48 @@ import XCTest
77
@testable import Web3Core
88

99
final class StringBIP44Tests: XCTestCase {
10-
private var invalidPaths: [String]!
11-
12-
override func setUpWithError() throws {
13-
try super.setUpWithError()
14-
invalidPaths = ["",
15-
"m",
16-
"m/",
17-
"m/44",
18-
"m/44'",
19-
"m/44'/",
20-
"m/44'/60",
21-
"m/44'/60'",
22-
"m/44'/60'/",
23-
"m/44'/60'/0",
24-
"m/44'/60'/0'",
25-
"m/44'/60'/0'/",
26-
"m/44'/60'/0'/0",
27-
"m/44'/60'/0'/0/",
28-
"/44'/60'/0'/0/0",
29-
"m44'/60'/0'/0/0",
30-
"m0'/60'/0'/0/0",
31-
"m/'/60'/0'/0/0",
32-
"m/60'/0'/0/0",
33-
"m/44'/60/0'/0/0",
34-
"m/44'/'/0'/0/0",
35-
"m/44'/60'/0/0/0",
36-
"m/44'/60'/'/0/0",
37-
"m/44'/60'/0'/0",
38-
"m/44'/60'/0'/0/",
39-
"m/44'/60'/0'/-1/0",
40-
"m/44'/60'/0'/2/0",
41-
"m/44'/60.0'/0'/0/0",
42-
"m/44'/60'/0.0'/0/0",
43-
"m/44'/60'/0'/0/0.0"]
10+
private var invalidPaths: [String] {
11+
[
12+
"",
13+
"m",
14+
"m/",
15+
"m/44",
16+
"m/44'",
17+
"m/44'/",
18+
"m/44'/60",
19+
"m/44'/60'",
20+
"m/44'/60'/",
21+
"m/44'/60'/0",
22+
"m/44'/60'/0'",
23+
"m/44'/60'/0'/",
24+
"m/44'/60'/0'/0",
25+
"m/44'/60'/0'/0/",
26+
"/44'/60'/0'/0/0",
27+
"m44'/60'/0'/0/0",
28+
"m0'/60'/0'/0/0",
29+
"m/'/60'/0'/0/0",
30+
"m/60'/0'/0/0",
31+
"m/44'/60/0'/0/0",
32+
"m/44'/'/0'/0/0",
33+
"m/44'/60'/0/0/0",
34+
"m/44'/60'/'/0/0",
35+
"m/44'/60'/0'/0",
36+
"m/44'/60'/0'/0/",
37+
"m/44'/60'/0'/-1/0",
38+
"m/44'/60'/0'/2/0",
39+
"m/44'/60.0'/0'/0/0",
40+
"m/44'/60'/0.0'/0/0",
41+
"m/44'/60'/0'/0/0.0"]
4442
}
45-
46-
override func tearDownWithError() throws {
47-
try super.tearDownWithError()
48-
invalidPaths = nil
49-
}
50-
43+
5144
// MARK: - accountFromPath
52-
45+
5346
func testInvalidPathReturnNilAccount() throws {
5447
invalidPaths.forEach { invalidPath in
5548
XCTAssertNil(invalidPath.accountFromPath)
5649
}
5750
}
58-
51+
5952
func testValidPathReturnAccount() {
6053
let scenarios: [TestScenario<String, Int>] = [
6154
.init(input: "m/44'/60'/0'/1/4", expected: 0),
@@ -67,47 +60,48 @@ final class StringBIP44Tests: XCTestCase {
6760
XCTAssertEqual(scenario.input.accountFromPath, scenario.expected)
6861
}
6962
}
70-
63+
7164
// MARK: - isBip44Path
72-
65+
7366
func testVerifyBip44Paths() {
74-
let validPaths = ["m/44'/0'/0'/0/0",
75-
"m/44'/1'/0'/0/0",
76-
"m/44'/0'/1'/0/0",
77-
"m/44'/0'/0'/1/0",
78-
"m/44'/0'/0'/0/1"]
67+
let validPaths = [
68+
"m/44'/0'/0'/0/0",
69+
"m/44'/1'/0'/0/0",
70+
"m/44'/0'/1'/0/0",
71+
"m/44'/0'/0'/1/0",
72+
"m/44'/0'/0'/0/1"]
7973
validPaths.forEach { validPath in
8074
XCTAssertTrue(validPath.isBip44Path)
8175
}
8276
}
83-
77+
8478
func testVerifyNotBip44Paths() {
8579
invalidPaths.forEach { invalidPath in
8680
XCTAssertFalse(invalidPath.isBip44Path)
8781
}
8882
}
89-
83+
9084
// MARK: - newPath
91-
85+
9286
func testNotBip44PathNewPathReturnsNil() {
9387
invalidPaths.forEach { invalidPath in
9488
XCTAssertNil(invalidPath.newPath(account: Int.random(in: 0...Int.max), addressIndex: Int.random(in: 0...Int.max)))
9589
}
9690
}
97-
91+
9892
func testNewPathGeneratesExternalChainAsZero() {
9993
let path = "m/44'/60'/0'/1/0"
100-
94+
10195
let result = path.newPath(account: 0, addressIndex: 0)
102-
96+
10397
XCTAssertEqual(result, "m/44'/60'/0'/0/0")
10498
}
105-
99+
106100
func testNewPathGeneratesNewAccountAndAddressIndex() {
107101
let path = "m/44'/60'/1'/0/2"
108-
102+
109103
let result = path.newPath(account: 4, addressIndex: 3)
110-
104+
111105
XCTAssertEqual(result, "m/44'/60'/4'/0/3")
112106
}
113107
}

Tests/web3swiftTests/remoteTests/EtherscanTransactionCheckerTests.swift

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,9 @@ import XCTest
77
@testable import Web3Core
88

99
final class EtherscanTransactionCheckerTests: XCTestCase {
10-
private var testApiKey: String!
11-
private var vitaliksAddress: String!
12-
private var emptyAddress: String!
13-
14-
override func setUpWithError() throws {
15-
try super.setUpWithError()
16-
testApiKey = "4HVPVMV1PN6NGZDFXZIYKEZRP53IA41KVC"
17-
vitaliksAddress = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"
18-
emptyAddress = "0x1BeY3KhtHpfATH5Yqxz9d8Z1XbqZFSXtK7"
19-
}
20-
21-
override func tearDownWithError() throws {
22-
try super.tearDownWithError()
23-
testApiKey = nil
24-
vitaliksAddress = nil
25-
emptyAddress = nil
26-
}
10+
private var testApiKey: String { "4HVPVMV1PN6NGZDFXZIYKEZRP53IA41KVC" }
11+
private var vitaliksAddress: String { "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B" }
12+
private var emptyAddress: String { "0x1BeY3KhtHpfATH5Yqxz9d8Z1XbqZFSXtK7" }
2713

2814
func testHasTransactions() async throws {
2915
let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: testApiKey)

0 commit comments

Comments
 (0)