Skip to content

Commit ab90bda

Browse files
authored
Merge pull request #1 from JeneaVranceanu/feat/decode-error
fix: decode error PR update
2 parents e66dd35 + 0ba7039 commit ab90bda

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

Sources/Web3Core/Contract/ContractProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ extension DefaultContractProtocol {
356356
throw Web3Error.inputError(desc: "Make sure ABI you use contains error that can match signature: 0x\(selector.toHexString())")
357357
}
358358
default:
359-
throw Web3Error.inputError(desc: "Invalid data count")
359+
throw Web3Error.inputError(desc: "Given data has invalid bytes count.")
360360
}
361361
}
362362

@@ -395,7 +395,7 @@ extension DefaultContractProtocol {
395395
@discardableResult
396396
public func callStatic(_ method: String, parameters: [Any], provider: Web3Provider) async throws -> [String: Any] {
397397
guard let address = address else {
398-
throw Web3Error.inputError(desc: "address field is missing")
398+
throw Web3Error.inputError(desc: "RPC failed: contract is missing an address.")
399399
}
400400
guard let data = self.method(method, parameters: parameters, extraData: nil) else {
401401
throw Web3Error.dataError

Sources/Web3Core/Utility/String+Extension.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,17 @@ extension String {
137137
}
138138

139139
public var isHex: Bool {
140-
stripHexPrefix().reduce(true, { $0 && $1.isHexDigit } )
140+
var _str = self.trim()
141+
if _str.isEmpty {
142+
return false
143+
}
144+
_str = _str.stripHexPrefix()
145+
for char in _str {
146+
if !char.isHexDigit {
147+
return false
148+
}
149+
}
150+
return true
141151
}
142152

143153
/// Splits a string into groups of `every` n characters, grouping from left-to-right by default. If `backwards` is true, right-to-left.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// String+ExtensionTests.swift
3+
//
4+
// Created by JeneaVranceanu on 26.11.2023.
5+
//
6+
7+
import Foundation
8+
import XCTest
9+
10+
class StringExtensionsTest: XCTestCase {
11+
12+
func testIsHex() throws {
13+
XCTAssertTrue("0x".isHex)
14+
XCTAssertTrue("0xF".isHex)
15+
XCTAssertTrue("F".isHex)
16+
XCTAssertTrue("0xFF".isHex)
17+
XCTAssertTrue("0x0123456789abcdefABCDEF".isHex)
18+
XCTAssertTrue("0123456789abcdefABCDEF".isHex)
19+
XCTAssertTrue("0123456789abcdefABCDEF ".isHex)
20+
XCTAssertTrue(" 0123456789abcdefABCDEF ".isHex)
21+
XCTAssertTrue(" 0123456789abcdefABCDEF".isHex)
22+
23+
XCTAssertFalse("".isHex)
24+
XCTAssertFalse("-".isHex)
25+
XCTAssertFalse("xyz".isHex)
26+
XCTAssertFalse("0xCAFEQ".isHex)
27+
XCTAssertFalse("R0123456789abcdefABCDEF ".isHex)
28+
XCTAssertFalse(" R0123456789abcdefABCDEF ".isHex)
29+
}
30+
31+
}

0 commit comments

Comments
 (0)