Skip to content

Commit 8cb9a20

Browse files
Merge pull request #783 from albertopeam/feature/transaction-description-add-from
Minor: description of transaction doesn't return from
2 parents 69b52b2 + 43f1e9a commit 8cb9a20

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ 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+
44+
XCTAssertTrue(sut.contains("EthereumAddress\n"))
45+
XCTAssertTrue(sut.contains("type: normal\n"))
46+
XCTAssertTrue(sut.contains("address: 0x200EB5cCdA1c35B0F5Bf82552FDD65a8AEe98E79"))
47+
}
3848
}

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: Optional(EthereumAddress\ntype: normal\naddress: 0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F\n)\n"))
604+
XCTAssertTrue(sut.contains(#"hash: Optional("0x41dc0cd9b133e0d4e47e269988b0109c966db5220d57e2a7f3cdc6c2f8de6a72")"#))
605+
}
606+
595607
// ***** Legacy Tests *****
596608
// TODO: Replace `XCTAssert` with more explicit `XCTAssertEqual`, where Applicable
597609

0 commit comments

Comments
 (0)