Skip to content

Commit 812bd13

Browse files
Add tests Gas Oracle
1 parent 88abb45 commit 812bd13

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

Sources/web3swift/Web3/Web3+GasOracle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension Web3 {
4141

4242
private func calcBaseFee(for block: Block?) -> BigUInt {
4343
guard let block = block else { return 0 }
44-
return Web3.calcBaseFee(block)
44+
return Web3.calcBaseFee(block) ?? 0
4545
}
4646

4747
private func calculateStatistic(for statistic: Statistic, data: [BigUInt]) throws -> BigUInt {
@@ -97,7 +97,7 @@ extension Web3 {
9797
let lastNthBlocksBaseFees = try (latestBlockNumber - blockCount ... latestBlockNumber)
9898
.map { try eth.getBlockByNumber($0) }
9999
.filter { !$0.transactions.isEmpty }
100-
.map { $0.baseFeePerGas }
100+
.compactMap { $0.baseFeePerGas }
101101

102102
return try calculateStatistic(for: statistic, data: lastNthBlocksBaseFees)
103103
}

Tests/web3swiftTests/localTests/LocalTests.xctestplan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"skippedTests" : [
1717
"ENSTests",
1818
"RemoteTests",
19+
"GasOracleTests",
20+
"InfuraTests",
1921
"RemoteParsingTests",
2022
"ST20AndSecurityTokenTests",
2123
"WebsocketTests",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// OracleTests.swift
3+
// Web3swift
4+
//
5+
// Created by Yaroslav on 11.04.2022.
6+
//
7+
8+
import XCTest
9+
10+
@testable import web3swift
11+
12+
// MARK: Works only with network connection
13+
class OracleTests: XCTestCase {
14+
15+
func testPretictBaseFee() throws {
16+
17+
}
18+
19+
func testPredictTip() throws {
20+
21+
}
22+
23+
func testPredictGasPrice() throws {
24+
25+
}
26+
}

web3swift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@
169169
5C03EAB4274405D20052C66D /* EIP712.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB50A52927060C5300D7E39B /* EIP712.swift */; };
170170
5C26D89E27F3724600431EB0 /* Web3+EIP1559.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C26D89D27F3724600431EB0 /* Web3+EIP1559.swift */; };
171171
5C26D8A027F3725500431EB0 /* EIP1559BlockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C26D89F27F3725500431EB0 /* EIP1559BlockTests.swift */; };
172+
5C26D8A227F5AC0300431EB0 /* Web3+GasOracle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C26D8A127F5AC0300431EB0 /* Web3+GasOracle.swift */; };
172173
5CC0333828023387006AD710 /* RemoteParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0333328023387006AD710 /* RemoteParsingTests.swift */; };
173174
5CC0333928023387006AD710 /* ENSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0333428023387006AD710 /* ENSTests.swift */; };
174175
5CC0333A28023387006AD710 /* ST20AndSecurityTokenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0333528023387006AD710 /* ST20AndSecurityTokenTests.swift */; };
175176
5CC0333B28023387006AD710 /* WebsocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0333628023387006AD710 /* WebsocketTests.swift */; };
176177
5CC0333E28034CED006AD710 /* InfuraTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0333D28034CED006AD710 /* InfuraTests.swift */; };
177-
5C26D8A227F5AC0300431EB0 /* Web3+GasOracle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C26D8A127F5AC0300431EB0 /* Web3+GasOracle.swift */; };
178+
5CC0334228043805006AD710 /* GasOracleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC0334128043805006AD710 /* GasOracleTests.swift */; };
178179
5CF7E8A2276B79290009900F /* web3swiftEIP681Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E891276B79270009900F /* web3swiftEIP681Tests.swift */; };
179180
5CF7E8A3276B792A0009900F /* web3swiftPersonalSignatureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E892276B79270009900F /* web3swiftPersonalSignatureTests.swift */; };
180181
5CF7E8A4276B792A0009900F /* web3swiftTransactionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E893276B79270009900F /* web3swiftTransactionsTests.swift */; };
@@ -388,12 +389,13 @@
388389
4E2DFEF325485B53001AF561 /* KeystoreParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeystoreParams.swift; sourceTree = "<group>"; };
389390
5C26D89D27F3724600431EB0 /* Web3+EIP1559.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+EIP1559.swift"; sourceTree = "<group>"; };
390391
5C26D89F27F3725500431EB0 /* EIP1559BlockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP1559BlockTests.swift; sourceTree = "<group>"; };
392+
5C26D8A127F5AC0300431EB0 /* Web3+GasOracle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+GasOracle.swift"; sourceTree = "<group>"; };
391393
5CC0333328023387006AD710 /* RemoteParsingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteParsingTests.swift; sourceTree = "<group>"; };
392394
5CC0333428023387006AD710 /* ENSTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ENSTests.swift; sourceTree = "<group>"; };
393395
5CC0333528023387006AD710 /* ST20AndSecurityTokenTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ST20AndSecurityTokenTests.swift; sourceTree = "<group>"; };
394396
5CC0333628023387006AD710 /* WebsocketTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebsocketTests.swift; sourceTree = "<group>"; };
395397
5CC0333D28034CED006AD710 /* InfuraTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfuraTests.swift; sourceTree = "<group>"; };
396-
5C26D8A127F5AC0300431EB0 /* Web3+GasOracle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+GasOracle.swift"; sourceTree = "<group>"; };
398+
5CC0334128043805006AD710 /* GasOracleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GasOracleTests.swift; sourceTree = "<group>"; };
397399
5CDEF972275A74590004A2F2 /* web3swift.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = web3swift.xctestplan; path = Tests/web3swiftTests/web3swift.xctestplan; sourceTree = SOURCE_ROOT; };
398400
5CDEF973275A74670004A2F2 /* LocalTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = LocalTests.xctestplan; sourceTree = "<group>"; };
399401
5CDEF974275A747B0004A2F2 /* RemoteTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = RemoteTests.xctestplan; sourceTree = "<group>"; };
@@ -981,6 +983,7 @@
981983
E252E68026B40C1600717C16 /* remoteTests */ = {
982984
isa = PBXGroup;
983985
children = (
986+
5CC0334128043805006AD710 /* GasOracleTests.swift */,
984987
5CC0333428023387006AD710 /* ENSTests.swift */,
985988
5CC0333D28034CED006AD710 /* InfuraTests.swift */,
986989
5CC0333328023387006AD710 /* RemoteParsingTests.swift */,
@@ -1403,6 +1406,7 @@
14031406
CB50A52827060BD600D7E39B /* EIP712Tests.swift in Sources */,
14041407
5CF7E8AD276B792A0009900F /* web3swiftBasicLocalNodeTests.swift in Sources */,
14051408
5CC0333E28034CED006AD710 /* InfuraTests.swift in Sources */,
1409+
5CC0334228043805006AD710 /* GasOracleTests.swift in Sources */,
14061410
5CC0333928023387006AD710 /* ENSTests.swift in Sources */,
14071411
5CF7E8A9276B792A0009900F /* web3swiftERC20ClassTests.swift in Sources */,
14081412
5CF7E8A8276B792A0009900F /* web3swiftERC20Tests.swift in Sources */,

0 commit comments

Comments
 (0)