From 280316c6a93749b2afb45803f91e79d288098eac Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Thu, 20 Oct 2022 21:16:42 -0700 Subject: [PATCH 01/37] exclude ios vc by default --- Package.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index faf66d529..e82c25956 100755 --- a/Package.swift +++ b/Package.swift @@ -3,12 +3,12 @@ import PackageDescription -#if os(macOS) +#if os(iOS) +let excludeFiles: String = [] +#else let excludeFiles = [ "./Browser/BrowserViewController.swift" // Because of inheriting iOS only class failed to build on macOS. ] -#elseif os(iOS) -let excludeFiles: String = [] #endif let package = Package( From 3461cb841fa6b16ecc2f883e1b3b80ac10d9c16d Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 21:44:08 -0700 Subject: [PATCH 02/37] Import FoundationNetworking for Linux --- Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift | 3 +++ .../EthereumNetwork/Utility/Async+BackwardCapability.swift | 3 +++ Sources/web3swift/Web3/Web3+HttpProvider.swift | 3 +++ 3 files changed, 9 insertions(+) diff --git a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift index 127bd8e6b..247d33cde 100644 --- a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift +++ b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift @@ -7,6 +7,9 @@ import Foundation import BigInt +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif extension APIRequest { public static func sendRequest(with provider: Web3Provider, for call: APIRequest) async throws -> APIResponse { diff --git a/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift b/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift index 46658db72..58f335f39 100644 --- a/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift +++ b/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift @@ -6,6 +6,9 @@ // import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif @available(iOS, obsoleted: 15.0, message: "Use the built-in API instead") @available(macOS, obsoleted: 12.0, message: "Use the built-in API instead") diff --git a/Sources/web3swift/Web3/Web3+HttpProvider.swift b/Sources/web3swift/Web3/Web3+HttpProvider.swift index b3db61b0f..af3c3acc3 100755 --- a/Sources/web3swift/Web3/Web3+HttpProvider.swift +++ b/Sources/web3swift/Web3/Web3+HttpProvider.swift @@ -6,6 +6,9 @@ import Foundation import BigInt import Core +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif /// The default http provider. public class Web3HttpProvider: Web3Provider { From 773ba9258868e389514a6947f72d224d57e995da Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 21:53:34 -0700 Subject: [PATCH 03/37] URLsession to FoundationNetworking --- Sources/Core/Structure/Web3ProviderProtocol.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Core/Structure/Web3ProviderProtocol.swift b/Sources/Core/Structure/Web3ProviderProtocol.swift index 68deae031..ca6bd19fc 100644 --- a/Sources/Core/Structure/Web3ProviderProtocol.swift +++ b/Sources/Core/Structure/Web3ProviderProtocol.swift @@ -6,6 +6,9 @@ // import Foundation +#if canImport(FoundationNetworking) +import FoundationNetworking +#endif public protocol Web3Provider { var network: Networks? {get set} From f14a8998fbfdc4a6bd1c4f0f0a5b2af7f39e6316 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 22:06:00 -0700 Subject: [PATCH 04/37] FoundationNetworking preceeding Foundation --- .../Core/EthereumNetwork/Request/APIRequest+Methods.swift | 4 ++-- .../EthereumNetwork/Utility/Async+BackwardCapability.swift | 2 +- Sources/Core/Structure/Web3ProviderProtocol.swift | 2 +- Sources/web3swift/Web3/Web3+HttpProvider.swift | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift index 247d33cde..c457b2ef8 100644 --- a/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift +++ b/Sources/Core/EthereumNetwork/Request/APIRequest+Methods.swift @@ -5,11 +5,11 @@ // Created by Yaroslav Yashin on 12.07.2022. // -import Foundation -import BigInt #if canImport(FoundationNetworking) import FoundationNetworking #endif +import Foundation +import BigInt extension APIRequest { public static func sendRequest(with provider: Web3Provider, for call: APIRequest) async throws -> APIResponse { diff --git a/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift b/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift index 58f335f39..22e0980e0 100644 --- a/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift +++ b/Sources/Core/EthereumNetwork/Utility/Async+BackwardCapability.swift @@ -5,10 +5,10 @@ // Created by Yaroslav Yashin on 05.06.2022. // -import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif +import Foundation @available(iOS, obsoleted: 15.0, message: "Use the built-in API instead") @available(macOS, obsoleted: 12.0, message: "Use the built-in API instead") diff --git a/Sources/Core/Structure/Web3ProviderProtocol.swift b/Sources/Core/Structure/Web3ProviderProtocol.swift index ca6bd19fc..1f743a6f2 100644 --- a/Sources/Core/Structure/Web3ProviderProtocol.swift +++ b/Sources/Core/Structure/Web3ProviderProtocol.swift @@ -5,10 +5,10 @@ // Created by Yaroslav Yashin on 11.07.2022. // -import Foundation #if canImport(FoundationNetworking) import FoundationNetworking #endif +import Foundation public protocol Web3Provider { var network: Networks? {get set} diff --git a/Sources/web3swift/Web3/Web3+HttpProvider.swift b/Sources/web3swift/Web3/Web3+HttpProvider.swift index af3c3acc3..9418c37b3 100755 --- a/Sources/web3swift/Web3/Web3+HttpProvider.swift +++ b/Sources/web3swift/Web3/Web3+HttpProvider.swift @@ -3,12 +3,12 @@ // Copyright © 2018 Alex Vlasov. All rights reserved. // -import Foundation -import BigInt -import Core #if canImport(FoundationNetworking) import FoundationNetworking #endif +import Foundation +import BigInt +import Core /// The default http provider. public class Web3HttpProvider: Web3Provider { From 33479eebfb780276ef9acaedec4cc33754a539e3 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 22:35:21 -0700 Subject: [PATCH 05/37] Add Linux alternative to SecRandomCopyBytes --- Sources/Core/Structure/SECP256k1.swift | 4 ++++ Sources/Core/Utility/Data+Extension.swift | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 787c5ee34..dd0ce3960 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -336,6 +336,9 @@ extension SECP256K1 { } internal static func randomBytes(length: Int) -> Data? { + #if os(Linux) + sk = [UInt8].random(count: Constants.SecretKeyLength) + #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) let result = data.withUnsafeMutableBytes { (mutableRBBytes) -> Int32? in @@ -353,6 +356,7 @@ extension SECP256K1 { } } return nil + #endif } internal static func toByteArray(_ value: T) -> [UInt8] { diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 4bc94645d..a165dfdaa 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -41,6 +41,9 @@ extension Data { } public static func randomBytes(length: Int) -> Data? { + #if os(Linux) + sk = [UInt8].random(count: Constants.SecretKeyLength) + #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) let result = data.withUnsafeMutableBytes { (body: UnsafeMutableRawBufferPointer) -> Int32? in @@ -56,6 +59,7 @@ extension Data { } } return nil + #endif } public func bitsInRange(_ startingBit: Int, _ length: Int) -> UInt64? { // return max of 8 bytes for simplicity, non-public From c8fc0a7c5d35160887b1ca13a8b9e871893a0c2f Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 22:39:16 -0700 Subject: [PATCH 06/37] Fix return random --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index dd0ce3960..3ec1fa9f3 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - sk = [UInt8].random(count: Constants.SecretKeyLength) + return [UInt8].random(count: Constants.SecretKeyLength) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index a165dfdaa..67048e1e8 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -42,7 +42,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - sk = [UInt8].random(count: Constants.SecretKeyLength) + return [UInt8].random(count: Constants.SecretKeyLength) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) From 9898f0dcc382d617cf3ef5cce3aa9fc632b38b2c Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 22:41:36 -0700 Subject: [PATCH 07/37] Fix count --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 3ec1fa9f3..d1b5d6de8 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - return [UInt8].random(count: Constants.SecretKeyLength) + return [UInt8].random(count: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 67048e1e8..db179f0a2 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -42,7 +42,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - return [UInt8].random(count: Constants.SecretKeyLength) + return [UInt8].random(count: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) From 5f90f67fc494c931a5d7526131d1c0c86b74511b Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 22:46:17 -0700 Subject: [PATCH 08/37] Import Vapor --- Sources/Core/Structure/SECP256k1.swift | 5 ++++- Sources/Core/Utility/Data+Extension.swift | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index d1b5d6de8..46141eb9a 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -8,6 +8,9 @@ import Foundation import secp256k1 +#if canImport(Vapor) +import Vapor +#endif public struct SECP256K1 { public struct UnmarshaledSignature{ @@ -336,7 +339,7 @@ extension SECP256K1 { } internal static func randomBytes(length: Int) -> Data? { - #if os(Linux) + #if canImport(Vapor) return [UInt8].random(count: length) #else for _ in 0...1024 { diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index db179f0a2..a88c99629 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -4,6 +4,9 @@ // import Foundation +#if canImport(Vapor) +import Vapor +#endif extension Data { init(fromArray values: [T]) { @@ -41,7 +44,7 @@ extension Data { } public static func randomBytes(length: Int) -> Data? { - #if os(Linux) + #if canImport(Vapor) return [UInt8].random(count: length) #else for _ in 0...1024 { From 8460d9236d6e85d293c33d49c845a14d80e4bf52 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 23:13:50 -0700 Subject: [PATCH 09/37] Add [UInt8].random --- Sources/Core/Structure/SECP256k1.swift | 5 +-- Sources/Core/Utility/Data+Extension.swift | 6 ++-- Sources/Core/Utility/UInt8+Random.swift | 38 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 Sources/Core/Utility/UInt8+Random.swift diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 46141eb9a..d1b5d6de8 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -8,9 +8,6 @@ import Foundation import secp256k1 -#if canImport(Vapor) -import Vapor -#endif public struct SECP256K1 { public struct UnmarshaledSignature{ @@ -339,7 +336,7 @@ extension SECP256K1 { } internal static func randomBytes(length: Int) -> Data? { - #if canImport(Vapor) + #if os(Linux) return [UInt8].random(count: length) #else for _ in 0...1024 { diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index a88c99629..c174158d9 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -4,9 +4,7 @@ // import Foundation -#if canImport(Vapor) -import Vapor -#endif + extension Data { init(fromArray values: [T]) { @@ -44,7 +42,7 @@ extension Data { } public static func randomBytes(length: Int) -> Data? { - #if canImport(Vapor) + #if os(Linux) return [UInt8].random(count: length) #else for _ in 0...1024 { diff --git a/Sources/Core/Utility/UInt8+Random.swift b/Sources/Core/Utility/UInt8+Random.swift new file mode 100644 index 000000000..8049fe9c4 --- /dev/null +++ b/Sources/Core/Utility/UInt8+Random.swift @@ -0,0 +1,38 @@ +// +// File.swift +// +// +// Created by Ronald Mannak on 10/29/22. +// + +import Foundation + +#if os(Linux) +extension FixedWidthInteger { + public static func random() -> Self { + return Self.random(in: .min ... .max) + } + + public static func random(using generator: inout T) -> Self + where T : RandomNumberGenerator + { + return Self.random(in: .min ... .max, using: &generator) + } +} + +extension Array where Element: FixedWidthInteger { + public static func random(count: Int) -> [Element] { + var array: [Element] = .init(repeating: 0, count: count) + (0..(count: Int, using generator: inout T) -> [Element] + where T: RandomNumberGenerator + { + var array: [Element] = .init(repeating: 0, count: count) + (0.. Date: Sat, 29 Oct 2022 23:16:41 -0700 Subject: [PATCH 10/37] Fix [UInt8] to Data --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index d1b5d6de8..4eaf85eb5 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - return [UInt8].random(count: length) + return Data([UInt8].random(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index c174158d9..a0744d09e 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -43,7 +43,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - return [UInt8].random(count: length) + return Data([UInt8].random(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) From d4955d4eab2c6baa728095bcddf0607337a98099 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 23:19:25 -0700 Subject: [PATCH 11/37] Excluded WebKit extension for Linux --- Sources/web3swift/Browser/Bridge.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/web3swift/Browser/Bridge.swift b/Sources/web3swift/Browser/Bridge.swift index 597277003..7a56afe41 100644 --- a/Sources/web3swift/Browser/Bridge.swift +++ b/Sources/web3swift/Browser/Bridge.swift @@ -6,6 +6,7 @@ // Copyright © 2017 Samaritan. All rights reserved. // +#if !os(Linux) import WebKit /// Bridge for WKWebView and JavaScript @@ -248,3 +249,4 @@ fileprivate extension WKWebView { evaluateJavaScript(jsString, completionHandler: completionHandler) } } +#endif From 855ad8eaca8fd2f8582a295883212945a3c74634 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 23:24:53 -0700 Subject: [PATCH 12/37] Disabled CoreImage for Linux --- Sources/web3swift/Utils/EIP/EIP67Code.swift | 6 ++++++ Tests/web3swiftTests/localTests/EIP67Tests.swift | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Sources/web3swift/Utils/EIP/EIP67Code.swift b/Sources/web3swift/Utils/EIP/EIP67Code.swift index 7cbfd0af3..1dcf4b2ae 100755 --- a/Sources/web3swift/Utils/EIP/EIP67Code.swift +++ b/Sources/web3swift/Utils/EIP/EIP67Code.swift @@ -4,7 +4,9 @@ // import Foundation +#if !os(Linux) import CoreImage +#endif import BigInt import Core @@ -77,11 +79,14 @@ extension Web3 { return mainPart } + #if !os(Linux) public func toImage(scale: Double = 1.0) -> CIImage { return EIP67CodeGenerator.createImage(from: self, scale: scale) } + #endif } + #if !os(Linux) public struct EIP67CodeGenerator { public static func createImage(from: EIP67Code, scale: Double = 1.0) -> CIImage { @@ -94,6 +99,7 @@ extension Web3 { return image } } + #endif public struct EIP67CodeParser { public static func parse(_ data: Data) -> EIP67Code? { diff --git a/Tests/web3swiftTests/localTests/EIP67Tests.swift b/Tests/web3swiftTests/localTests/EIP67Tests.swift index 420919286..a7c94791a 100755 --- a/Tests/web3swiftTests/localTests/EIP67Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP67Tests.swift @@ -21,6 +21,7 @@ class EIP67Tests: LocalTestCase { print(encoding) } + #if !os(Linux) func testEIP67codeGeneration() throws { var eip67Data = Web3.EIP67Code.init(address: EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!) eip67Data.gasLimit = BigUInt(21000) @@ -29,6 +30,7 @@ class EIP67Tests: LocalTestCase { let encoding = eip67Data.toImage(scale: 5.0) XCTAssert(encoding != CIImage()) } + #endif func testEIP67decoding() throws { var eip67Data = Web3.EIP67Code.init(address: EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!) From 936ff2a6826e3d1e60e2ed90faa5d43a185f6ff0 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sat, 29 Oct 2022 23:29:03 -0700 Subject: [PATCH 13/37] Comment out random --- Sources/Core/Utility/UInt8+Random.swift | 58 ++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Sources/Core/Utility/UInt8+Random.swift b/Sources/Core/Utility/UInt8+Random.swift index 8049fe9c4..34a21df64 100644 --- a/Sources/Core/Utility/UInt8+Random.swift +++ b/Sources/Core/Utility/UInt8+Random.swift @@ -7,32 +7,32 @@ import Foundation -#if os(Linux) -extension FixedWidthInteger { - public static func random() -> Self { - return Self.random(in: .min ... .max) - } - - public static func random(using generator: inout T) -> Self - where T : RandomNumberGenerator - { - return Self.random(in: .min ... .max, using: &generator) - } -} - -extension Array where Element: FixedWidthInteger { - public static func random(count: Int) -> [Element] { - var array: [Element] = .init(repeating: 0, count: count) - (0..(count: Int, using generator: inout T) -> [Element] - where T: RandomNumberGenerator - { - var array: [Element] = .init(repeating: 0, count: count) - (0.. Self { +// return Self.random(in: .min ... .max) +// } +// +// public static func random(using generator: inout T) -> Self +// where T : RandomNumberGenerator +// { +// return Self.random(in: .min ... .max, using: &generator) +// } +//} +// +//extension Array where Element: FixedWidthInteger { +// public static func random(count: Int) -> [Element] { +// var array: [Element] = .init(repeating: 0, count: count) +// (0..(count: Int, using generator: inout T) -> [Element] +// where T: RandomNumberGenerator +// { +// var array: [Element] = .init(repeating: 0, count: count) +// (0.. Date: Sun, 30 Oct 2022 07:40:54 -0700 Subject: [PATCH 14/37] Rename random to randomData --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- Sources/Core/Utility/UInt8+Random.swift | 58 +++++++++++------------ 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 4eaf85eb5..22dfbf788 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data([UInt8].random(count: length)) + return Data([UInt8].randomData(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index a0744d09e..9466d635d 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -43,7 +43,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data([UInt8].random(count: length)) + return Data([UInt8].randomData(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/UInt8+Random.swift b/Sources/Core/Utility/UInt8+Random.swift index 34a21df64..c4ed58222 100644 --- a/Sources/Core/Utility/UInt8+Random.swift +++ b/Sources/Core/Utility/UInt8+Random.swift @@ -7,32 +7,32 @@ import Foundation -//#if os(Linux) -//extension FixedWidthInteger { -// public static func random() -> Self { -// return Self.random(in: .min ... .max) -// } -// -// public static func random(using generator: inout T) -> Self -// where T : RandomNumberGenerator -// { -// return Self.random(in: .min ... .max, using: &generator) -// } -//} -// -//extension Array where Element: FixedWidthInteger { -// public static func random(count: Int) -> [Element] { -// var array: [Element] = .init(repeating: 0, count: count) -// (0..(count: Int, using generator: inout T) -> [Element] -// where T: RandomNumberGenerator -// { -// var array: [Element] = .init(repeating: 0, count: count) -// (0.. Self { + return Self.random(in: .min ... .max) + } + + public static func randomData(using generator: inout T) -> Self + where T : RandomNumberGenerator + { + return Self.random(in: .min ... .max, using: &generator) + } +} + +extension Array where Element: FixedWidthInteger { + public static func randomData(count: Int) -> [Element] { + var array: [Element] = .init(repeating: 0, count: count) + (0..(count: Int, using generator: inout T) -> [Element] + where T: RandomNumberGenerator + { + var array: [Element] = .init(repeating: 0, count: count) + (0.. Date: Sun, 30 Oct 2022 08:01:36 -0700 Subject: [PATCH 15/37] fix randomData --- Sources/Core/Utility/UInt8+Random.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Core/Utility/UInt8+Random.swift b/Sources/Core/Utility/UInt8+Random.swift index c4ed58222..19faeec25 100644 --- a/Sources/Core/Utility/UInt8+Random.swift +++ b/Sources/Core/Utility/UInt8+Random.swift @@ -10,20 +10,20 @@ import Foundation #if os(Linux) extension FixedWidthInteger { public static func randomData() -> Self { - return Self.random(in: .min ... .max) + return Self.randomData(in: .min ... .max) } public static func randomData(using generator: inout T) -> Self where T : RandomNumberGenerator { - return Self.random(in: .min ... .max, using: &generator) + return Self.randomData(in: .min ... .max, using: &generator) } } extension Array where Element: FixedWidthInteger { public static func randomData(count: Int) -> [Element] { var array: [Element] = .init(repeating: 0, count: count) - (0.. Date: Sun, 30 Oct 2022 08:59:18 -0700 Subject: [PATCH 16/37] Add Ubuntu CI workflow --- .github/workflows/ubuntu.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ubuntu.yml diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 000000000..f5a18045f --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,23 @@ +# This workflow will build a Swift project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift + +name: Swift + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + build: + + runs-on: ubuntu-latest + container: swift:5.7-focal + + steps: + - uses: actions/checkout@v3 + - name: Build + run: swift build + - name: Run tests + run: swift test From 44039d20b730bb2c0f3e10285e8a8223fae19253 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sun, 30 Oct 2022 09:02:40 -0700 Subject: [PATCH 17/37] Rename swift action to ubuntu --- .github/workflows/ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index f5a18045f..1a5a773be 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -1,7 +1,7 @@ # This workflow will build a Swift project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift -name: Swift +name: Ubuntu on: push: From 9e341a3db37a4a0135121b395999d35e90c4d0cf Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sun, 30 Oct 2022 16:43:42 -0700 Subject: [PATCH 18/37] Add dev/random --- Sources/Core/Utility/Data+Random.swift | 93 +++++++++++++++++++++++++ Sources/Core/Utility/UInt8+Random.swift | 38 ---------- 2 files changed, 93 insertions(+), 38 deletions(-) create mode 100644 Sources/Core/Utility/Data+Random.swift delete mode 100644 Sources/Core/Utility/UInt8+Random.swift diff --git a/Sources/Core/Utility/Data+Random.swift b/Sources/Core/Utility/Data+Random.swift new file mode 100644 index 000000000..1d0ffe3a1 --- /dev/null +++ b/Sources/Core/Utility/Data+Random.swift @@ -0,0 +1,93 @@ +// +// File.swift +// +// +// Created by Ronald Mannak on 10/29/22. +// + +import Foundation +#if canImport(libc) +import libc + + +/// URandom represents a file connection to /dev/urandom on Unix systems. +/// /dev/urandom is a cryptographically secure random generator provided by the OS. +public final class URandom: RandomProtocol { + public enum Error: Swift.Error { + case open(Int32) + case read(Int32) + } + + private let file: UnsafeMutablePointer + + /// Initialize URandom + public init(path: String) throws { + guard let file = fopen(path, "rb") else { + // The Random protocol doesn't allow init to fail, so we have to + // check whether /dev/urandom was successfully opened here + throw Error.open(errno) + } + self.file = file + } + + deinit { + fclose(file) + } + + private func read(numBytes: Int) throws -> [Int8] { + + + // Initialize an empty array with space for numBytes bytes + var bytes = [Int8](repeating: 0, count: numBytes) + guard fread(&bytes, 1, numBytes, file) == numBytes else { + // If the requested number of random bytes couldn't be read, + // we need to throw an error + throw Error.read(errno) + } + + return bytes + } + + /// Get a random array of Bytes + public func bytes(count: Int) throws -> Bytes { + return try read(numBytes: count).map({ Byte(bitPattern: $0) }) + } +} + +extension URandom: EmptyInitializable { + public convenience init() throws { + try self.init(path: "/dev/urandom") + } +} + +#endif + +//#if os(Linux) +//extension FixedWidthInteger { +// public static func randomData() -> Self { +// return Self.randomData(in: .min ... .max) +// } +// +// public static func randomData(using generator: inout T) -> Self +// where T : RandomNumberGenerator +// { +// return Self.randomData(in: .min ... .max, using: &generator) +// } +//} +// +//extension Array where Element: FixedWidthInteger { +// public static func randomData(count: Int) -> [Element] { +// var array: [Element] = .init(repeating: 0, count: count) +// (0..(count: Int, using generator: inout T) -> [Element] +// where T: RandomNumberGenerator +// { +// var array: [Element] = .init(repeating: 0, count: count) +// (0.. Self { - return Self.randomData(in: .min ... .max) - } - - public static func randomData(using generator: inout T) -> Self - where T : RandomNumberGenerator - { - return Self.randomData(in: .min ... .max, using: &generator) - } -} - -extension Array where Element: FixedWidthInteger { - public static func randomData(count: Int) -> [Element] { - var array: [Element] = .init(repeating: 0, count: count) - (0..(count: Int, using generator: inout T) -> [Element] - where T: RandomNumberGenerator - { - var array: [Element] = .init(repeating: 0, count: count) - (0.. Date: Sun, 30 Oct 2022 16:49:15 -0700 Subject: [PATCH 19/37] Use URandom --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- .../{Data+Random.swift => URandom.swift} | 30 ------------------- 3 files changed, 2 insertions(+), 32 deletions(-) rename Sources/Core/Utility/{Data+Random.swift => URandom.swift} (62%) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 22dfbf788..31239d155 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data([UInt8].randomData(count: length)) + return Data(URandom().bytes(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 9466d635d..d4c863637 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -43,7 +43,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data([UInt8].randomData(count: length)) + return Data(URandom().bytes(count: length)) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Random.swift b/Sources/Core/Utility/URandom.swift similarity index 62% rename from Sources/Core/Utility/Data+Random.swift rename to Sources/Core/Utility/URandom.swift index 1d0ffe3a1..1ed282dfa 100644 --- a/Sources/Core/Utility/Data+Random.swift +++ b/Sources/Core/Utility/URandom.swift @@ -61,33 +61,3 @@ extension URandom: EmptyInitializable { } #endif - -//#if os(Linux) -//extension FixedWidthInteger { -// public static func randomData() -> Self { -// return Self.randomData(in: .min ... .max) -// } -// -// public static func randomData(using generator: inout T) -> Self -// where T : RandomNumberGenerator -// { -// return Self.randomData(in: .min ... .max, using: &generator) -// } -//} -// -//extension Array where Element: FixedWidthInteger { -// public static func randomData(count: Int) -> [Element] { -// var array: [Element] = .init(repeating: 0, count: count) -// (0..(count: Int, using generator: inout T) -> [Element] -// where T: RandomNumberGenerator -// { -// var array: [Element] = .init(repeating: 0, count: count) -// (0.. Date: Sun, 30 Oct 2022 16:59:31 -0700 Subject: [PATCH 20/37] Swift to temp random --- Sources/Core/Structure/SECP256k1.swift | 3 +- Sources/Core/Utility/Data+Extension.swift | 3 +- Sources/Core/Utility/URandom.swift | 104 ++++++++++++---------- 3 files changed, 62 insertions(+), 48 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 31239d155..9e706e553 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -337,7 +337,8 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data(URandom().bytes(count: length)) +// return Data(URandom().bytes(count: length)) + return Data.random(length: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index d4c863637..8de0473d9 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -43,7 +43,8 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) - return Data(URandom().bytes(count: length)) +// return Data(URandom().bytes(count: length)) + return Data.random(length: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/URandom.swift b/Sources/Core/Utility/URandom.swift index 1ed282dfa..12edccab4 100644 --- a/Sources/Core/Utility/URandom.swift +++ b/Sources/Core/Utility/URandom.swift @@ -10,54 +10,66 @@ import Foundation import libc -/// URandom represents a file connection to /dev/urandom on Unix systems. -/// /dev/urandom is a cryptographically secure random generator provided by the OS. -public final class URandom: RandomProtocol { - public enum Error: Swift.Error { - case open(Int32) - case read(Int32) - } - - private let file: UnsafeMutablePointer - - /// Initialize URandom - public init(path: String) throws { - guard let file = fopen(path, "rb") else { - // The Random protocol doesn't allow init to fail, so we have to - // check whether /dev/urandom was successfully opened here - throw Error.open(errno) - } - self.file = file - } - - deinit { - fclose(file) - } - - private func read(numBytes: Int) throws -> [Int8] { - - - // Initialize an empty array with space for numBytes bytes - var bytes = [Int8](repeating: 0, count: numBytes) - guard fread(&bytes, 1, numBytes, file) == numBytes else { - // If the requested number of random bytes couldn't be read, - // we need to throw an error - throw Error.read(errno) - } +///// URandom represents a file connection to /dev/urandom on Unix systems. +///// /dev/urandom is a cryptographically secure random generator provided by the OS. +//public final class URandom: RandomProtocol { +// public enum Error: Swift.Error { +// case open(Int32) +// case read(Int32) +// } +// +// private let file: UnsafeMutablePointer +// +// /// Initialize URandom +// public init(path: String) throws { +// guard let file = fopen(path, "rb") else { +// // The Random protocol doesn't allow init to fail, so we have to +// // check whether /dev/urandom was successfully opened here +// throw Error.open(errno) +// } +// self.file = file +// } +// +// deinit { +// fclose(file) +// } +// +// private func read(numBytes: Int) throws -> [Int8] { +// +// +// // Initialize an empty array with space for numBytes bytes +// var bytes = [Int8](repeating: 0, count: numBytes) +// guard fread(&bytes, 1, numBytes, file) == numBytes else { +// // If the requested number of random bytes couldn't be read, +// // we need to throw an error +// throw Error.read(errno) +// } +// +// return bytes +// } +// +// /// Get a random array of Bytes +// public func bytes(count: Int) throws -> Bytes { +// return try read(numBytes: count).map({ Byte(bitPattern: $0) }) +// } +//} +// +//extension URandom: EmptyInitializable { +// public convenience init() throws { +// try self.init(path: "/dev/urandom") +// } +//} - return bytes - } +#endif - /// Get a random array of Bytes - public func bytes(count: Int) throws -> Bytes { - return try read(numBytes: count).map({ Byte(bitPattern: $0) }) - } -} -extension URandom: EmptyInitializable { - public convenience init() throws { - try self.init(path: "/dev/urandom") +extension Data { + /// Returns cryptographically secure random data. + /// Not safe. Needs to be replaced. See https://forums.swift.org/t/random-data-uint8-random-or-secrandomcopybytes/56165 + /// + /// - Parameter length: Length of the data in bytes. + /// - Returns: Generated data of the specified length. + public static func random(length: Int) throws -> Data { + return Data((0 ..< length).map { _ in UInt8.random(in: UInt8.min ... UInt8.max) }) } } - -#endif From 60b181b68d76a64e6ffc326af68b874d042a4922 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sun, 30 Oct 2022 17:01:57 -0700 Subject: [PATCH 21/37] Add try? --- Sources/Core/Structure/SECP256k1.swift | 2 +- Sources/Core/Utility/Data+Extension.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Core/Structure/SECP256k1.swift b/Sources/Core/Structure/SECP256k1.swift index 9e706e553..818a9221e 100755 --- a/Sources/Core/Structure/SECP256k1.swift +++ b/Sources/Core/Structure/SECP256k1.swift @@ -338,7 +338,7 @@ extension SECP256K1 { internal static func randomBytes(length: Int) -> Data? { #if os(Linux) // return Data(URandom().bytes(count: length)) - return Data.random(length: length) + return try? Data.random(length: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 8de0473d9..4e5ab3d85 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -44,7 +44,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) // return Data(URandom().bytes(count: length)) - return Data.random(length: length) + return try? Data.random(length: length) #else for _ in 0...1024 { var data = Data(repeating: 0, count: length) From 5976670dbbc80ce5c9009537b53ecaef192f5bc0 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Sun, 30 Oct 2022 17:13:56 -0700 Subject: [PATCH 22/37] Remove force unwraps in unit test --- .../localTests/LocalTestCase.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Tests/web3swiftTests/localTests/LocalTestCase.swift b/Tests/web3swiftTests/localTests/LocalTestCase.swift index 38b9198e1..6eb3891b6 100644 --- a/Tests/web3swiftTests/localTests/LocalTestCase.swift +++ b/Tests/web3swiftTests/localTests/LocalTestCase.swift @@ -8,31 +8,39 @@ import web3swift // SuperClass that all local tests should be derived from // while this class does show up in the navigator, it has no associated tests class LocalTestCase: XCTestCase { + + enum TestError: Error { + case testError + } static let url = URL(string: "http://127.0.0.1:8545")! override func setUp() async throws { - let web3 = try! await Web3.new(LocalTestCase.url) + let web3 = try await Web3.new(LocalTestCase.url) - let block = try! await web3.eth.blockNumber() + let block = try await web3.eth.blockNumber() if block >= 25 { return } print("\n ****** Preloading Ganache (\(25 - block) blocks) *****\n") - let allAddresses = try! await web3.eth.ownedAccounts() + let allAddresses = try await web3.eth.ownedAccounts() let sendToAddress = allAddresses[0] - let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2) - let value = Utilities.parseToBigUInt("1.0", units: .eth)! + guard let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2), + let value = Utilities.parseToBigUInt("1.0", units: .eth) else { + throw TestError.testError + } let from = allAddresses[0] - let writeTX = contract!.createWriteOperation("fallback")! + guard let writeTX = contract.createWriteOperation("fallback") else { + throw TestError.testError + } writeTX.transaction.from = from writeTX.transaction.value = value writeTX.transaction.gasLimitPolicy = .manual(78423) writeTX.transaction.gasPricePolicy = .manual(20000000000) for _ in block..<25 { - let _ = try! await writeTX.writeToChain(password: "") + let _ = try await writeTX.writeToChain(password: "") } } } From 84528e2104c9adaab837cd3a201e990ff9ecf8aa Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Mon, 31 Oct 2022 13:38:01 -0700 Subject: [PATCH 23/37] Force actions to run --- Sources/Core/Utility/Data+Extension.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Core/Utility/Data+Extension.swift b/Sources/Core/Utility/Data+Extension.swift index 4e5ab3d85..049573f93 100755 --- a/Sources/Core/Utility/Data+Extension.swift +++ b/Sources/Core/Utility/Data+Extension.swift @@ -43,7 +43,7 @@ extension Data { public static func randomBytes(length: Int) -> Data? { #if os(Linux) -// return Data(URandom().bytes(count: length)) +// return Data(URandom().bytes(count: length)) return try? Data.random(length: length) #else for _ in 0...1024 { From cdf4ad492eb8c5cea639864ee09203ad6ac869b8 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Mon, 31 Oct 2022 14:14:07 -0700 Subject: [PATCH 24/37] Update Ubuntu actions --- .github/workflows/ubuntu.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 1a5a773be..9521c2a8c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -17,7 +17,15 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Resolve dependencies + run: swift package resolve - name: Build run: swift build - - name: Run tests - run: swift test + - name: Start ganache in background + run: ganache & + - name: Wait till ganache starts + run: sleep 1 + - name: Run local tests + run: swift test --skip-build -c debug --filter localTests + - name: Run remote tests + run: swift test --skip-build -c debug --filter remoteTests From 616168fff5ac3a80eaeab498aa91b93c301be4da Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Mon, 31 Oct 2022 14:18:14 -0700 Subject: [PATCH 25/37] Run tests in single step --- .github/workflows/ubuntu.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 9521c2a8c..a9663966c 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -25,7 +25,9 @@ jobs: run: ganache & - name: Wait till ganache starts run: sleep 1 - - name: Run local tests - run: swift test --skip-build -c debug --filter localTests - - name: Run remote tests - run: swift test --skip-build -c debug --filter remoteTests + - name: Run tests + run: swift test +# - name: Run local tests +# run: swift test --skip-build -c debug --filter localTests +# - name: Run remote tests +# run: swift test --skip-build -c debug --filter remoteTests From bea91b5d00849f11417029192ce4937cb736a29b Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Mon, 31 Oct 2022 14:21:52 -0700 Subject: [PATCH 26/37] Install ganache --- .github/workflows/ubuntu.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index a9663966c..6a7b7f5ca 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -21,6 +21,8 @@ jobs: run: swift package resolve - name: Build run: swift build + - name: Install ganache + run: npm install ganache --global - name: Start ganache in background run: ganache & - name: Wait till ganache starts From ab991d53a4652a081db50fcef9d34a95a5ea8d2b Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Mon, 31 Oct 2022 14:27:34 -0700 Subject: [PATCH 27/37] Install Node --- .github/workflows/ubuntu.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 6a7b7f5ca..2033a83d4 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -17,6 +17,9 @@ jobs: steps: - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 - name: Resolve dependencies run: swift package resolve - name: Build From bb0a410cccddc2483930e4bf4eb4df996df6fd37 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Tue, 1 Nov 2022 12:12:37 -0700 Subject: [PATCH 28/37] ping localhost --- .github/workflows/ubuntu.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 2033a83d4..16e5eb0c3 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -30,8 +30,10 @@ jobs: run: ganache & - name: Wait till ganache starts run: sleep 1 - - name: Run tests - run: swift test + - name: Ping + run: nc -vz 127.0.01 8545 + # - name: Run tests + # run: swift test # - name: Run local tests # run: swift test --skip-build -c debug --filter localTests # - name: Run remote tests From 71117e3d643d1268a8bbf992ae87b5a8780db515 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Tue, 1 Nov 2022 12:16:55 -0700 Subject: [PATCH 29/37] install nc --- .github/workflows/ubuntu.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 16e5eb0c3..415ac614a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -30,6 +30,8 @@ jobs: run: ganache & - name: Wait till ganache starts run: sleep 1 + - name: install nc + run: apt-get update && apt-get install -y netcat - name: Ping run: nc -vz 127.0.01 8545 # - name: Run tests From 3cdb52885d9ee506823d183b201e6a7bc95c6c41 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Tue, 1 Nov 2022 12:23:08 -0700 Subject: [PATCH 30/37] remote tests only --- .github/workflows/ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 415ac614a..e109cfec3 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -38,5 +38,5 @@ jobs: # run: swift test # - name: Run local tests # run: swift test --skip-build -c debug --filter localTests -# - name: Run remote tests -# run: swift test --skip-build -c debug --filter remoteTests + - name: Run remote tests + run: swift test --skip-build -c debug --filter remoteTests From 1f51faf0063dd060850f4146b682ee3c537f66cb Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Tue, 1 Nov 2022 12:27:19 -0700 Subject: [PATCH 31/37] fix yaml error --- .github/workflows/ubuntu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e109cfec3..22c539c2b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -38,5 +38,5 @@ jobs: # run: swift test # - name: Run local tests # run: swift test --skip-build -c debug --filter localTests - - name: Run remote tests - run: swift test --skip-build -c debug --filter remoteTests + - name: Run remote tests + run: swift test --skip-build -c debug --filter remoteTests From 96191e95661934668028f97a80114a9f3e00c5e1 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Tue, 1 Nov 2022 12:37:57 -0700 Subject: [PATCH 32/37] Revert to default swift test --- .github/workflows/ubuntu.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 22c539c2b..ecd234d80 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -34,9 +34,9 @@ jobs: run: apt-get update && apt-get install -y netcat - name: Ping run: nc -vz 127.0.01 8545 - # - name: Run tests - # run: swift test -# - name: Run local tests -# run: swift test --skip-build -c debug --filter localTests - - name: Run remote tests - run: swift test --skip-build -c debug --filter remoteTests + - name: Run tests + run: swift test + # - name: Run local tests + # run: swift test --skip-build -c debug --filter localTests + # - name: Run remote tests + # run: swift test --skip-build -c debug --filter remoteTests From b7b77a45fb9514b30d20e465293fcc563dc9d6b2 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Wed, 2 Nov 2022 07:42:33 -0700 Subject: [PATCH 33/37] fix localhost typo --- .github/workflows/ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index ecd234d80..e81d22a20 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -33,7 +33,7 @@ jobs: - name: install nc run: apt-get update && apt-get install -y netcat - name: Ping - run: nc -vz 127.0.01 8545 + run: nc -vz 127.0.0.1 8545 - name: Run tests run: swift test # - name: Run local tests From f3c7125b44ff6db46d4e31aae4f33436d2225319 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Wed, 2 Nov 2022 07:46:39 -0700 Subject: [PATCH 34/37] Intentional wrong port. Should fail --- .github/workflows/ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e81d22a20..935abbc84 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -33,7 +33,7 @@ jobs: - name: install nc run: apt-get update && apt-get install -y netcat - name: Ping - run: nc -vz 127.0.0.1 8545 + run: nc -vz 127.0.0.1 8547 - name: Run tests run: swift test # - name: Run local tests From 71ec91d565c6be11b26e80d3a488a4bc11817fa2 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Wed, 2 Nov 2022 07:52:31 -0700 Subject: [PATCH 35/37] revert to correct port --- .github/workflows/ubuntu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 935abbc84..e81d22a20 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -33,7 +33,7 @@ jobs: - name: install nc run: apt-get update && apt-get install -y netcat - name: Ping - run: nc -vz 127.0.0.1 8547 + run: nc -vz 127.0.0.1 8545 - name: Run tests run: swift test # - name: Run local tests From ce46ea7f1195f2e06a148421a56dbefc7c3c854e Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Thu, 3 Nov 2022 12:37:09 -0700 Subject: [PATCH 36/37] Update Ubunti CI script --- .github/workflows/ubuntu.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e81d22a20..6f4fa46eb 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -4,10 +4,25 @@ name: Ubuntu on: - push: - branches: [ "develop" ] - pull_request: - branches: [ "develop" ] +push: + branches: + - master + - develop + - hotfix + - unstable + paths: + - Packag*.swift + - web3swift.podspec + - Cartfile + - Sources/** + - 'Tests/**' + - 'web3swift*/**' + - '.github/workflows/**' +pull_request: + branches: + - master + - develop + - unstable jobs: build: @@ -36,7 +51,3 @@ jobs: run: nc -vz 127.0.0.1 8545 - name: Run tests run: swift test - # - name: Run local tests - # run: swift test --skip-build -c debug --filter localTests - # - name: Run remote tests - # run: swift test --skip-build -c debug --filter remoteTests From 7052ac70c74dfdceeb125fb3805e058aa514dde2 Mon Sep 17 00:00:00 2001 From: Ronald Mannak Date: Thu, 3 Nov 2022 12:45:08 -0700 Subject: [PATCH 37/37] =?UTF-8?q?The=20inevitable=20=E2=80=9CI=20love=20YA?= =?UTF-8?q?ML=E2=80=9D=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ubuntu.yml | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 6f4fa46eb..e4faacdf8 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -4,25 +4,25 @@ name: Ubuntu on: -push: - branches: - - master - - develop - - hotfix - - unstable - paths: - - Packag*.swift - - web3swift.podspec - - Cartfile - - Sources/** - - 'Tests/**' - - 'web3swift*/**' - - '.github/workflows/**' -pull_request: - branches: - - master - - develop - - unstable + push: + branches: + - master + - develop + - hotfix + - unstable + paths: + - Packag*.swift + - web3swift.podspec + - Cartfile + - Sources/** + - 'Tests/**' + - 'web3swift*/**' + - '.github/workflows/**' + pull_request: + branches: + - master + - develop + - unstable jobs: build: