Skip to content

Commit 629174c

Browse files
Fix EthereumTransaction decoding bug.
Fix appropriate test result for such Add test to check whether all transactions in block decodes well.
1 parent 92c7c15 commit 629174c

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Sources/web3swift/Web3/Web3+Structures.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ extension EthereumTransaction: Decodable {
8383
public init(from decoder: Decoder) throws {
8484
let options = try TransactionOptions(from: decoder)
8585
let container = try decoder.container(keyedBy: CodingKeys.self)
86-
87-
// test to see if it is a EIP-1559 wrapper
88-
if let envelope = try? container.decodeHex(BigUInt.self, forKey: .type) {
89-
// if present and non-sero we are a new wrapper we can't decode
90-
if envelope != BigInt(0) { throw Web3Error.dataError }
91-
}
9286

9387
if let data = try? container.decodeHex(Data.self, forKey: .data) {
9488
self.data = data

Tests/web3swiftTests/remoteTests/GasOracleTests.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class OracleTests: XCTestCase {
1515

1616
let web3 = Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
1717

18-
lazy var oracle: Web3.Oracle = .init(web3, block: .exact(14571792), blockCount: 20, percentiles: [10, 40, 60, 90])
18+
let blockNumber: BigUInt = 14571792
19+
20+
lazy var oracle: Web3.Oracle = .init(web3, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90])
1921

2022
func testPretictBaseFee() throws {
2123
let etalonPercentiles: [BigUInt] = [
@@ -64,13 +66,24 @@ class OracleTests: XCTestCase {
6466

6567
func testPredictLegacyGasPrice() throws {
6668
let etalonPercentiles: [BigUInt] = [
67-
100474449775, // 10 percentile
68-
114000000000, // 40 percentile
69-
125178275323, // 60 percentile
70-
146197706224 // 90 percentile
69+
93253857566, // 10 percentile
70+
106634912620, // 40 percentile
71+
111000000000, // 60 percentile
72+
127210686305 // 90 percentile
7173
]
7274

7375
let gasPriceLegacyPercentiles = oracle.gasPriceLegacyPercentiles
7476
XCTAssertEqual(gasPriceLegacyPercentiles, etalonPercentiles, "Arrays should be equal")
7577
}
78+
79+
func testAllTransactionInBlockDecodesWell() throws {
80+
let blockWithTransaction = try web3.eth.getBlockByNumber(blockNumber, fullTransactions: true)
81+
82+
let nullTransactions = blockWithTransaction.transactions.filter {
83+
guard case .null = $0 else { return false }
84+
return true
85+
}
86+
87+
XCTAssert(nullTransactions.isEmpty, "This amount transaction fails to decode: \(nullTransactions.count)")
88+
}
7689
}

0 commit comments

Comments
 (0)