Skip to content

Commit e8a5e2b

Browse files
committed
add string spit test
1 parent c0e06d5 commit e8a5e2b

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

Package.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ import PackageDescription
66
let package = Package(
77
name: "Web3swift",
88
platforms: [
9-
.macOS(.v10_15), .iOS(.v13)
9+
.macOS(.v12), .iOS(.v13)
1010
],
1111
products: [
1212
.library(name: "web3swift", targets: ["web3swift"])
1313
],
1414
dependencies: [
1515
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
16-
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.5.1")
16+
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.5.1"),
17+
// .package(url: "https://github.com/realm/SwiftLint", branch: "main")
1718
],
1819
targets: [
1920
.target(name: "secp256k1"),
2021
.target(
2122
name: "Web3Core",
22-
dependencies: ["BigInt", "secp256k1", "CryptoSwift"]
23+
dependencies: ["BigInt", "secp256k1", "CryptoSwift"]//,
24+
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
2325
),
2426
.target(
2527
name: "web3swift",
@@ -28,7 +30,8 @@ let package = Package(
2830
.copy("./Browser/browser.js"),
2931
.copy("./Browser/browser.min.js"),
3032
.copy("./Browser/wk.bridge.min.js")
31-
]
33+
]//,
34+
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
3235
),
3336
.testTarget(
3437
name: "localTests",

Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extension APIRequest {
3939
throw Web3Error.nodeError(desc: "\(error.message)\nError code: \(error.code)")
4040
}
4141
let description = "\(parsedErrorCode.errorName). Error code: \(error.code). \(error.message)"
42+
print(description)
4243
switch parsedErrorCode {
4344
case .parseError, .invalidParams:
4445
throw Web3Error.inputError(desc: description)

Sources/Web3Core/EthereumNetwork/Utility/Async+BackwardCapability.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Foundation
99

1010
@available(iOS, obsoleted: 15.0, message: "Use the built-in API instead")
11-
@available(macOS, obsoleted: 12.0, message: "Use the built-in API instead")
1211
extension URLSession {
1312
func data(for request: URLRequest) async throws -> (Data, HTTPURLResponse) {
1413
try await withCheckedThrowingContinuation { continuation in

Sources/web3swift/Utils/ENS/ENSRegistry.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public extension ENS {
6565
return Resolver(web3: self.web3, resolverContractAddress: resolverAddress)
6666
}
6767

68+
let hexCharacters: [Character] = Array("0123456789abcdef")
69+
70+
func hexlify(_ value: Data) -> String {
71+
var result = "0x"
72+
for byte in value {
73+
result += "\(hexCharacters[Int(byte / 16)])\(hexCharacters[Int(byte % 16)])"
74+
}
75+
return result
76+
}
77+
6878
public func getTTL(node: String) async throws -> BigUInt {
6979
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
7080

Tests/web3swiftTests/localTests/UncategorizedTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ class UncategorizedTests: XCTestCase {
5151
XCTAssert(biguint == BigUInt("126978086000000000"))
5252
}
5353

54+
func testStringSplit() {
55+
XCTAssertEqual("abcdefgh".split(every: 3), ["abc", "def", "gh"])
56+
XCTAssertEqual("abcdefgh".split(every: 3, backwards: true), ["ab", "cde", "fgh"])
57+
58+
XCTAssertEqual("abcdefgh".split(every: 10), ["abcdefgh"])
59+
XCTAssertEqual("".split(every: 3), [])
60+
61+
XCTAssertEqual("abcdefgh".split(every: 1), ["a", "b", "c", "d", "e", "f", "g", "h"])
62+
XCTAssertEqual("abcdefgh".split(every: 1, backwards: true), ["a", "b", "c", "d", "e", "f", "g", "h"]) // should be the same as from the front
63+
}
64+
5465
func testBloom() throws {
5566
let positive = [
5667
"testtest",

0 commit comments

Comments
 (0)