Skip to content

[CHANGE] Migrate tests to Goerli. Remove Rinkeby/Ropsten testnet definitions #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ OR

`EthereumWebSocketClient`
```swift
guard let clientUrl = URL(string: "wss://ropsten.infura.io/ws/v3//123") else { return }
guard let clientUrl = URL(string: "wss://goerli.infura.io/ws/v3//123") else { return }
let client = EthereumWebSocketClient(url: clientUrl)
```

Expand Down Expand Up @@ -159,7 +159,7 @@ We support querying ERC721 token data via the `ERC721` struct. Including:

### Running Tests

The tests will all pass when running against Ropsten. You will need to provide a URL for the blockchain proxy (e.g. on Infura), and a key-pair in `TestConfig.swift`. Some of the account signing tests will fail, given the signature assertions are against a specific (unprovided) key.
The tests will all pass when running against Goerli. You will need to provide a URL for the blockchain proxy (e.g. on Infura), and a key-pair in `TestConfig.swift`. Some of the account signing tests will fail, given the signature assertions are against a specific (unprovided) key.

## Dependencies

Expand Down
122 changes: 48 additions & 74 deletions web3sTests/Client/EthereumClientTests.swift

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions web3sTests/Contract/ABIEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class ABIEventTests: XCTestCase {
super.setUp()
client = EthereumHttpClient(url: URL(string: TestConfig.clientUrl)!)
}

