Skip to content

Commit ded3fee

Browse files
fix: swiftlint errors in Web3.swift
1 parent 5dcb100 commit ded3fee

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

Sources/web3swift/Web3/Web3.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ extension Web3 {
2121
}
2222

2323
/// Initialized Web3 instance bound to Infura's mainnet provider.
24-
public static func InfuraMainnetWeb3(accessToken: String? = nil) async -> Web3 {
25-
let infura = await InfuraProvider(Networks.Mainnet, accessToken: accessToken)!
24+
public static func InfuraMainnetWeb3(accessToken: String? = nil) async -> Web3? {
25+
guard let infura = await InfuraProvider(Networks.Mainnet, accessToken: accessToken) else { return nil }
2626
return Web3(provider: infura)
2727
}
2828

2929
/// Initialized Web3 instance bound to Infura's goerli provider.
30-
public static func InfuraGoerliWeb3(accessToken: String? = nil) async -> Web3 {
31-
let infura = await InfuraProvider(Networks.Goerli, accessToken: accessToken)!
30+
public static func InfuraGoerliWeb3(accessToken: String? = nil) async -> Web3? {
31+
guard let infura = await InfuraProvider(Networks.Goerli, accessToken: accessToken) else { return nil }
3232
return Web3(provider: infura)
3333
}
3434

3535
/// Initialized Web3 instance bound to Infura's rinkeby provider.
3636
@available(*, deprecated, message: "This network support was deprecated by Infura")
37-
public static func InfuraRinkebyWeb3(accessToken: String? = nil) async -> Web3 {
38-
let infura = await InfuraProvider(Networks.Rinkeby, accessToken: accessToken)!
37+
public static func InfuraRinkebyWeb3(accessToken: String? = nil) async -> Web3? {
38+
guard let infura = await InfuraProvider(Networks.Rinkeby, accessToken: accessToken) else { return nil }
3939
return Web3(provider: infura)
4040
}
4141

4242
/// Initialized Web3 instance bound to Infura's ropsten provider.
4343
@available(*, deprecated, message: "This network support was deprecated by Infura")
44-
public static func InfuraRopstenWeb3(accessToken: String? = nil) async -> Web3 {
45-
let infura = await InfuraProvider(Networks.Ropsten, accessToken: accessToken)!
44+
public static func InfuraRopstenWeb3(accessToken: String? = nil) async -> Web3? {
45+
guard let infura = await InfuraProvider(Networks.Ropsten, accessToken: accessToken) else { return nil }
4646
return Web3(provider: infura)
4747
}
4848

4949
/// Initialized Web3 instance bound to Infura's kovan provider.
5050
@available(*, deprecated, message: "This network support was deprecated by Infura")
51-
public static func InfuraKovanWeb3(accessToken: String? = nil) async -> Web3 {
52-
let infura = await InfuraProvider(Networks.Kovan, accessToken: accessToken)!
51+
public static func InfuraKovanWeb3(accessToken: String? = nil) async -> Web3? {
52+
guard let infura = await InfuraProvider(Networks.Kovan, accessToken: accessToken) else { return nil }
5353
return Web3(provider: infura)
5454
}
5555

Tests/web3swiftTests/localTests/EIP1559BlockTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import BigInt
44
@testable
55
import web3swift
66

7+
@testable
78
import Web3Core
89

910
class EIP1559BlockTests: LocalTestCase {

Tests/web3swiftTests/remoteTests/EIP1559Tests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ import Web3Core
1010

1111
@testable import web3swift
1212

13+
// swiftlint:disable force_unwrapping
1314
final class EIP1559Tests: XCTestCase {
1415

1516
func testEIP1159MainnetTransaction() async throws {
16-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
17+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
18+
else {
19+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
20+
return
21+
}
1722
var tx = CodableTransaction(
1823
type: .eip1559,
1924
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
@@ -29,7 +34,11 @@ final class EIP1559Tests: XCTestCase {
2934
}
3035

3136
func testEIP1159GoerliTransaction() async throws {
32-
let web3 = await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken)
37+
guard let web3 = await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken)
38+
else {
39+
XCTFail("Failed to connect to InfuraGoerli using token \(Constants.infuraToken)")
40+
return
41+
}
3342
var tx = CodableTransaction(
3443
type: .eip1559,
3544
to: EthereumAddress("0xeBec795c9c8bBD61FFc14A6662944748F299cAcf")!,

Tests/web3swiftTests/remoteTests/GasOracleTests.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ class GasOracleTests: XCTestCase {
1616
let blockNumber: BigUInt = 14571792
1717

1818
func testPretictBaseFee() async throws {
19-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
19+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
20+
else {
21+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
22+
return
23+
}
2024
lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90])
2125
let etalonPercentiles: [BigUInt] = [
2226
94217344703, // 10 percentile
@@ -30,7 +34,11 @@ class GasOracleTests: XCTestCase {
3034
}
3135

3236
func testPredictTip() async throws {
33-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
37+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
38+
else {
39+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
40+
return
41+
}
3442
lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90])
3543
let etalonPercentiles: [BigUInt] = [
3644
1217066957, // 10 percentile
@@ -44,7 +52,11 @@ class GasOracleTests: XCTestCase {
4452
}
4553

4654
func testPredictBothFee() async throws {
47-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
55+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
56+
else {
57+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
58+
return
59+
}
4860
lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90])
4961
let etalonPercentiles: ([BigUInt], [BigUInt]) = (
5062
baseFee: [

Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ import Web3Core
1111

1212
@testable import web3swift
1313

14+
// swiftlint:disable force_unwrapping
1415
final class PolicyResolverTests: XCTestCase {
1516

1617
func testResolveAllForEIP1159Transaction() async throws {
17-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
18+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
19+
else {
20+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
21+
return
22+
}
1823
let resolver = PolicyResolver(provider: web3.provider)
1924
var tx = CodableTransaction(
2025
type: .eip1559,
@@ -35,7 +40,11 @@ final class PolicyResolverTests: XCTestCase {
3540
}
3641

3742
func testResolveAllForLegacyTransaction() async throws {
38-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
43+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
44+
else {
45+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
46+
return
47+
}
3948
let resolver = PolicyResolver(provider: web3.provider)
4049
var tx = CodableTransaction(
4150
type: .legacy,
@@ -59,7 +68,11 @@ final class PolicyResolverTests: XCTestCase {
5968
let expectedGasLimit = BigUInt(22_000)
6069
let expectedBaseFee = BigUInt(20)
6170
let expectedPriorityFee = BigUInt(9)
62-
let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
71+
guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
72+
else {
73+
XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)")
74+
return
75+
}
6376
let resolver = PolicyResolver(provider: web3.provider)
6477
var tx = CodableTransaction(
6578
type: .eip1559,

0 commit comments

Comments
 (0)