Skip to content

Commit 58c12c3

Browse files
committed
added EthereumAddress conformance to CustomStringConvertible. added sender to CustomStringConvertible for CodableTransaction
1 parent 763f307 commit 58c12c3

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Sources/Web3Core/EthereumAddress/EthereumAddress.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,16 @@ extension EthereumAddress: Codable {
155155
extension EthereumAddress: Hashable { }
156156

157157
extension EthereumAddress: APIResultType { }
158+
159+
// MARK: - CustomStringConvertible
160+
161+
extension EthereumAddress: CustomStringConvertible {
162+
/// Used when converting an instance to a string
163+
public var description: String {
164+
var toReturn = ""
165+
toReturn += "EthereumAddress" + "\n"
166+
toReturn += "type: " + String(describing: type) + "\n"
167+
toReturn += "address: " + String(describing: address) + "\n"
168+
return toReturn
169+
}
170+
}

Sources/Web3Core/Transaction/CodableTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ extension CodableTransaction: CustomStringConvertible {
271271
var toReturn = ""
272272
toReturn += "Transaction" + "\n"
273273
toReturn += String(describing: self.envelope)
274-
toReturn += "from: " + String(describing: self.sender?.address) + "\n"
274+
toReturn += "from: " + String(describing: self.sender) + "\n"
275275
toReturn += "hash: " + String(describing: self.hash?.toHexString().addHexPrefix()) + "\n"
276276
return toReturn
277277
}

Tests/web3swiftTests/localTests/EthereumAddressTest.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// EthereumAddressTest.swift
3-
//
3+
//
44
//
55
// Created by JeneaVranceanu on 03.02.2023.
66
//
@@ -35,4 +35,15 @@ class EthereumAddressTest: XCTestCase {
3535
XCTAssertNil(ethereumAddress)
3636
}
3737

38+
func testDescription() async throws {
39+
let rawAddress = "0x200eb5ccda1c35b0f5bf82552fdd65a8aee98e79"
40+
let ethereumAddress = EthereumAddress(rawAddress)
41+
42+
let sut = String(describing: ethereumAddress)
43+
print(sut)
44+
45+
XCTAssertTrue(sut.contains("EthereumAddress\n"))
46+
XCTAssertTrue(sut.contains("type: normal\n"))
47+
XCTAssertTrue(sut.contains("address: 0x"))
48+
}
3849
}

Tests/web3swiftTests/localTests/TransactionsTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,18 @@ class TransactionsTests: XCTestCase {
592592
}
593593
}
594594

595+
func testDescription() async throws {
596+
let vector = testVector[TestCase.eip1559.rawValue]
597+
let jsonData = try XCTUnwrap(vector.JSON.data(using: .utf8))
598+
let txn = try JSONDecoder().decode(CodableTransaction.self, from: jsonData)
599+
600+
let sut = String(describing: txn)
601+
602+
XCTAssertTrue(sut.contains("Transaction"))
603+
XCTAssertTrue(sut.contains("from: "))
604+
XCTAssertTrue(sut.contains("hash: "))
605+
}
606+
595607
// ***** Legacy Tests *****
596608
// TODO: Replace `XCTAssert` with more explicit `XCTAssertEqual`, where Applicable
597609

0 commit comments

Comments
 (0)