func test_givenEventWithData4_ItParsesCorrectly() async {
do {
let encodedAddress = (try? ABIEncoder.encode(EthereumAddress("0x3B6Def16666a23905DD29071d13E7a9db08240E2")).bytes) ?? []
let encodedAddress = (try? ABIEncoder.encode(EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F")).bytes) ?? []

let eventsResult = try await client.getEvents(addresses: nil,
topics: [try? EnabledStaticCall.signature(), String(hexFromBytes: encodedAddress), nil],
fromBlock: .Number(8386245),
toBlock: .Number(8386245),
eventTypes: [EnabledStaticCall.self])

let eventFirst = eventsResult.events.first as? EnabledStaticCall
XCTAssertEqual(eventFirst?.module, EthereumAddress("0x3b6def16666a23905dd29071d13e7a9db08240e2"))
XCTAssertEqual(eventFirst?.method, Data(hex: "0x20c13b0b")!)

let eventLast = eventsResult.events.last as? EnabledStaticCall
XCTAssertEqual(eventLast?.module, EthereumAddress("0x3b6def16666a23905dd29071d13e7a9db08240e2"))
XCTAssertEqual(eventLast?.method, Data(hex: "0x1626ba7e")!)
topics: [try? AddressAndData4Event.signature(), String(hexFromBytes: encodedAddress), nil],
fromBlock: .Number(8017312 ),
toBlock: .Number(8017312 ),
eventTypes: [AddressAndData4Event.self])

let eventFirst = eventsResult.events.first as? AddressAndData4Event
XCTAssertEqual(eventFirst?.address, EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F"))
XCTAssertEqual(eventFirst?.data, Data(hex: "0x05f50234")!)

let eventLast = eventsResult.events.last as? AddressAndData4Event
XCTAssertEqual(eventLast?.address, EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F"))
XCTAssertEqual(eventLast?.data, Data(hex: "0xdeadbeef")!)
} catch {
XCTFail("Expected events but failed \(error).")
}
Expand All @@ -40,17 +40,17 @@ class ABIEventTests: XCTestCase {
func test_givenEventWithData32_ItParsesCorrectly() async {
do {
let eventsResult = try await client.getEvents(addresses: nil,
topics: [try? UpgraderRegistered.signature()],
topics: [try? AddressAndData32Event.signature()],
fromBlock: .Number(
8110676 ),
8017318 ),
toBlock: .Number(
8110676 ),
eventTypes: [UpgraderRegistered.self])
8017318 ),
eventTypes: [AddressAndData32Event.self])

XCTAssertEqual(eventsResult.events.count, 1)
let event = eventsResult.events.first as? UpgraderRegistered
XCTAssertEqual(event?.upgrader, EthereumAddress("0x17b11d842ae09eddedf5592f8271a7d07f6931e7"))
XCTAssertEqual(event?.name, Data(hex: "0x307864323664616666635f307833373731376663310000000000000000000000")!)
let event = eventsResult.events.first as? AddressAndData32Event
XCTAssertEqual(event?.address, EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F"))
XCTAssertEqual(event?.data, Data(hex: "05f5023424311e0f21827eba3fbe0dc4c3810a9d49fae3a16bf2b9d12c33d576")!)
} catch {
XCTFail("Expected events but failed \(error).")
}
Expand All @@ -64,39 +64,39 @@ class ABIEventWebSocketTests: ABIEventTests {
}
}

struct EnabledStaticCall: ABIEvent {
static let name = "EnabledStaticCall"
struct AddressAndData4Event: ABIEvent {
static let name = "AddressAndData4Event"
static let types: [ABIType.Type] = [EthereumAddress.self, Data4.self]
static let typesIndexed = [true, true]
let log: EthereumLog

let module: EthereumAddress
let method: Data
let address: EthereumAddress
let data: Data

init?(topics: [ABIDecoder.DecodedValue], data: [ABIDecoder.DecodedValue], log: EthereumLog) throws {
try EnabledStaticCall.checkParameters(topics, data)
try AddressAndData4Event.checkParameters(topics, data)
self.log = log

self.module = try topics[0].decoded()
self.method = try topics[1].decoded()
self.address = try topics[0].decoded()
self.data = try topics[1].decoded()

}
}

struct UpgraderRegistered: ABIEvent {
static let name = "UpgraderRegistered"
struct AddressAndData32Event: ABIEvent {
static let name = "AddressAndData32Event"
static let types: [ABIType.Type] = [EthereumAddress.self, Data32.self]
static let typesIndexed = [true, false]
let log: EthereumLog

let upgrader: EthereumAddress
let name: Data
let address: EthereumAddress
let data: Data

init?(topics: [ABIDecoder.DecodedValue], data: [ABIDecoder.DecodedValue], log: EthereumLog) throws {
try UpgraderRegistered.checkParameters(topics, data)
try AddressAndData32Event.checkParameters(topics, data)
self.log = log

self.upgrader = try topics[0].decoded()
self.name = try data[0].decoded()
self.address = try topics[0].decoded()
self.data = try data[0].decoded()
}
}
20 changes: 10 additions & 10 deletions web3sTests/ENS/ENSOffchainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ENSOffchainTests: XCTestCase {

}

func testGivenRopstenRegistry_WhenResolvingOffchainENS_ResolvesCorrectly() async {
func testGivenRegistry_WhenResolvingOffchainENS_ResolvesCorrectly() async {
do {
let nameService = EthereumNameService(client: client!)
let ens = try await nameService.resolve(
Expand All @@ -40,7 +40,7 @@ class ENSOffchainTests: XCTestCase {
}
}

func testGivenRopstenRegistry_WhenResolvingOffchainENSAndDisabled_ThenFails() async {
func testGivenRegistry_WhenResolvingOffchainENSAndDisabled_ThenFails() async {
do {
let nameService = EthereumNameService(client: client!)
_ = try await nameService.resolve(
Expand All @@ -53,20 +53,20 @@ class ENSOffchainTests: XCTestCase {
}
}

func testGivenRopstenRegistry_WhenResolvingNonOffchainENS_ThenResolves() async {
func testGivenRegistry_WhenResolvingNonOffchainENS_ThenResolves() async {
do {
let nameService = EthereumNameService(client: client!)
let ens = try await nameService.resolve(
ens: "resolver.eth",
mode: .allowOffchainLookup
)
XCTAssertEqual(EthereumAddress("0x42d63ae25990889e35f215bc95884039ba354115"), ens)
XCTAssertEqual(EthereumAddress("0xe264d5bb84ba3b8061adc38d3d76e6674ab91852"), ens)
} catch {
XCTFail("Expected ens but failed \(error).")
}
}

func testGivenRopstenRegistry_WhenWildcardSupported_AndAddressHasSubdomain_ThenResolvesCorrectly() async {
func testGivenRegistry_WhenWildcardSupported_AndAddressHasSubdomain_ThenResolvesCorrectly() async {
do {
let nameService = EthereumNameService(client: client!)

Expand All @@ -81,7 +81,7 @@ class ENSOffchainTests: XCTestCase {
}
}

func testGivenRopstenRegistry_WhenWildcardNOTSupported_AndAddressHasSubdomain_ThenFailsResolving() async {
func testGivenRegistry_WhenWildcardNOTSupported_AndAddressHasSubdomain_ThenFailsResolving() async {
do {
let nameService = EthereumNameService(client: client!)

Expand All @@ -96,15 +96,15 @@ class ENSOffchainTests: XCTestCase {
}
}

func testGivenRopstenRegistry_WhenTwoRequestsWithAndWithoutSubdomain_ThenBothResolveCorrectly() async {
func testGivenRegistry_WhenTwoRequestsWithAndWithoutSubdomain_ThenBothResolveCorrectly() async {
let nameService = EthereumNameService(client: client!)

do {
let ens = try await nameService.resolve(
ens: "resolver.eth",
mode: .allowOffchainLookup
)
XCTAssertEqual(EthereumAddress("0x42d63ae25990889e35f215bc95884039ba354115"), ens)
XCTAssertEqual(EthereumAddress("0xe264d5bb84ba3b8061adc38d3d76e6674ab91852"), ens)
} catch {
XCTFail("Expected ens but failed \(error).")
}
Expand All @@ -120,7 +120,7 @@ class ENSOffchainTests: XCTestCase {
}
}

func testGivenRopstenRegistry_WhenTwoRequestsWithoutAndWithSubdomain_ThenBothResolveCorrectly() async {
func testGivenRegistry_WhenTwoRequestsWithoutAndWithSubdomain_ThenBothResolveCorrectly() async {
let nameService = EthereumNameService(client: client!)

do {
Expand All @@ -139,7 +139,7 @@ class ENSOffchainTests: XCTestCase {
ens: "resolver.eth",
mode: .allowOffchainLookup
)
XCTAssertEqual(EthereumAddress("0x42d63ae25990889e35f215bc95884039ba354115"), ens)
XCTAssertEqual(EthereumAddress("0xe264d5bb84ba3b8061adc38d3d76e6674ab91852"), ens)
} catch {
XCTFail("Expected ens but failed \(error).")
}
Expand Down
Loading