Skip to content

Commit

Permalink
Broken remote tests disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavyaroslav committed Dec 28, 2024
1 parent 6e989aa commit 32a82bf
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 100 deletions.
34 changes: 16 additions & 18 deletions Tests/web3swiftTests/remoteTests/EIP1559Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,13 @@ import Web3Core

// swiftlint:disable force_unwrapping
final class EIP1559Tests: XCTestCase {

func testEIP1159MainnetTransaction() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
var tx = CodableTransaction(
var tx = try CodableTransaction(
type: .eip1559,
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
chainID: web3.provider.network!.chainID,
value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
)
// Vitalik's address
tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
// Should fail if there would be something wrong with the tx
let res = try await web3.eth.estimateGas(for: tx)
XCTAssertGreaterThan(res, 0)
}

func testEIP1159GoerliTransaction() async throws {
let web3 = try await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken)
var tx = CodableTransaction(
type: .eip1559,
to: EthereumAddress("0xeBec795c9c8bBD61FFc14A6662944748F299cAcf")!,
chainID: web3.provider.network!.chainID,
value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
value: XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
)
// Vitalik's address
tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
Expand All @@ -43,4 +27,18 @@ final class EIP1559Tests: XCTestCase {
XCTAssertGreaterThan(res, 0)
}

// func testEIP1159GoerliTransaction() async throws {
// let web3 = try await Web3.InfuraGoerliWeb3(accessToken: Constants.infuraToken)
// var tx = CodableTransaction(
// type: .eip1559,
// to: EthereumAddress("0xeBec795c9c8bBD61FFc14A6662944748F299cAcf")!,
// chainID: web3.provider.network!.chainID,
// value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether))
// )
// // Vitalik's address
// tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
// // Should fail if there would be something wrong with the tx
// let res = try await web3.eth.estimateGas(for: tx)
// XCTAssertGreaterThan(res, 0)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import XCTest
@testable import Web3Core

final class EtherscanTransactionCheckerTests: XCTestCase {
private var testApiKey: String { "4HVPVMV1PN6NGZDFXZIYKEZRP53IA41KVC" }
private var vitaliksAddress: String { "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B" }
private var emptyAddress: String { "0x3a0cd085155dc74cdddf3196f23c8cec9b217dd8" }

func testHasTransactions() async throws {
let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: testApiKey)

let result = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress)))
let result = try await sut.hasTransactions(ethereumAddress: XCTUnwrap(EthereumAddress(vitaliksAddress)))

XCTAssertTrue(result)
}
Expand All @@ -31,40 +27,52 @@ final class EtherscanTransactionCheckerTests: XCTestCase {
func testNetworkError() async throws {
do {
let urlSessionMock = URLSessionMock()
urlSessionMock.response = (Data(), try XCTUnwrap(HTTPURLResponse(url: try XCTUnwrap(URL(string: "https://")), statusCode: 500, httpVersion: nil, headerFields: nil)))
urlSessionMock.response = try (
Data(),
XCTUnwrap(HTTPURLResponse(
url: XCTUnwrap(URL(string: "https://")),
statusCode: 500,
httpVersion: nil,
headerFields: nil
))
)
let sut = EtherscanTransactionChecker(urlSession: urlSessionMock, apiKey: testApiKey)

_ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress)))
_ = try await sut.hasTransactions(ethereumAddress: XCTUnwrap(EthereumAddress(vitaliksAddress)))

XCTFail("Network must throw an error")
} catch let EtherscanTransactionCheckerError.network(statusCode) {
XCTAssertEqual(statusCode, 500)
}
}

func testInitURLError() async throws {
do {
let sut = EtherscanTransactionChecker(urlSession: URLSessionMock(), apiKey: " ")
// func testInitURLError() async throws {
// do {
// let sut = EtherscanTransactionChecker(urlSession: URLSessionMock(), apiKey: " ")

_ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress)))
// _ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress)))

XCTFail("URL init must throw an error")
} catch EtherscanTransactionCheckerError.invalidUrl {
XCTAssertTrue(true)
}
}
// XCTFail("URL init must throw an error")
// } catch EtherscanTransactionCheckerError.invalidUrl {
// XCTAssertTrue(true)
// }
// }

func testWrongApiKey() async throws {
do {
let sut = EtherscanTransactionChecker(urlSession: URLSession.shared, apiKey: "-")

_ = try await sut.hasTransactions(ethereumAddress: try XCTUnwrap(EthereumAddress(vitaliksAddress)))
_ = try await sut.hasTransactions(ethereumAddress: XCTUnwrap(EthereumAddress(vitaliksAddress)))

XCTFail("API not returns a valid response")
} catch DecodingError.typeMismatch {
XCTAssertTrue(true)
}
}

private var testApiKey: String { "4HVPVMV1PN6NGZDFXZIYKEZRP53IA41KVC" }
private var vitaliksAddress: String { "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B" }
private var emptyAddress: String { "0x3a0cd085155dc74cdddf3196f23c8cec9b217dd8" }
}

// MARK: - EtherscanTransactionCheckerErrorTests
Expand All @@ -78,7 +86,7 @@ final class EtherscanTransactionCheckerErrorTests: XCTestCase {

// MARK: - test double

final private class URLSessionMock: URLSessionProxy {
private final class URLSessionMock: URLSessionProxy {
var response: (Data, URLResponse) = (Data(), URLResponse())

func data(for request: URLRequest) async throws -> (Data, URLResponse) {
Expand Down
54 changes: 31 additions & 23 deletions Tests/web3swiftTests/remoteTests/InfuraTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Web3Core
@testable import web3swift

// MARK: Works only with network connection

class InfuraTests: XCTestCase {
func testGetBalance() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
Expand All @@ -18,33 +19,36 @@ class InfuraTests: XCTestCase {
XCTAssertNotNil(balString)
}

func testGetBlockByHash() async throws {
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() async throws {
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
// let result = try await web3.eth.block(
// by: "0x6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695",
// fullTransactions: false
// )
// XCTAssertEqual(result.number, 5_184_323)
// }

func testGetBlockByHash_hashAsData() async throws {
let blockHash = Data.fromHex("6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695")!
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 testGetBlockByHash_hashAsData() async throws {
// let blockHash = Data.fromHex("6d05ba24da6b7a1af22dc6cc2a1fe42f58b2a5ea4c406b19c8cf672ed8ec0695")!
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
// let result = try await web3.eth.block(by: blockHash, fullTransactions: false)
// XCTAssertEqual(result.number, 5_184_323)
// }

func testGetBlockByNumber1() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
_ = try await web3.eth.block(by: .latest, fullTransactions: false)
}
// func testGetBlockByNumber1() async throws {
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
// _ = try await web3.eth.block(by: .latest, fullTransactions: false)
// }

func testGetBlockByNumber2() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
_ = try await web3.eth.block(by: .exact(5184323), fullTransactions: true)
}
// func testGetBlockByNumber2() async throws {
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
// _ = try await web3.eth.block(by: .exact(5_184_323), fullTransactions: true)
// }

func testGetBlockByNumber3() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
do {
_ = try await web3.eth.block(by: .exact(10000000000000), fullTransactions: true)
_ = try await web3.eth.block(by: .exact(10_000_000_000_000), fullTransactions: true)
XCTFail("The expression above must throw DecodingError.")
} catch {
// DecodingError is thrown as a block for the given block number does not exist
Expand All @@ -65,9 +69,12 @@ class InfuraTests: XCTestCase {
// filter.fromBlock = .exact(5200120)
// filter.toBlock = .exact(5200120)
// filter.address = [EthereumAddress("0x53066cddbc0099eb6c96785d9b3df2aaeede5da3")!]
// filter.topics = [EventFilterParameters.Topic.strings([EventFilterParameters.Topic.string("0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5"), EventFilterParameters.Topic.string(nil)])]
// filter.topics =
// [EventFilterParameters.Topic.strings([EventFilterParameters.Topic.string("0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5"),
// EventFilterParameters.Topic.string(nil)])]
// // need
// let eventParserResult = try await contract!.getIndexedEvents(eventName: "Transfer", filter: filter, joinWithReceipts: true)
// let eventParserResult = try await contract!.getIndexedEvents(eventName: "Transfer", filter: filter, joinWithReceipts:
// true)
//
// XCTAssert(eventParserResult.count == 2)
// XCTAssert(eventParserResult.first?.transactionReceipt != nil)
Expand All @@ -80,7 +87,8 @@ class InfuraTests: XCTestCase {
// let contract = web3.contract(jsonString, at: nil, abiVersion: 2)
// var filter = EventFilter()
// filter.addresses = [EthereumAddress("0x53066cddbc0099eb6c96785d9b3df2aaeede5da3")!]
// filter.parameterFilters = [([EthereumAddress("0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5")!] as [EventFilterable]), ([EthereumAddress("0xd5395c132c791a7f46fa8fc27f0ab6bacd824484")!] as [EventFilterable])]
// filter.parameterFilters = [([EthereumAddress("0xefdcf2c36f3756ce7247628afdb632fa4ee12ec5")!] as [EventFilterable]),
// ([EthereumAddress("0xd5395c132c791a7f46fa8fc27f0ab6bacd824484")!] as [EventFilterable])]
// guard let eventParser = contract?.createEventParser("Transfer", filter: filter) else {return XCTFail()}
// let present = try eventParser.parseBlockByNumberPromise(UInt64(5200120)).wait()
//
Expand Down
45 changes: 22 additions & 23 deletions Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import Web3Core

// swiftlint:disable force_unwrapping
final class PolicyResolverTests: XCTestCase {

func testResolveAllForEIP1159Transaction() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
let resolver = PolicyResolver(provider: web3.provider)
var tx = CodableTransaction(
var tx = try CodableTransaction(
type: .eip1559,
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
chainID: web3.provider.network!.chainID,
value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
value: XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
gasLimit: 21_000
)
// Vitalik's address
Expand All @@ -35,25 +34,25 @@ final class PolicyResolverTests: XCTestCase {
XCTAssertGreaterThan(tx.nonce, 0)
}

func testResolveAllForLegacyTransaction() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
let resolver = PolicyResolver(provider: web3.provider)
var tx = CodableTransaction(
type: .legacy,
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
chainID: web3.provider.network!.chainID,
value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
gasLimit: 21_000
)
// Vitalik's address
tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
let policies = Policies(gasLimitPolicy: .manual(21_000))
try await resolver.resolveAll(for: &tx, with: policies)
// func testResolveAllForLegacyTransaction() async throws {
// let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
// let resolver = PolicyResolver(provider: web3.provider)
// var tx = CodableTransaction(
// type: .legacy,
// to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
// chainID: web3.provider.network!.chainID,
// value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
// gasLimit: 21_000
// )
// // Vitalik's address
// tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")!
// let policies = Policies(gasLimitPolicy: .manual(21_000))
// try await resolver.resolveAll(for: &tx, with: policies)

XCTAssertGreaterThan(tx.gasLimit, 0)
XCTAssertGreaterThan(tx.gasPrice ?? 0, 0)
XCTAssertGreaterThan(tx.nonce, 0)
}
// XCTAssertGreaterThan(tx.gasLimit, 0)
// XCTAssertGreaterThan(tx.gasPrice ?? 0, 0)
// XCTAssertGreaterThan(tx.nonce, 0)
// }

func testResolveExact() async throws {
let expectedNonce = BigUInt(42)
Expand All @@ -62,11 +61,11 @@ final class PolicyResolverTests: XCTestCase {
let expectedPriorityFee = BigUInt(9)
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
let resolver = PolicyResolver(provider: web3.provider)
var tx = CodableTransaction(
var tx = try CodableTransaction(
type: .eip1559,
to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!,
chainID: web3.provider.network!.chainID,
value: try XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
value: XCTUnwrap(Utilities.parseToBigUInt("0.1", units: .ether)),
gasLimit: 21_000
)
// Vitalik's address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import XCTest
@testable import Web3Core

final class TransactionPollingTaskRemoteTest: XCTestCase {

func testTransactionPolling() async throws {
let web3 = try await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken)
let txHash = Data.fromHex("0xb37cab767de85e734821f4b7b46f5093126658322a3f1b10bfef82b8009c8b82")!
let transactionReceipt = try await TransactionPollingTask(transactionHash: txHash, web3Instance: web3).wait()
XCTAssertEqual(transactionReceipt.status, .ok)
XCTAssertEqual(transactionReceipt.blockHash, Data.fromHex("0xdac48e6612d3c5b21c0e4b8edd9d25687a97137c636ff57a8df9f1f01bdfd25d"))
XCTAssertEqual(transactionReceipt.blockNumber, 16818367)
XCTAssertEqual(transactionReceipt.blockHash,
Data.fromHex("0xdac48e6612d3c5b21c0e4b8edd9d25687a97137c636ff57a8df9f1f01bdfd25d"))
XCTAssertEqual(transactionReceipt.blockNumber, 16_818_367)
XCTAssertEqual(transactionReceipt.gasUsed, "21000")
}

}
27 changes: 13 additions & 14 deletions Tests/web3swiftTests/remoteTests/Web3HttpProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ import Web3Core
@testable import web3swift

final class Web3HttpProviderTests: XCTestCase {

/// if one of these rpc server lose efficacy, find a substitution from https://chainlist.org/
func testGetNetwork() async throws {
let requestURLstring = "https://" + Networks.Mainnet.name + Constants.infuraHttpScheme + Constants.infuraToken
var web3 = try await Web3HttpProvider(url: URL(string: requestURLstring)!, network: nil)
XCTAssertEqual(web3.network?.chainID, 1)
// func testGetNetwork() async throws {
// let requestURLstring = "https://" + Networks.Mainnet.name + Constants.infuraHttpScheme + Constants.infuraToken
// var web3 = try await Web3HttpProvider(url: URL(string: requestURLstring)!, network: nil)
// XCTAssertEqual(web3.network?.chainID, 1)

web3 = try await Web3HttpProvider(url: URL(string: "https://arbitrum-one.publicnode.com")!, network: nil)
XCTAssertEqual(web3.network?.chainID, 42161)
// web3 = try await Web3HttpProvider(url: URL(string: "https://arbitrum-one.publicnode.com")!, network: nil)
// XCTAssertEqual(web3.network?.chainID, 42161)

web3 = try await Web3HttpProvider(url: URL(string: "https://rpc.ankr.com/bsc")!, network: nil)
XCTAssertEqual(web3.network?.chainID, 56)
// web3 = try await Web3HttpProvider(url: URL(string: "https://rpc.ankr.com/bsc")!, network: nil)
// XCTAssertEqual(web3.network?.chainID, 56)

web3 = try await Web3HttpProvider(url: URL(string: "https://rpc-mainnet.maticvigil.com/")!, network: nil)
XCTAssertEqual(web3.network?.chainID, 137)
// web3 = try await Web3HttpProvider(url: URL(string: "https://rpc-mainnet.maticvigil.com/")!, network: nil)
// XCTAssertEqual(web3.network?.chainID, 137)

web3 = try await Web3HttpProvider(url: URL(string: "https://optimism.gateway.tenderly.co")!, network: nil)
XCTAssertEqual(web3.network?.chainID, 10)
}
// web3 = try await Web3HttpProvider(url: URL(string: "https://optimism.gateway.tenderly.co")!, network: nil)
// XCTAssertEqual(web3.network?.chainID, 10)
// }
}

0 comments on commit 32a82bf

Please sign in to comment.