Skip to content

Commit 39ea368

Browse files
committed
changed XCTAssert to XCTAssertEqual, and added failure messages
1 parent 3c98992 commit 39ea368

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

Tests/web3swiftTests/localTests/web3swiftTransactionsTests.swift

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ class web3swiftTransactionsTests: XCTestCase {
189189
do {
190190
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
191191
// check that the transaction type is legacy
192-
XCTAssert(jsonTxn.type == .legacy)
192+
XCTAssertEqual(jsonTxn.type, .legacy, "Transaction Type Mismatch")
193193
// check the hash, if they match everything was parsed, and re-encoded correctly
194-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
194+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
195195
// check that we recovered the address correctly
196-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
196+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
197197
} catch {
198198
print(error)
199199
return XCTFail(String(describing: error))
@@ -211,11 +211,11 @@ class web3swiftTransactionsTests: XCTestCase {
211211
return XCTFail("Decoding RLP encoded transaction failed")
212212
}
213213
// check that the transaction type is legacy
214-
XCTAssert(rlpTxn.type == .legacy)
214+
XCTAssertEqual(rlpTxn.type, .legacy, "Transaction Type Mismatch")
215215
// check the hash, if they match everything was parsed, and re-encoded correctly
216-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
216+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
217217
// check that we recovered the address correctly
218-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
218+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
219219
}
220220

221221
// test signing a fallback legacy transaction (chainId not part of the signing process)
@@ -237,11 +237,11 @@ class web3swiftTransactionsTests: XCTestCase {
237237
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
238238

239239
// check the hash, if they match everything was parsed, and re-encoded correctly
240-
XCTAssert(rawTxn == vector.RLP)
240+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
241241
// check the hash, if they match everything was parsed, and re-encoded correctly
242-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
242+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
243243
// check that we recovered the address correctly
244-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
244+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
245245
} catch {
246246
print(error)
247247
return XCTFail(String(describing: error))
@@ -258,11 +258,11 @@ class web3swiftTransactionsTests: XCTestCase {
258258
do {
259259
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
260260
// check that the transaction type is legacy
261-
XCTAssert(jsonTxn.type == .legacy)
261+
XCTAssertEqual(jsonTxn.type, .legacy, "Transaction Type Mismatch")
262262
// check the hash, if they match everything was parsed, and re-encoded correctly
263-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
263+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
264264
// check that we recovered the address correctly
265-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
265+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
266266
} catch {
267267
print(error)
268268
return XCTFail(String(describing: error))
@@ -280,11 +280,11 @@ class web3swiftTransactionsTests: XCTestCase {
280280
return XCTFail("Decoding RLP encoded transaction failed")
281281
}
282282
// check that the transaction type is legacy
283-
XCTAssert(rlpTxn.type == .legacy)
283+
XCTAssertEqual(rlpTxn.type, .legacy, "Transaction Type Mismatch")
284284
// check the hash, if they match everything was parsed, and re-encoded correctly
285-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
285+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
286286
// check that we recovered the address correctly
287-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
287+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
288288
}
289289

290290
// test signing a normal legacy transaction conforming to EIP155
@@ -306,11 +306,11 @@ class web3swiftTransactionsTests: XCTestCase {
306306
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
307307

308308
// check the hash, if they match everything was parsed, and re-encoded correctly
309-
XCTAssert(rawTxn == vector.RLP)
309+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
310310
// check the hash, if they match everything was parsed, and re-encoded correctly
311-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
311+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
312312
// check that we recovered the address correctly
313-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
313+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
314314
} catch {
315315
print(error)
316316
return XCTFail(String(describing: error))
@@ -327,11 +327,11 @@ class web3swiftTransactionsTests: XCTestCase {
327327
do {
328328
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
329329
// check that the transaction type is eip2930
330-
XCTAssert(jsonTxn.type == .eip2930)
330+
XCTAssertEqual(jsonTxn.type, .eip2930, "Transaction Type Mismatch")
331331
// check the hash, if they match everything was parsed, and re-encoded correctly
332-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
332+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
333333
// check that we recovered the address correctly
334-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
334+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
335335
} catch {
336336
print(error)
337337
return XCTFail(String(describing: error))
@@ -349,11 +349,11 @@ class web3swiftTransactionsTests: XCTestCase {
349349
return XCTFail("Decoding RLP encoded transaction failed")
350350
}
351351
// check that the transaction type is eip2930
352-
XCTAssert(rlpTxn.type == .eip2930)
352+
XCTAssertEqual(rlpTxn.type, .eip2930, "Transaction Type Mismatch")
353353
// check the hash, if they match everything was parsed, and re-encoded correctly
354-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
354+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
355355
// check that we recovered the address correctly
356-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
356+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
357357
}
358358

359359
// test signing a EIP-2930 transaction (without accessList)
@@ -375,11 +375,11 @@ class web3swiftTransactionsTests: XCTestCase {
375375
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
376376

377377
// check the hash, if they match everything was parsed, and re-encoded correctly
378-
XCTAssert(rawTxn == vector.RLP)
378+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
379379
// check the hash, if they match everything was parsed, and re-encoded correctly
380-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
380+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
381381
// check that we recovered the address correctly
382-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
382+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
383383
} catch {
384384
print(error)
385385
return XCTFail(String(describing: error))
@@ -396,11 +396,11 @@ class web3swiftTransactionsTests: XCTestCase {
396396
do {
397397
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
398398
// check that the transaction type is eip2930
399-
XCTAssert(jsonTxn.type == .eip2930)
399+
XCTAssertEqual(jsonTxn.type, .eip2930, "Transaction Type Mismatch")
400400
// check the hash, if they match everything was parsed, and re-encoded correctly
401-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
401+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
402402
// check that we recovered the address correctly
403-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
403+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
404404
} catch {
405405
print(error)
406406
return XCTFail(String(describing: error))
@@ -418,11 +418,11 @@ class web3swiftTransactionsTests: XCTestCase {
418418
return XCTFail("Decoding RLP encoded transaction failed")
419419
}
420420
// check that the transaction type is eip2930
421-
XCTAssert(rlpTxn.type == .eip2930)
421+
XCTAssertEqual(rlpTxn.type, .eip2930, "Transaction Type Mismatch")
422422
// check the hash, if they match everything was parsed, and re-encoded correctly
423-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
423+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
424424
// check that we recovered the address correctly
425-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
425+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
426426
}
427427

428428
// test signing a EIP-2930 transaction (with accessList)
@@ -444,11 +444,11 @@ class web3swiftTransactionsTests: XCTestCase {
444444
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
445445

446446
// check the hash, if they match everything was parsed, and re-encoded correctly
447-
XCTAssert(rawTxn == vector.RLP)
447+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
448448
// check the hash, if they match everything was parsed, and re-encoded correctly
449-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
449+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
450450
// check that we recovered the address correctly
451-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
451+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
452452
} catch {
453453
print(error)
454454
return XCTFail(String(describing: error))
@@ -465,11 +465,11 @@ class web3swiftTransactionsTests: XCTestCase {
465465
do {
466466
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
467467
// check that the transaction type is eip1559
468-
XCTAssert(jsonTxn.type == .eip1559)
468+
XCTAssertEqual(jsonTxn.type, .eip1559, "Transaction Type Mismatch")
469469
// check the hash, if they match everything was parsed, and re-encoded correctly
470-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
470+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
471471
// check that we recovered the address correctly
472-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
472+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
473473
} catch {
474474
print(error)
475475
return XCTFail(String(describing: error))
@@ -487,11 +487,11 @@ class web3swiftTransactionsTests: XCTestCase {
487487
return XCTFail("Decoding RLP encoded transaction failed")
488488
}
489489
// check that the transaction type is eip1559
490-
XCTAssert(rlpTxn.type == .eip1559)
490+
XCTAssertEqual(rlpTxn.type, .eip1559, "Transaction Type Mismatch")
491491
// check the hash, if they match everything was parsed, and re-encoded correctly
492-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
492+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
493493
// check that we recovered the address correctly
494-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
494+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
495495
}
496496

497497
// test signing a EIP-1559 transaction (without accessList)
@@ -513,11 +513,11 @@ class web3swiftTransactionsTests: XCTestCase {
513513
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
514514

515515
// check the hash, if they match everything was parsed, and re-encoded correctly
516-
XCTAssert(rawTxn == vector.RLP)
516+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
517517
// check the hash, if they match everything was parsed, and re-encoded correctly
518-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
518+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
519519
// check that we recovered the address correctly
520-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
520+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
521521
} catch {
522522
print(error)
523523
return XCTFail(String(describing: error))
@@ -534,11 +534,11 @@ class web3swiftTransactionsTests: XCTestCase {
534534
do {
535535
let jsonTxn: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
536536
// check that the transaction type is eip1559
537-
XCTAssert(jsonTxn.type == .eip1559)
537+
XCTAssertEqual(jsonTxn.type, .eip1559, "Transaction Type Mismatch")
538538
// check the hash, if they match everything was parsed, and re-encoded correctly
539-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
539+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
540540
// check that we recovered the address correctly
541-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
541+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
542542
} catch {
543543
print(error)
544544
return XCTFail(String(describing: error))
@@ -556,11 +556,11 @@ class web3swiftTransactionsTests: XCTestCase {
556556
return XCTFail("Decoding RLP encoded transaction failed")
557557
}
558558
// check that the transaction type is eip1559
559-
XCTAssert(rlpTxn.type == .eip1559)
559+
XCTAssertEqual(rlpTxn.type, .eip1559, "Transaction Type Mismatch")
560560
// check the hash, if they match everything was parsed, and re-encoded correctly
561-
XCTAssert(rlpTxn.hash!.toHexString().addHexPrefix() == vector.hash)
561+
XCTAssertEqual(rlpTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
562562
// check that we recovered the address correctly
563-
XCTAssert(rlpTxn.sender!.address == expectedAddress.address)
563+
XCTAssertEqual(rlpTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
564564
}
565565

566566
// test signing a EIP-1559 transaction (with accessList)
@@ -582,18 +582,19 @@ class web3swiftTransactionsTests: XCTestCase {
582582
let rawTxn = jsonTxn.encode()!.toHexString().addHexPrefix()
583583

584584
// check the hash, if they match everything was parsed, and re-encoded correctly
585-
XCTAssert(rawTxn == vector.RLP)
585+
XCTAssertEqual(rawTxn, vector.RLP, "Transaction Encoding Mismatch")
586586
// check the hash, if they match everything was parsed, and re-encoded correctly
587-
XCTAssert(jsonTxn.hash!.toHexString().addHexPrefix() == vector.hash)
587+
XCTAssertEqual(jsonTxn.hash!.toHexString().addHexPrefix(), vector.hash, "Transaction Hash Mismatch")
588588
// check that we recovered the address correctly
589-
XCTAssert(jsonTxn.sender!.address == expectedAddress.address)
589+
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
590590
} catch {
591591
print(error)
592592
return XCTFail(String(describing: error))
593593
}
594594
}
595595

596596
// ***** Legacy Tests *****
597+
// TODO: Replace `XCTAssert` with more explicite `XCTAssertEqual`, where Applicable
597598

598599
func testDirectTransaction() throws {
599600
do {

0 commit comments

Comments
 (0)