From 5e276d084b48e77439670ec4fa7a7871022c09ef Mon Sep 17 00:00:00 2001 From: Brett Fazio Date: Tue, 2 Feb 2021 10:34:06 -0500 Subject: [PATCH 1/2] Fix 2/7 failing test cases by getting latest block --- Tests/Web3Tests/Web3Tests/Web3HttpTests.swift | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift b/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift index da9dec8f..05e98c66 100644 --- a/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift +++ b/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift @@ -23,7 +23,6 @@ class Web3HttpTests: QuickSpec { describe("http rpc requests") { let web3 = Web3(rpcURL: infuraUrl) - context("web3 client version") { waitUntil(timeout: 2.0) { done in @@ -216,6 +215,7 @@ class Web3HttpTests: QuickSpec { waitUntil(timeout: 2.0) { done in web3.eth.blockNumber { response in + print("quant \(response.result)") it("should be status ok") { expect(response.status.isSuccess) == true } @@ -243,19 +243,26 @@ class Web3HttpTests: QuickSpec { } waitUntil(timeout: 2.0) { done in - web3.eth.getBalance(address: ethereumAddress, block: .block(4000000)) { response in - it("should be status ok") { - expect(response.status.isSuccess) == true - } - it("should not be nil") { - expect(response.result).toNot(beNil()) - } - it("should be a quantity response") { - expect(response.result?.quantity) == BigUInt("1ea7ab3de3c2f1dc75", radix: 16) - } + + // Infura only works on 128 most recent blocks, dynmaically get the latest block to test. + web3.eth.blockNumber { blockResponse in + + expect(blockResponse.result).toNot(beNil()) + + web3.eth.getBalance(address: ethereumAddress, block: .block(blockResponse.result!.quantity)) { response in + it("should be status ok") { + expect(response.status.isSuccess) == true + } + it("should not be nil") { + expect(response.result).toNot(beNil()) + } + it("should be a quantity response") { + expect(response.result?.quantity) == BigUInt("1ea7ab3de3c2f1dc75", radix: 16) + } - // Tests done - done() + // Tests done + done() + } } } } @@ -397,7 +404,7 @@ class Web3HttpTests: QuickSpec { } context("eth get code") { - waitUntil(timeout: 2.0) { done in + waitUntil(timeout: 5.0) { done in firstly { try web3.eth.getCode(address: EthereumAddress(hex: "0x2e704bF506b96adaC7aD1df0db461344146a4657", eip55: true), block: .block(5397525)) }.done { code in From 04bd56f732ff0b583df41c01b08b20195e50d690 Mon Sep 17 00:00:00 2001 From: Brett Fazio Date: Tue, 2 Feb 2021 10:35:35 -0500 Subject: [PATCH 2/2] remove debug statement --- Tests/Web3Tests/Web3Tests/Web3HttpTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift b/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift index 05e98c66..96159944 100644 --- a/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift +++ b/Tests/Web3Tests/Web3Tests/Web3HttpTests.swift @@ -215,7 +215,6 @@ class Web3HttpTests: QuickSpec { waitUntil(timeout: 2.0) { done in web3.eth.blockNumber { response in - print("quant \(response.result)") it("should be status ok") { expect(response.status.isSuccess) == true }