diff --git a/Sources/web3swift/Web3/Web3+HttpProvider.swift b/Sources/web3swift/Web3/Web3+HttpProvider.swift index 29ad59831..a6411552d 100755 --- a/Sources/web3swift/Web3/Web3+HttpProvider.swift +++ b/Sources/web3swift/Web3/Web3+HttpProvider.swift @@ -18,9 +18,18 @@ public class Web3HttpProvider: Web3Provider { let urlSession = URLSession(configuration: config) return urlSession }() - public init?(_ httpProviderURL: URL, network net: Networks?, keystoreManager manager: KeystoreManager? = nil) async { - guard httpProviderURL.scheme == "http" || httpProviderURL.scheme == "https" else { return nil } - url = httpProviderURL + + @available(*, deprecated, message: "Will be removed in Web3Swift v4. Please use `init(url: URL, network: Networks?, keystoreManager: KeystoreManager?)` instead as it will throw an error instead of returning `nil` value.") + public convenience init?(_ httpProviderURL: URL, network net: Networks?, keystoreManager manager: KeystoreManager? = nil) async { + try? await self.init(url: httpProviderURL, network: net, keystoreManager: manager) + } + + public init(url: URL, network net: Networks?, keystoreManager manager: KeystoreManager? = nil) async throws { + guard url.scheme == "http" || url.scheme == "https" else { + throw Web3Error.inputError(desc: "Web3HttpProvider endpoint must have scheme http or https. Given scheme \(url.scheme ?? "none"). \(url.absoluteString)") + } + + self.url = url if let net = net { network = net } else { @@ -29,13 +38,8 @@ public class Web3HttpProvider: Web3Provider { urlRequest.setValue("application/json", forHTTPHeaderField: "Accept") urlRequest.httpMethod = APIRequest.getNetwork.call urlRequest.httpBody = APIRequest.getNetwork.encodedBody - do { - let response: APIResponse = try await APIRequest.send(uRLRequest: urlRequest, with: session) - let network = Networks.fromInt(response.result) - self.network = network - } catch { - return nil - } + let response: APIResponse = try await APIRequest.send(uRLRequest: urlRequest, with: session) + self.network = Networks.fromInt(response.result) } attachedKeystoreManager = manager } diff --git a/Sources/web3swift/Web3/Web3+InfuraProviders.swift b/Sources/web3swift/Web3/Web3+InfuraProviders.swift index 18e71d3ec..7d3d5040f 100755 --- a/Sources/web3swift/Web3/Web3+InfuraProviders.swift +++ b/Sources/web3swift/Web3/Web3+InfuraProviders.swift @@ -8,12 +8,18 @@ import Web3Core /// Custom Web3 HTTP provider of Infura nodes. public final class InfuraProvider: Web3HttpProvider { - public init?(_ net: Networks, accessToken token: String? = nil, keystoreManager manager: KeystoreManager? = nil) async { + + @available(*, deprecated, message: "Will be removed in Web3Swift v4. Please use `init(net: Networks, accessToken: String?, keystoreManager: KeystoreManager?)` instead as it will throw an error instead of returning `nil`.") + public convenience init?(_ net: Networks, accessToken token: String? = nil, keystoreManager manager: KeystoreManager? = nil) async { + try? await self.init(net: net, accessToken: token, keystoreManager: manager) + } + + public init(net: Networks, accessToken token: String? = nil, keystoreManager manager: KeystoreManager? = nil) async throws { var requestURLstring = "https://" + net.name + Constants.infuraHttpScheme requestURLstring += token ?? Constants.infuraToken guard let providerURL = URL(string: requestURLstring) else { - return nil + throw Web3Error.inputError(desc: "URL created with token \(token ?? "Default token - \(Constants.infuraToken)") is not a valid URL: \(requestURLstring)") } - await super.init(providerURL, network: net, keystoreManager: manager) + try await super.init(url: providerURL, network: net, keystoreManager: manager) } } diff --git a/Sources/web3swift/Web3/Web3.swift b/Sources/web3swift/Web3/Web3.swift index d5c543946..8b5dfc792 100755 --- a/Sources/web3swift/Web3/Web3.swift +++ b/Sources/web3swift/Web3/Web3.swift @@ -13,43 +13,40 @@ extension Web3 { /// Initialized provider-bound Web3 instance using a provider's URL. Under the hood it performs a synchronous call to get /// the Network ID for EIP155 purposes public static func new(_ providerURL: URL, network: Networks = .Mainnet) async throws -> Web3 { - // FIXME: Change this hardcoded value to dynamically fethed from a Node - guard let provider = await Web3HttpProvider(providerURL, network: network) else { - throw Web3Error.inputError(desc: "Wrong provider - should be Web3HttpProvider with endpoint scheme http or https") - } + let provider = try await Web3HttpProvider(url: providerURL, network: network) return Web3(provider: provider) } /// Initialized Web3 instance bound to Infura's mainnet provider. - public static func InfuraMainnetWeb3(accessToken: String? = nil) async -> Web3? { - guard let infura = await InfuraProvider(Networks.Mainnet, accessToken: accessToken) else { return nil } + public static func InfuraMainnetWeb3(accessToken: String? = nil) async throws -> Web3 { + let infura = try await InfuraProvider(net: Networks.Mainnet, accessToken: accessToken) return Web3(provider: infura) } /// Initialized Web3 instance bound to Infura's goerli provider. - public static func InfuraGoerliWeb3(accessToken: String? = nil) async -> Web3? { - guard let infura = await InfuraProvider(Networks.Goerli, accessToken: accessToken) else { return nil } + public static func InfuraGoerliWeb3(accessToken: String? = nil) async throws -> Web3 { + let infura = try await InfuraProvider(net: Networks.Goerli, accessToken: accessToken) return Web3(provider: infura) } /// Initialized Web3 instance bound to Infura's rinkeby provider. @available(*, deprecated, message: "This network support was deprecated by Infura") - public static func InfuraRinkebyWeb3(accessToken: String? = nil) async -> Web3? { - guard let infura = await InfuraProvider(Networks.Rinkeby, accessToken: accessToken) else { return nil } + public static func InfuraRinkebyWeb3(accessToken: String? = nil) async throws -> Web3 { + let infura = try await InfuraProvider(net: Networks.Rinkeby, accessToken: accessToken) return Web3(provider: infura) } /// Initialized Web3 instance bound to Infura's ropsten provider. @available(*, deprecated, message: "This network support was deprecated by Infura") - public static func InfuraRopstenWeb3(accessToken: String? = nil) async -> Web3? { - guard let infura = await InfuraProvider(Networks.Ropsten, accessToken: accessToken) else { return nil } + public static func InfuraRopstenWeb3(accessToken: String? = nil) async throws -> Web3 { + let infura = try await InfuraProvider(net: Networks.Ropsten, accessToken: accessToken) return Web3(provider: infura) } /// Initialized Web3 instance bound to Infura's kovan provider. @available(*, deprecated, message: "This network support was deprecated by Infura") - public static func InfuraKovanWeb3(accessToken: String? = nil) async -> Web3? { - guard let infura = await InfuraProvider(Networks.Kovan, accessToken: accessToken) else { return nil } + public static func InfuraKovanWeb3(accessToken: String? = nil) async throws -> Web3 { + let infura = try await InfuraProvider(net: Networks.Kovan, accessToken: accessToken) return Web3(provider: infura) } diff --git a/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift b/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift index ca30a8d94..ebf9193a1 100644 --- a/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift +++ b/Tests/web3swiftTests/localTests/ST20AndSecurityTokenTests.swift @@ -18,7 +18,7 @@ class ST20AndSecurityTokenTests: XCTestCase { var securityToken: SecurityToken! override func setUp() async throws { - web3 = await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken) + web3 = try await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken) ethMock = Web3EthMock(provider: web3.provider) web3.ethInstance = ethMock st20token = ST20.init(web3: web3, provider: web3.provider, address: .contractDeploymentAddress()) diff --git a/Tests/web3swiftTests/remoteTests/EIP1559Tests.swift b/Tests/web3swiftTests/remoteTests/EIP1559Tests.swift index e493edace..f1e0904c0 100644 --- a/Tests/web3swiftTests/remoteTests/EIP1559Tests.swift +++ b/Tests/web3swiftTests/remoteTests/EIP1559Tests.swift @@ -14,11 +14,7 @@ import Web3Core final class EIP1559Tests: XCTestCase { func testEIP1159MainnetTransaction() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) var tx = CodableTransaction( type: .eip1559, to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!, @@ -34,11 +30,7 @@ final class EIP1559Tests: XCTestCase { } func testEIP1159GoerliTransaction() async throws { - guard let web3 = await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraGoerli using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken) var tx = CodableTransaction( type: .eip1559, to: EthereumAddress("0xeBec795c9c8bBD61FFc14A6662944748F299cAcf")!, diff --git a/Tests/web3swiftTests/remoteTests/ENSTests.swift b/Tests/web3swiftTests/remoteTests/ENSTests.swift index 1a9872ccb..a21c5f848 100755 --- a/Tests/web3swiftTests/remoteTests/ENSTests.swift +++ b/Tests/web3swiftTests/remoteTests/ENSTests.swift @@ -23,11 +23,7 @@ class ENSTests: XCTestCase { } func testResolverAddress() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let address = try await ens?.registry.getResolver(forDomain: domain).resolverContractAddress @@ -36,11 +32,7 @@ class ENSTests: XCTestCase { } func testResolver() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let address = try await ens?.getAddress(forNode: domain) @@ -48,11 +40,7 @@ class ENSTests: XCTestCase { } func testSupportsInterface() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let resolver = try await ens?.registry.getResolver(forDomain: domain) @@ -67,11 +55,7 @@ class ENSTests: XCTestCase { } func testABI() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let resolver = try await ens?.registry.getResolver(forDomain: domain) @@ -86,11 +70,7 @@ class ENSTests: XCTestCase { } func testOwner() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let owner = try await ens?.registry.getOwner(node: domain) @@ -98,11 +78,7 @@ class ENSTests: XCTestCase { } func testTTL() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = try XCTUnwrap(ENS(web3: web3)) let domain = "somename.eth" let ttl = try await ens.registry.getTTL(node: domain) @@ -110,11 +86,7 @@ class ENSTests: XCTestCase { } func testGetAddress() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let resolver = try await ens?.registry.getResolver(forDomain: domain) @@ -123,11 +95,7 @@ class ENSTests: XCTestCase { } func testGetPubkey() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let ens = ENS(web3: web3) let domain = "somename.eth" let resolver = try await ens?.registry.getResolver(forDomain: domain) diff --git a/Tests/web3swiftTests/remoteTests/GasOracleTests.swift b/Tests/web3swiftTests/remoteTests/GasOracleTests.swift index 9b7769b82..89b782fb6 100644 --- a/Tests/web3swiftTests/remoteTests/GasOracleTests.swift +++ b/Tests/web3swiftTests/remoteTests/GasOracleTests.swift @@ -16,11 +16,7 @@ class GasOracleTests: XCTestCase { let blockNumber: BigUInt = 14571792 func testPretictBaseFee() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90]) let etalonPercentiles: [BigUInt] = [ 94217344703, // 10 percentile @@ -34,11 +30,7 @@ class GasOracleTests: XCTestCase { } func testPredictTip() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90]) let etalonPercentiles: [BigUInt] = [ 1217066957, // 10 percentile @@ -52,11 +44,7 @@ class GasOracleTests: XCTestCase { } func testPredictBothFee() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) lazy var oracle: Oracle = .init(web3.provider, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90]) let etalonPercentiles: ([BigUInt], [BigUInt]) = ( baseFee: [ @@ -79,7 +67,7 @@ class GasOracleTests: XCTestCase { } // func testPredictLegacyGasPrice() async throws { -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // lazy var oracle: Web3.Oracle = .init(web3, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90]) // let etalonPercentiles: [BigUInt] = [ // 93253857566, // 10 percentile @@ -93,7 +81,7 @@ class GasOracleTests: XCTestCase { // } // // func testAllTransactionInBlockDecodesWell() async throws { -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // lazy var oracle: Web3.Oracle = .init(web3, block: .exact(blockNumber), blockCount: 20, percentiles: [10, 40, 60, 90]) // let blockWithTransaction = try await web3.eth.getBlockByNumber(blockNumber, fullTransactions: true) // @@ -107,13 +95,13 @@ class GasOracleTests: XCTestCase { // FIXME: Move it to external test suit. // func testBlockNumber() async throws { -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let latestBlockNumber = try await web3.eth.getBlockNumber() // // } // // func testgetAccounts() async throws { -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let accounts = try await web3.eth.getAccounts() // // } diff --git a/Tests/web3swiftTests/remoteTests/InfuraTests.swift b/Tests/web3swiftTests/remoteTests/InfuraTests.swift index 8de339cdd..8f5b04af2 100755 --- a/Tests/web3swiftTests/remoteTests/InfuraTests.swift +++ b/Tests/web3swiftTests/remoteTests/InfuraTests.swift @@ -12,11 +12,7 @@ import Web3Core class InfuraTests: XCTestCase { func testGetBalance() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let address = EthereumAddress("0xd61b5ca425F8C8775882d4defefC68A6979DBbce")! let balance = try await web3.eth.getBalance(for: address) let balString = Utilities.formatToPrecision(balance, units: .ether, formattingDecimals: 3) @@ -24,50 +20,30 @@ class InfuraTests: XCTestCase { } func testGetBlockByHash() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let result = try await web3.eth.block(by: "0x6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695", fullTransactions: false) XCTAssertEqual(result.number, 5184323) } func testGetBlockByHash_hashAsData() async throws { let blockHash = Data.fromHex("6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695")! - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let result = try await web3.eth.block(by: blockHash, fullTransactions: false) XCTAssertEqual(result.number, 5184323) } func testGetBlockByNumber1() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) _ = try await web3.eth.block(by: .latest, fullTransactions: false) } func testGetBlockByNumber2() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) _ = try await web3.eth.block(by: .exact(5184323), fullTransactions: true) } - func testGetBlockByNumber3() async { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + func testGetBlockByNumber3() async throws { + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) do { _ = try await web3.eth.block(by: .exact(10000000000000), fullTransactions: true) XCTFail("The expression above must throw DecodingError.") @@ -78,17 +54,13 @@ class InfuraTests: XCTestCase { } func testGasPrice() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) _ = try await web3.eth.gasPrice() } // func testGetIndexedEventsPromise() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let contract = web3.contract(jsonString, at: nil, abiVersion: 2) // var filter = EventFilterParameters() // filter.fromBlock = .exact(5200120) diff --git a/Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift b/Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift index 84db3b8df..8f92327f7 100644 --- a/Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift +++ b/Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift @@ -15,11 +15,7 @@ import Web3Core final class PolicyResolverTests: XCTestCase { func testResolveAllForEIP1159Transaction() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let resolver = PolicyResolver(provider: web3.provider) var tx = CodableTransaction( type: .eip1559, @@ -40,11 +36,7 @@ final class PolicyResolverTests: XCTestCase { } func testResolveAllForLegacyTransaction() async throws { - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let resolver = PolicyResolver(provider: web3.provider) var tx = CodableTransaction( type: .legacy, @@ -68,11 +60,7 @@ final class PolicyResolverTests: XCTestCase { let expectedGasLimit = BigUInt(22_000) let expectedBaseFee = BigUInt(20) let expectedPriorityFee = BigUInt(9) - guard let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) - else { - XCTFail("Failed to connect to InfuraMainnet using token \(Constants.infuraToken)") - return - } + let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) let resolver = PolicyResolver(provider: web3.provider) var tx = CodableTransaction( type: .eip1559, diff --git a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift index b4b272b20..7f3ad7c82 100755 --- a/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift +++ b/Tests/web3swiftTests/remoteTests/RemoteParsingTests.swift @@ -91,7 +91,7 @@ class RemoteParsingTests: XCTestCase { // func testEventParsing5usingABIv2() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let contract = web3.contract(jsonString, at: nil, abiVersion: 2) // var filter = EventFilter() // filter.fromBlock = .exact(5200120) @@ -104,7 +104,7 @@ class RemoteParsingTests: XCTestCase { // func testEventParsing6usingABIv2() async throws { // let jsonString = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialAmount\",\"type\":\"uint256\"},{\"name\":\"_tokenName\",\"type\":\"string\"},{\"name\":\"_decimalUnits\",\"type\":\"uint8\"},{\"name\":\"_tokenSymbol\",\"type\":\"string\"}],\"type\":\"constructor\"},{\"payable\":false,\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},]" -// let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) +// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) // let contract = web3.contract(jsonString, at: nil, abiVersion: 2) // var filter = EventFilter() // filter.fromBlock = .exact(5200120)