Skip to content

Commit

Permalink
add string spit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pharms-eth committed Aug 29, 2023
1 parent c0e06d5 commit e8a5e2b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
11 changes: 7 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import PackageDescription
let package = Package(
name: "Web3swift",
platforms: [
.macOS(.v10_15), .iOS(.v13)
.macOS(.v12), .iOS(.v13)
],
products: [
.library(name: "web3swift", targets: ["web3swift"])
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.5.1")
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.5.1"),
// .package(url: "https://github.com/realm/SwiftLint", branch: "main")
],
targets: [
.target(name: "secp256k1"),
.target(
name: "Web3Core",
dependencies: ["BigInt", "secp256k1", "CryptoSwift"]
dependencies: ["BigInt", "secp256k1", "CryptoSwift"]//,
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
),
.target(
name: "web3swift",
Expand All @@ -28,7 +30,8 @@ let package = Package(
.copy("./Browser/browser.js"),
.copy("./Browser/browser.min.js"),
.copy("./Browser/wk.bridge.min.js")
]
]//,
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
),
.testTarget(
name: "localTests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension APIRequest {
throw Web3Error.nodeError(desc: "\(error.message)\nError code: \(error.code)")
}
let description = "\(parsedErrorCode.errorName). Error code: \(error.code). \(error.message)"
print(description)
switch parsedErrorCode {
case .parseError, .invalidParams:
throw Web3Error.inputError(desc: description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation

@available(iOS, obsoleted: 15.0, message: "Use the built-in API instead")
@available(macOS, obsoleted: 12.0, message: "Use the built-in API instead")
extension URLSession {
func data(for request: URLRequest) async throws -> (Data, HTTPURLResponse) {
try await withCheckedThrowingContinuation { continuation in
Expand Down
10 changes: 10 additions & 0 deletions Sources/web3swift/Utils/ENS/ENSRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public extension ENS {
return Resolver(web3: self.web3, resolverContractAddress: resolverAddress)
}

let hexCharacters: [Character] = Array("0123456789abcdef")

func hexlify(_ value: Data) -> String {
var result = "0x"
for byte in value {
result += "\(hexCharacters[Int(byte / 16)])\(hexCharacters[Int(byte % 16)])"
}
return result
}

public func getTTL(node: String) async throws -> BigUInt {
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}

Expand Down
11 changes: 11 additions & 0 deletions Tests/web3swiftTests/localTests/UncategorizedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ class UncategorizedTests: XCTestCase {
XCTAssert(biguint == BigUInt("126978086000000000"))
}

func testStringSplit() {
XCTAssertEqual("abcdefgh".split(every: 3), ["abc", "def", "gh"])
XCTAssertEqual("abcdefgh".split(every: 3, backwards: true), ["ab", "cde", "fgh"])

XCTAssertEqual("abcdefgh".split(every: 10), ["abcdefgh"])
XCTAssertEqual("".split(every: 3), [])

XCTAssertEqual("abcdefgh".split(every: 1), ["a", "b", "c", "d", "e", "f", "g", "h"])
XCTAssertEqual("abcdefgh".split(every: 1, backwards: true), ["a", "b", "c", "d", "e", "f", "g", "h"]) // should be the same as from the front
}

func testBloom() throws {
let positive = [
"testtest",
Expand Down

0 comments on commit e8a5e2b

Please sign in to comment.