From 141332137a4247d522c9a08fc7be555d4034399f Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 22:14:20 +0300 Subject: [PATCH 1/8] [CHANGE] Restructure Swift Package - Moved source files to Sources/Web3Swift - Moved test files to Tests/Web3SwiftTests - Moved libs on root - Moved ZKSync source files to Sources/Web3ZkSync --- Package.swift | 27 +++++++++---------- .../EthereumAccount+SignTransaction.swift | 0 .../Web3Swift}/Account/EthereumAccount.swift | 0 .../Account/EthereumKeyStorage+Password.swift | 0 .../Account/EthereumKeyStorage.swift | 0 .../Web3Swift}/Account/Signature.swift | 0 .../Web3Swift}/Account/TypedData.swift | 0 .../Client/BaseEthereumClient+Call.swift | 0 .../Client/BaseEthereumClient.swift | 0 .../Client/HTTP/EthereumHttpClient.swift | 0 .../Client/Models/EthereumAddress.swift | 0 .../Client/Models/EthereumBlock.swift | 0 .../Client/Models/EthereumBlockInfo.swift | 0 .../Client/Models/EthereumHeader.swift | 0 .../Client/Models/EthereumLog.swift | 0 .../Client/Models/EthereumNetwork.swift | 0 .../Client/Models/EthereumSubscription.swift | 0 .../Client/Models/EthereumSyncStatus.swift | 0 .../Client/Models/EthereumTransaction.swift | 0 .../Models/EthereumTransactionReceipt.swift | 0 .../EventLoopGroupProvider.swift | 0 .../HttpNetworkProvider.swift | 0 .../Client/NetworkProviders/JSONRPC.swift | 0 .../NetworkProviderProtocol.swift | 0 .../WebSocketConfiguration.swift | 0 .../WebSocketNetworkProvider.swift | 0 .../Protocols/EthereumClientProtocol.swift | 0 .../Client/Protocols/EthereumProvider.swift | 0 .../Client/RecursiveLogCollector.swift | 0 .../Client/WSS/EthereumWebSocketClient.swift | 0 .../Web3Swift}/Contract/ABIDecoder.swift | 0 .../Web3Swift}/Contract/ABIEncoder.swift | 0 .../Web3Swift}/Contract/ABIRawType.swift | 0 .../Statically Typed/ABIDecoder+Static.swift | 0 .../Statically Typed/ABIEncoder+Static.swift | 0 .../Contract/Statically Typed/ABIEvent.swift | 0 .../Statically Typed/ABIFunction.swift | 0 .../ABIFunctionEncodable.swift | 0 .../Statically Typed/ABIFunctionEncoder.swift | 0 .../Statically Typed/ABIRawType+Static.swift | 0 .../Statically Typed/ABIRevertError.swift | 0 .../Contract/Statically Typed/ABITuple.swift | 0 .../EthereumClient+Static.swift | 0 .../Web3Swift}/ENS/ENSContracts.swift | 0 .../Web3Swift}/ENS/ENSMultiResolver.swift | 0 .../Web3Swift}/ENS/ENSResolver.swift | 0 .../Web3Swift}/ENS/ENSResponses.swift | 0 .../Web3Swift}/ENS/EthereumNameService.swift | 0 .../Web3Swift}/ERC1271/ERC1271.swift | 0 .../Web3Swift}/ERC1271/ERC1271Error.swift | 0 .../Web3Swift}/ERC1271/ERC1271Functions.swift | 0 .../Web3Swift}/ERC1271/ERC1271Responses.swift | 0 .../Web3Swift}/ERC165/ERC165.swift | 0 .../Web3Swift}/ERC20/ERC20.swift | 0 .../Web3Swift}/ERC20/ERC20Events.swift | 0 .../Web3Swift}/ERC20/ERC20Functions.swift | 0 .../Web3Swift}/ERC20/ERC20Responses.swift | 0 .../Web3Swift}/ERC721/ERC721.swift | 0 .../Web3Swift}/ERC721/ERC721Events.swift | 0 .../Web3Swift}/ERC721/ERC721Functions.swift | 0 .../Web3Swift}/ERC721/ERC721Responses.swift | 0 .../Extensions/ByteExtensions.swift | 0 .../Web3Swift}/Extensions/Data+Random.swift | 0 .../Web3Swift}/Extensions/Extensions.swift | 0 .../Web3Swift}/Extensions/HexExtensions.swift | 0 .../Extensions/KeccakExtensions.swift | 0 .../Extensions/ResultExtensions.swift | 0 .../Extensions/String+Numeric.swift | 0 .../Extensions/URLSessionExtensions.swift | 0 .../Web3Swift}/Multicall/Multicall.swift | 0 .../Multicall/MulticallContract.swift | 0 .../OffchainLookup/OffchainLookup.swift | 0 .../EthereumAccount+SignSIWERequest.swift | 0 .../Web3Swift}/SIWE/SiweMessage+Codable.swift | 0 .../Web3Swift}/SIWE/SiweMessage+RegEx.swift | 0 .../Web3Swift}/SIWE/SiweMessage+String.swift | 0 .../SIWE/SiweMessage+Validation.swift | 0 .../Web3Swift}/SIWE/SiweMessage.swift | 0 .../Web3Swift}/SIWE/SiweVerifier.swift | 0 .../Web3Swift}/Utils/AesUtil.swift | 0 .../Web3Swift}/Utils/HexUtil.swift | 0 .../Web3Swift}/Utils/KeyDerivation.swift | 0 .../Web3Swift}/Utils/KeyUtil.swift | 0 .../Web3Swift}/Utils/KeystoreUtil.swift | 0 .../Web3Swift}/Utils/PropertyWrappers.swift | 0 .../src => Sources/Web3Swift}/Utils/RLP.swift | 0 .../Web3ZKSync}/ABIFunction+ZKSync.swift | 0 .../Web3ZKSync}/EthereumAccount+ZKSync.swift | 0 .../Web3ZKSync}/ZKSyncProvider.swift | 0 .../Web3ZKSync}/ZKSyncTransaction.swift | 0 ...EthereumAccount+SignTransactionTests.swift | 0 .../EthereumAccount+SignTypedTests.swift | 0 .../Account/EthereumAccountTests.swift | 0 .../Account/EthereumKeyStorageTests.swift | 0 .../Account/cryptofights_712.json | 0 .../Account/ethermail_signTypedDataV4.json | 0 .../real_word_opensea_signTypedDataV4.json | 0 .../Address/EthereumAddressTests.swift | 0 .../Client/EthereumClientTests.swift | 0 .../Contract/ABIDecoderTests.swift | 0 .../Contract/ABIEncoderTests.swift | 0 .../Contract/ABIEventTests.swift | 0 .../Contract/ABIFunctionEncoderTests.swift | 0 .../Contract/ABIFunctionTests.swift | 0 .../ENS/ENSOffchainTests.swift | 0 .../Web3SwiftTests}/ENS/ENSTests.swift | 0 .../ERC1271/ERC1271Tests.swift | 0 .../Web3SwiftTests}/ERC165/ERC165Tests.swift | 0 .../Web3SwiftTests}/ERC20/ERC20Tests.swift | 0 .../Web3SwiftTests}/ERC721/ERC721Tests.swift | 0 .../Extensions/ByteExtensionsTests.swift | 0 .../Extensions/Data+RandomTests.swift | 0 .../Extensions/HexExtensionsTests.swift | 0 .../Extensions/KeccakExtensionsTests.swift | 0 .../Extensions/String+NumericTests.swift | 0 .../Mocks/TestEthereumKeyStorage.swift | 0 .../Multicall/MulticallTests.swift | 0 .../OffchainLookup/OffchainLookupTests.swift | 0 .../Web3SwiftTests}/Resources/ABITests.sol | 0 .../Resources/DummyOffchainResolver.sol | 0 .../Resources/ERC1271Checker.sol | 0 .../Resources/ERC1271CheckerBool.sol | 0 .../Resources/ERC165Sample.sol | 0 .../Resources/ERC721Metadata.json | 0 .../Web3SwiftTests}/Resources/Multicall2.sol | 0 .../Web3SwiftTests}/Resources/TestERC721.sol | 0 .../Web3SwiftTests}/Resources/rlptests.json | 0 .../Web3SwiftTests}/SIWE/SIWETests.swift | 0 .../SIWE/SiweMessageTests.swift | 0 .../SIWE/SiweVerifierTests.swift | 0 .../Web3SwiftTests}/TestConfig.swift | 0 .../Transaction/TransactionTests.swift | 0 .../Web3SwiftTests}/Utils/AesUtilTests.swift | 0 .../Web3SwiftTests}/Utils/HexUtilTests.swift | 0 .../Utils/KeyDerivationTests.swift | 0 .../Web3SwiftTests}/Utils/KeyUtilTests.swift | 0 .../Utils/KeystoreUtilTests.swift | 0 .../Web3SwiftTests}/Utils/RLPTests.swift | 0 .../ZKSync/EthereumClient+ZKSyncTests.swift | 0 .../ZKSync/ZKSyncTransactionTests.swift | 0 .../CryptoSwift/Array+Extensions.swift | 0 .../CryptoSwift/BatchedCollection.swift | 0 .../lib => libs}/CryptoSwift/Generics.swift | 0 .../lib => libs}/CryptoSwift/HMAC.swift | 0 .../CryptoSwift/Int+Extensions.swift | 0 .../lib => libs}/CryptoSwift/PBKDF2.swift | 0 .../lib => libs}/CryptoSwift/SHA2.swift | 0 .../CryptoSwift/UInt32+Extensions.swift | 0 .../CryptoSwift/UInt64+Extensions.swift | 0 .../lib => libs}/CryptoSwift/Utils.swift | 0 .../CryptoSwift/ZeroPadding.swift | 0 {web3swift/lib => libs}/aes/aes.c | 0 {web3swift/lib => libs}/aes/include/aes.h | 0 {web3swift/lib => libs}/aes/module.map | 0 .../lib => libs}/keccak-tiny/.clang-format | 0 .../keccak-tiny/include/keccak-tiny.h | 0 .../lib => libs}/keccak-tiny/keccak-tiny.c | 0 .../lib => libs}/keccak-tiny/module.map | 0 scripts/prepareForPush.sh | 2 -- scripts/runSwiftFormat.sh | 6 ++--- scripts/setupKey.sh | 7 +++-- web3swift/web3swift.h | 16 ----------- 162 files changed, 21 insertions(+), 37 deletions(-) rename {web3swift/src => Sources/Web3Swift}/Account/EthereumAccount+SignTransaction.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Account/EthereumAccount.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Account/EthereumKeyStorage+Password.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Account/EthereumKeyStorage.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Account/Signature.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Account/TypedData.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/BaseEthereumClient+Call.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/BaseEthereumClient.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/HTTP/EthereumHttpClient.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumAddress.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumBlock.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumBlockInfo.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumHeader.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumLog.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumNetwork.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumSubscription.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumSyncStatus.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumTransaction.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Models/EthereumTransactionReceipt.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/EventLoopGroupProvider.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/HttpNetworkProvider.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/JSONRPC.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/NetworkProviderProtocol.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/WebSocketConfiguration.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/NetworkProviders/WebSocketNetworkProvider.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Protocols/EthereumClientProtocol.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/Protocols/EthereumProvider.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/RecursiveLogCollector.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Client/WSS/EthereumWebSocketClient.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/ABIDecoder.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/ABIEncoder.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/ABIRawType.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIDecoder+Static.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIEncoder+Static.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIEvent.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIFunction.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIFunctionEncodable.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIFunctionEncoder.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIRawType+Static.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABIRevertError.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/ABITuple.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Contract/Statically Typed/EthereumClient+Static.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ENS/ENSContracts.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ENS/ENSMultiResolver.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ENS/ENSResolver.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ENS/ENSResponses.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ENS/EthereumNameService.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC1271/ERC1271.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC1271/ERC1271Error.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC1271/ERC1271Functions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC1271/ERC1271Responses.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC165/ERC165.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC20/ERC20.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC20/ERC20Events.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC20/ERC20Functions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC20/ERC20Responses.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC721/ERC721.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC721/ERC721Events.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC721/ERC721Functions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/ERC721/ERC721Responses.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/ByteExtensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/Data+Random.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/Extensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/HexExtensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/KeccakExtensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/ResultExtensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/String+Numeric.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Extensions/URLSessionExtensions.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Multicall/Multicall.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Multicall/MulticallContract.swift (100%) rename {web3swift/src => Sources/Web3Swift}/OffchainLookup/OffchainLookup.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/EthereumAccount+SignSIWERequest.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweMessage+Codable.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweMessage+RegEx.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweMessage+String.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweMessage+Validation.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweMessage.swift (100%) rename {web3swift/src => Sources/Web3Swift}/SIWE/SiweVerifier.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/AesUtil.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/HexUtil.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/KeyDerivation.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/KeyUtil.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/KeystoreUtil.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/PropertyWrappers.swift (100%) rename {web3swift/src => Sources/Web3Swift}/Utils/RLP.swift (100%) rename {web3swift/src/ZKSync => Sources/Web3ZKSync}/ABIFunction+ZKSync.swift (100%) rename {web3swift/src/ZKSync => Sources/Web3ZKSync}/EthereumAccount+ZKSync.swift (100%) rename {web3swift/src/ZKSync => Sources/Web3ZKSync}/ZKSyncProvider.swift (100%) rename {web3swift/src/ZKSync => Sources/Web3ZKSync}/ZKSyncTransaction.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/EthereumAccount+SignTransactionTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/EthereumAccount+SignTypedTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/EthereumAccountTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/EthereumKeyStorageTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/cryptofights_712.json (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/ethermail_signTypedDataV4.json (100%) rename {web3sTests => Tests/Web3SwiftTests}/Account/real_word_opensea_signTypedDataV4.json (100%) rename {web3sTests => Tests/Web3SwiftTests}/Address/EthereumAddressTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Client/EthereumClientTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Contract/ABIDecoderTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Contract/ABIEncoderTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Contract/ABIEventTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Contract/ABIFunctionEncoderTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Contract/ABIFunctionTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ENS/ENSOffchainTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ENS/ENSTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ERC1271/ERC1271Tests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ERC165/ERC165Tests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ERC20/ERC20Tests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ERC721/ERC721Tests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Extensions/ByteExtensionsTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Extensions/Data+RandomTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Extensions/HexExtensionsTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Extensions/KeccakExtensionsTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Extensions/String+NumericTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Mocks/TestEthereumKeyStorage.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Multicall/MulticallTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/OffchainLookup/OffchainLookupTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/ABITests.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/DummyOffchainResolver.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/ERC1271Checker.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/ERC1271CheckerBool.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/ERC165Sample.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/ERC721Metadata.json (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/Multicall2.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/TestERC721.sol (100%) rename {web3sTests => Tests/Web3SwiftTests}/Resources/rlptests.json (100%) rename {web3sTests => Tests/Web3SwiftTests}/SIWE/SIWETests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/SIWE/SiweMessageTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/SIWE/SiweVerifierTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/TestConfig.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Transaction/TransactionTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/AesUtilTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/HexUtilTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/KeyDerivationTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/KeyUtilTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/KeystoreUtilTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/Utils/RLPTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ZKSync/EthereumClient+ZKSyncTests.swift (100%) rename {web3sTests => Tests/Web3SwiftTests}/ZKSync/ZKSyncTransactionTests.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/Array+Extensions.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/BatchedCollection.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/Generics.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/HMAC.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/Int+Extensions.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/PBKDF2.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/SHA2.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/UInt32+Extensions.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/UInt64+Extensions.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/Utils.swift (100%) rename {web3swift/lib => libs}/CryptoSwift/ZeroPadding.swift (100%) rename {web3swift/lib => libs}/aes/aes.c (100%) rename {web3swift/lib => libs}/aes/include/aes.h (100%) rename {web3swift/lib => libs}/aes/module.map (100%) rename {web3swift/lib => libs}/keccak-tiny/.clang-format (100%) rename {web3swift/lib => libs}/keccak-tiny/include/keccak-tiny.h (100%) rename {web3swift/lib => libs}/keccak-tiny/keccak-tiny.c (100%) rename {web3swift/lib => libs}/keccak-tiny/module.map (100%) delete mode 100644 web3swift/web3swift.h diff --git a/Package.swift b/Package.swift index 32f9386c..a9341cef 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.6 import PackageDescription let package = Package( @@ -13,11 +13,11 @@ let package = Package( .library(name: "web3-zksync.swift", targets: ["web3-zksync"]) ], dependencies: [ - .package(name: "BigInt", url: "https://github.com/attaswift/BigInt", from: "5.3.0"), - .package(name: "GenericJSON", url: "https://github.com/iwill/generic-json-swift", .upToNextMajor(from: "2.0.0")), + .package(url: "https://github.com/attaswift/BigInt", .upToNextMajor(from: "5.3.0")), + .package(url: "https://github.com/iwill/generic-json-swift", .upToNextMajor(from: "2.0.0")), .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", .upToNextMajor(from: "0.6.0")), - .package(url: "https://github.com/vapor/websocket-kit.git", from: "2.0.0"), - .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0") + .package(url: "https://github.com/vapor/websocket-kit.git", .upToNextMajor(from: "2.0.0")), + .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.0.0")) ], targets: [ .target( @@ -27,14 +27,13 @@ let package = Package( .target(name: "keccaktiny"), .target(name: "aes"), .target(name: "Internal_CryptoSwift_PBDKF2"), - "BigInt", - "GenericJSON", + .product(name: "BigInt", package: "BigInt"), + .product(name: "GenericJSON", package: "generic-json-swift"), .product(name: "secp256k1", package: "secp256k1.swift"), .product(name: "WebSocketKit", package: "websocket-kit"), .product(name: "Logging", package: "swift-log") ], - path: "web3swift/src", - exclude: ["ZKSync"] + path: "Sources/Web3Swift" ), .target( name: "web3-zksync", @@ -42,29 +41,29 @@ let package = Package( [ .target(name: "web3") ], - path: "web3swift/src/ZKSync" + path: "Sources/Web3ZKSync" ), .target( name: "keccaktiny", dependencies: [], - path: "web3swift/lib/keccak-tiny", + path: "libs/keccak-tiny", exclude: ["module.map"] ), .target( name: "aes", dependencies: [], - path: "web3swift/lib/aes", + path: "libs/aes", exclude: ["module.map"] ), .target( name: "Internal_CryptoSwift_PBDKF2", dependencies: [], - path: "web3swift/lib/CryptoSwift" + path: "libs/CryptoSwift" ), .testTarget( name: "web3swiftTests", dependencies: ["web3", "web3-zksync"], - path: "web3sTests", + path: "Tests/Web3SwiftTests", resources: [ .copy("Resources/rlptests.json"), .copy("Account/cryptofights_712.json"), diff --git a/web3swift/src/Account/EthereumAccount+SignTransaction.swift b/Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift similarity index 100% rename from web3swift/src/Account/EthereumAccount+SignTransaction.swift rename to Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift diff --git a/web3swift/src/Account/EthereumAccount.swift b/Sources/Web3Swift/Account/EthereumAccount.swift similarity index 100% rename from web3swift/src/Account/EthereumAccount.swift rename to Sources/Web3Swift/Account/EthereumAccount.swift diff --git a/web3swift/src/Account/EthereumKeyStorage+Password.swift b/Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift similarity index 100% rename from web3swift/src/Account/EthereumKeyStorage+Password.swift rename to Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift diff --git a/web3swift/src/Account/EthereumKeyStorage.swift b/Sources/Web3Swift/Account/EthereumKeyStorage.swift similarity index 100% rename from web3swift/src/Account/EthereumKeyStorage.swift rename to Sources/Web3Swift/Account/EthereumKeyStorage.swift diff --git a/web3swift/src/Account/Signature.swift b/Sources/Web3Swift/Account/Signature.swift similarity index 100% rename from web3swift/src/Account/Signature.swift rename to Sources/Web3Swift/Account/Signature.swift diff --git a/web3swift/src/Account/TypedData.swift b/Sources/Web3Swift/Account/TypedData.swift similarity index 100% rename from web3swift/src/Account/TypedData.swift rename to Sources/Web3Swift/Account/TypedData.swift diff --git a/web3swift/src/Client/BaseEthereumClient+Call.swift b/Sources/Web3Swift/Client/BaseEthereumClient+Call.swift similarity index 100% rename from web3swift/src/Client/BaseEthereumClient+Call.swift rename to Sources/Web3Swift/Client/BaseEthereumClient+Call.swift diff --git a/web3swift/src/Client/BaseEthereumClient.swift b/Sources/Web3Swift/Client/BaseEthereumClient.swift similarity index 100% rename from web3swift/src/Client/BaseEthereumClient.swift rename to Sources/Web3Swift/Client/BaseEthereumClient.swift diff --git a/web3swift/src/Client/HTTP/EthereumHttpClient.swift b/Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift similarity index 100% rename from web3swift/src/Client/HTTP/EthereumHttpClient.swift rename to Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift diff --git a/web3swift/src/Client/Models/EthereumAddress.swift b/Sources/Web3Swift/Client/Models/EthereumAddress.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumAddress.swift rename to Sources/Web3Swift/Client/Models/EthereumAddress.swift diff --git a/web3swift/src/Client/Models/EthereumBlock.swift b/Sources/Web3Swift/Client/Models/EthereumBlock.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumBlock.swift rename to Sources/Web3Swift/Client/Models/EthereumBlock.swift diff --git a/web3swift/src/Client/Models/EthereumBlockInfo.swift b/Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumBlockInfo.swift rename to Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift diff --git a/web3swift/src/Client/Models/EthereumHeader.swift b/Sources/Web3Swift/Client/Models/EthereumHeader.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumHeader.swift rename to Sources/Web3Swift/Client/Models/EthereumHeader.swift diff --git a/web3swift/src/Client/Models/EthereumLog.swift b/Sources/Web3Swift/Client/Models/EthereumLog.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumLog.swift rename to Sources/Web3Swift/Client/Models/EthereumLog.swift diff --git a/web3swift/src/Client/Models/EthereumNetwork.swift b/Sources/Web3Swift/Client/Models/EthereumNetwork.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumNetwork.swift rename to Sources/Web3Swift/Client/Models/EthereumNetwork.swift diff --git a/web3swift/src/Client/Models/EthereumSubscription.swift b/Sources/Web3Swift/Client/Models/EthereumSubscription.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumSubscription.swift rename to Sources/Web3Swift/Client/Models/EthereumSubscription.swift diff --git a/web3swift/src/Client/Models/EthereumSyncStatus.swift b/Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumSyncStatus.swift rename to Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift diff --git a/web3swift/src/Client/Models/EthereumTransaction.swift b/Sources/Web3Swift/Client/Models/EthereumTransaction.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumTransaction.swift rename to Sources/Web3Swift/Client/Models/EthereumTransaction.swift diff --git a/web3swift/src/Client/Models/EthereumTransactionReceipt.swift b/Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift similarity index 100% rename from web3swift/src/Client/Models/EthereumTransactionReceipt.swift rename to Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift diff --git a/web3swift/src/Client/NetworkProviders/EventLoopGroupProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/EventLoopGroupProvider.swift rename to Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift diff --git a/web3swift/src/Client/NetworkProviders/HttpNetworkProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/HttpNetworkProvider.swift rename to Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift diff --git a/web3swift/src/Client/NetworkProviders/JSONRPC.swift b/Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/JSONRPC.swift rename to Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift diff --git a/web3swift/src/Client/NetworkProviders/NetworkProviderProtocol.swift b/Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/NetworkProviderProtocol.swift rename to Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift diff --git a/web3swift/src/Client/NetworkProviders/WebSocketConfiguration.swift b/Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/WebSocketConfiguration.swift rename to Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift diff --git a/web3swift/src/Client/NetworkProviders/WebSocketNetworkProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift similarity index 100% rename from web3swift/src/Client/NetworkProviders/WebSocketNetworkProvider.swift rename to Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift diff --git a/web3swift/src/Client/Protocols/EthereumClientProtocol.swift b/Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift similarity index 100% rename from web3swift/src/Client/Protocols/EthereumClientProtocol.swift rename to Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift diff --git a/web3swift/src/Client/Protocols/EthereumProvider.swift b/Sources/Web3Swift/Client/Protocols/EthereumProvider.swift similarity index 100% rename from web3swift/src/Client/Protocols/EthereumProvider.swift rename to Sources/Web3Swift/Client/Protocols/EthereumProvider.swift diff --git a/web3swift/src/Client/RecursiveLogCollector.swift b/Sources/Web3Swift/Client/RecursiveLogCollector.swift similarity index 100% rename from web3swift/src/Client/RecursiveLogCollector.swift rename to Sources/Web3Swift/Client/RecursiveLogCollector.swift diff --git a/web3swift/src/Client/WSS/EthereumWebSocketClient.swift b/Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift similarity index 100% rename from web3swift/src/Client/WSS/EthereumWebSocketClient.swift rename to Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift diff --git a/web3swift/src/Contract/ABIDecoder.swift b/Sources/Web3Swift/Contract/ABIDecoder.swift similarity index 100% rename from web3swift/src/Contract/ABIDecoder.swift rename to Sources/Web3Swift/Contract/ABIDecoder.swift diff --git a/web3swift/src/Contract/ABIEncoder.swift b/Sources/Web3Swift/Contract/ABIEncoder.swift similarity index 100% rename from web3swift/src/Contract/ABIEncoder.swift rename to Sources/Web3Swift/Contract/ABIEncoder.swift diff --git a/web3swift/src/Contract/ABIRawType.swift b/Sources/Web3Swift/Contract/ABIRawType.swift similarity index 100% rename from web3swift/src/Contract/ABIRawType.swift rename to Sources/Web3Swift/Contract/ABIRawType.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIDecoder+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIDecoder+Static.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIEncoder+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIEncoder+Static.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIEvent.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIEvent.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIFunction.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIFunction.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIFunctionEncodable.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIFunctionEncodable.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIFunctionEncoder.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIFunctionEncoder.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIRawType+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIRawType+Static.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift diff --git a/web3swift/src/Contract/Statically Typed/ABIRevertError.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABIRevertError.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift diff --git a/web3swift/src/Contract/Statically Typed/ABITuple.swift b/Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/ABITuple.swift rename to Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift diff --git a/web3swift/src/Contract/Statically Typed/EthereumClient+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift similarity index 100% rename from web3swift/src/Contract/Statically Typed/EthereumClient+Static.swift rename to Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift diff --git a/web3swift/src/ENS/ENSContracts.swift b/Sources/Web3Swift/ENS/ENSContracts.swift similarity index 100% rename from web3swift/src/ENS/ENSContracts.swift rename to Sources/Web3Swift/ENS/ENSContracts.swift diff --git a/web3swift/src/ENS/ENSMultiResolver.swift b/Sources/Web3Swift/ENS/ENSMultiResolver.swift similarity index 100% rename from web3swift/src/ENS/ENSMultiResolver.swift rename to Sources/Web3Swift/ENS/ENSMultiResolver.swift diff --git a/web3swift/src/ENS/ENSResolver.swift b/Sources/Web3Swift/ENS/ENSResolver.swift similarity index 100% rename from web3swift/src/ENS/ENSResolver.swift rename to Sources/Web3Swift/ENS/ENSResolver.swift diff --git a/web3swift/src/ENS/ENSResponses.swift b/Sources/Web3Swift/ENS/ENSResponses.swift similarity index 100% rename from web3swift/src/ENS/ENSResponses.swift rename to Sources/Web3Swift/ENS/ENSResponses.swift diff --git a/web3swift/src/ENS/EthereumNameService.swift b/Sources/Web3Swift/ENS/EthereumNameService.swift similarity index 100% rename from web3swift/src/ENS/EthereumNameService.swift rename to Sources/Web3Swift/ENS/EthereumNameService.swift diff --git a/web3swift/src/ERC1271/ERC1271.swift b/Sources/Web3Swift/ERC1271/ERC1271.swift similarity index 100% rename from web3swift/src/ERC1271/ERC1271.swift rename to Sources/Web3Swift/ERC1271/ERC1271.swift diff --git a/web3swift/src/ERC1271/ERC1271Error.swift b/Sources/Web3Swift/ERC1271/ERC1271Error.swift similarity index 100% rename from web3swift/src/ERC1271/ERC1271Error.swift rename to Sources/Web3Swift/ERC1271/ERC1271Error.swift diff --git a/web3swift/src/ERC1271/ERC1271Functions.swift b/Sources/Web3Swift/ERC1271/ERC1271Functions.swift similarity index 100% rename from web3swift/src/ERC1271/ERC1271Functions.swift rename to Sources/Web3Swift/ERC1271/ERC1271Functions.swift diff --git a/web3swift/src/ERC1271/ERC1271Responses.swift b/Sources/Web3Swift/ERC1271/ERC1271Responses.swift similarity index 100% rename from web3swift/src/ERC1271/ERC1271Responses.swift rename to Sources/Web3Swift/ERC1271/ERC1271Responses.swift diff --git a/web3swift/src/ERC165/ERC165.swift b/Sources/Web3Swift/ERC165/ERC165.swift similarity index 100% rename from web3swift/src/ERC165/ERC165.swift rename to Sources/Web3Swift/ERC165/ERC165.swift diff --git a/web3swift/src/ERC20/ERC20.swift b/Sources/Web3Swift/ERC20/ERC20.swift similarity index 100% rename from web3swift/src/ERC20/ERC20.swift rename to Sources/Web3Swift/ERC20/ERC20.swift diff --git a/web3swift/src/ERC20/ERC20Events.swift b/Sources/Web3Swift/ERC20/ERC20Events.swift similarity index 100% rename from web3swift/src/ERC20/ERC20Events.swift rename to Sources/Web3Swift/ERC20/ERC20Events.swift diff --git a/web3swift/src/ERC20/ERC20Functions.swift b/Sources/Web3Swift/ERC20/ERC20Functions.swift similarity index 100% rename from web3swift/src/ERC20/ERC20Functions.swift rename to Sources/Web3Swift/ERC20/ERC20Functions.swift diff --git a/web3swift/src/ERC20/ERC20Responses.swift b/Sources/Web3Swift/ERC20/ERC20Responses.swift similarity index 100% rename from web3swift/src/ERC20/ERC20Responses.swift rename to Sources/Web3Swift/ERC20/ERC20Responses.swift diff --git a/web3swift/src/ERC721/ERC721.swift b/Sources/Web3Swift/ERC721/ERC721.swift similarity index 100% rename from web3swift/src/ERC721/ERC721.swift rename to Sources/Web3Swift/ERC721/ERC721.swift diff --git a/web3swift/src/ERC721/ERC721Events.swift b/Sources/Web3Swift/ERC721/ERC721Events.swift similarity index 100% rename from web3swift/src/ERC721/ERC721Events.swift rename to Sources/Web3Swift/ERC721/ERC721Events.swift diff --git a/web3swift/src/ERC721/ERC721Functions.swift b/Sources/Web3Swift/ERC721/ERC721Functions.swift similarity index 100% rename from web3swift/src/ERC721/ERC721Functions.swift rename to Sources/Web3Swift/ERC721/ERC721Functions.swift diff --git a/web3swift/src/ERC721/ERC721Responses.swift b/Sources/Web3Swift/ERC721/ERC721Responses.swift similarity index 100% rename from web3swift/src/ERC721/ERC721Responses.swift rename to Sources/Web3Swift/ERC721/ERC721Responses.swift diff --git a/web3swift/src/Extensions/ByteExtensions.swift b/Sources/Web3Swift/Extensions/ByteExtensions.swift similarity index 100% rename from web3swift/src/Extensions/ByteExtensions.swift rename to Sources/Web3Swift/Extensions/ByteExtensions.swift diff --git a/web3swift/src/Extensions/Data+Random.swift b/Sources/Web3Swift/Extensions/Data+Random.swift similarity index 100% rename from web3swift/src/Extensions/Data+Random.swift rename to Sources/Web3Swift/Extensions/Data+Random.swift diff --git a/web3swift/src/Extensions/Extensions.swift b/Sources/Web3Swift/Extensions/Extensions.swift similarity index 100% rename from web3swift/src/Extensions/Extensions.swift rename to Sources/Web3Swift/Extensions/Extensions.swift diff --git a/web3swift/src/Extensions/HexExtensions.swift b/Sources/Web3Swift/Extensions/HexExtensions.swift similarity index 100% rename from web3swift/src/Extensions/HexExtensions.swift rename to Sources/Web3Swift/Extensions/HexExtensions.swift diff --git a/web3swift/src/Extensions/KeccakExtensions.swift b/Sources/Web3Swift/Extensions/KeccakExtensions.swift similarity index 100% rename from web3swift/src/Extensions/KeccakExtensions.swift rename to Sources/Web3Swift/Extensions/KeccakExtensions.swift diff --git a/web3swift/src/Extensions/ResultExtensions.swift b/Sources/Web3Swift/Extensions/ResultExtensions.swift similarity index 100% rename from web3swift/src/Extensions/ResultExtensions.swift rename to Sources/Web3Swift/Extensions/ResultExtensions.swift diff --git a/web3swift/src/Extensions/String+Numeric.swift b/Sources/Web3Swift/Extensions/String+Numeric.swift similarity index 100% rename from web3swift/src/Extensions/String+Numeric.swift rename to Sources/Web3Swift/Extensions/String+Numeric.swift diff --git a/web3swift/src/Extensions/URLSessionExtensions.swift b/Sources/Web3Swift/Extensions/URLSessionExtensions.swift similarity index 100% rename from web3swift/src/Extensions/URLSessionExtensions.swift rename to Sources/Web3Swift/Extensions/URLSessionExtensions.swift diff --git a/web3swift/src/Multicall/Multicall.swift b/Sources/Web3Swift/Multicall/Multicall.swift similarity index 100% rename from web3swift/src/Multicall/Multicall.swift rename to Sources/Web3Swift/Multicall/Multicall.swift diff --git a/web3swift/src/Multicall/MulticallContract.swift b/Sources/Web3Swift/Multicall/MulticallContract.swift similarity index 100% rename from web3swift/src/Multicall/MulticallContract.swift rename to Sources/Web3Swift/Multicall/MulticallContract.swift diff --git a/web3swift/src/OffchainLookup/OffchainLookup.swift b/Sources/Web3Swift/OffchainLookup/OffchainLookup.swift similarity index 100% rename from web3swift/src/OffchainLookup/OffchainLookup.swift rename to Sources/Web3Swift/OffchainLookup/OffchainLookup.swift diff --git a/web3swift/src/SIWE/EthereumAccount+SignSIWERequest.swift b/Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift similarity index 100% rename from web3swift/src/SIWE/EthereumAccount+SignSIWERequest.swift rename to Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift diff --git a/web3swift/src/SIWE/SiweMessage+Codable.swift b/Sources/Web3Swift/SIWE/SiweMessage+Codable.swift similarity index 100% rename from web3swift/src/SIWE/SiweMessage+Codable.swift rename to Sources/Web3Swift/SIWE/SiweMessage+Codable.swift diff --git a/web3swift/src/SIWE/SiweMessage+RegEx.swift b/Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift similarity index 100% rename from web3swift/src/SIWE/SiweMessage+RegEx.swift rename to Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift diff --git a/web3swift/src/SIWE/SiweMessage+String.swift b/Sources/Web3Swift/SIWE/SiweMessage+String.swift similarity index 100% rename from web3swift/src/SIWE/SiweMessage+String.swift rename to Sources/Web3Swift/SIWE/SiweMessage+String.swift diff --git a/web3swift/src/SIWE/SiweMessage+Validation.swift b/Sources/Web3Swift/SIWE/SiweMessage+Validation.swift similarity index 100% rename from web3swift/src/SIWE/SiweMessage+Validation.swift rename to Sources/Web3Swift/SIWE/SiweMessage+Validation.swift diff --git a/web3swift/src/SIWE/SiweMessage.swift b/Sources/Web3Swift/SIWE/SiweMessage.swift similarity index 100% rename from web3swift/src/SIWE/SiweMessage.swift rename to Sources/Web3Swift/SIWE/SiweMessage.swift diff --git a/web3swift/src/SIWE/SiweVerifier.swift b/Sources/Web3Swift/SIWE/SiweVerifier.swift similarity index 100% rename from web3swift/src/SIWE/SiweVerifier.swift rename to Sources/Web3Swift/SIWE/SiweVerifier.swift diff --git a/web3swift/src/Utils/AesUtil.swift b/Sources/Web3Swift/Utils/AesUtil.swift similarity index 100% rename from web3swift/src/Utils/AesUtil.swift rename to Sources/Web3Swift/Utils/AesUtil.swift diff --git a/web3swift/src/Utils/HexUtil.swift b/Sources/Web3Swift/Utils/HexUtil.swift similarity index 100% rename from web3swift/src/Utils/HexUtil.swift rename to Sources/Web3Swift/Utils/HexUtil.swift diff --git a/web3swift/src/Utils/KeyDerivation.swift b/Sources/Web3Swift/Utils/KeyDerivation.swift similarity index 100% rename from web3swift/src/Utils/KeyDerivation.swift rename to Sources/Web3Swift/Utils/KeyDerivation.swift diff --git a/web3swift/src/Utils/KeyUtil.swift b/Sources/Web3Swift/Utils/KeyUtil.swift similarity index 100% rename from web3swift/src/Utils/KeyUtil.swift rename to Sources/Web3Swift/Utils/KeyUtil.swift diff --git a/web3swift/src/Utils/KeystoreUtil.swift b/Sources/Web3Swift/Utils/KeystoreUtil.swift similarity index 100% rename from web3swift/src/Utils/KeystoreUtil.swift rename to Sources/Web3Swift/Utils/KeystoreUtil.swift diff --git a/web3swift/src/Utils/PropertyWrappers.swift b/Sources/Web3Swift/Utils/PropertyWrappers.swift similarity index 100% rename from web3swift/src/Utils/PropertyWrappers.swift rename to Sources/Web3Swift/Utils/PropertyWrappers.swift diff --git a/web3swift/src/Utils/RLP.swift b/Sources/Web3Swift/Utils/RLP.swift similarity index 100% rename from web3swift/src/Utils/RLP.swift rename to Sources/Web3Swift/Utils/RLP.swift diff --git a/web3swift/src/ZKSync/ABIFunction+ZKSync.swift b/Sources/Web3ZKSync/ABIFunction+ZKSync.swift similarity index 100% rename from web3swift/src/ZKSync/ABIFunction+ZKSync.swift rename to Sources/Web3ZKSync/ABIFunction+ZKSync.swift diff --git a/web3swift/src/ZKSync/EthereumAccount+ZKSync.swift b/Sources/Web3ZKSync/EthereumAccount+ZKSync.swift similarity index 100% rename from web3swift/src/ZKSync/EthereumAccount+ZKSync.swift rename to Sources/Web3ZKSync/EthereumAccount+ZKSync.swift diff --git a/web3swift/src/ZKSync/ZKSyncProvider.swift b/Sources/Web3ZKSync/ZKSyncProvider.swift similarity index 100% rename from web3swift/src/ZKSync/ZKSyncProvider.swift rename to Sources/Web3ZKSync/ZKSyncProvider.swift diff --git a/web3swift/src/ZKSync/ZKSyncTransaction.swift b/Sources/Web3ZKSync/ZKSyncTransaction.swift similarity index 100% rename from web3swift/src/ZKSync/ZKSyncTransaction.swift rename to Sources/Web3ZKSync/ZKSyncTransaction.swift diff --git a/web3sTests/Account/EthereumAccount+SignTransactionTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift similarity index 100% rename from web3sTests/Account/EthereumAccount+SignTransactionTests.swift rename to Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift diff --git a/web3sTests/Account/EthereumAccount+SignTypedTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift similarity index 100% rename from web3sTests/Account/EthereumAccount+SignTypedTests.swift rename to Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift diff --git a/web3sTests/Account/EthereumAccountTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccountTests.swift similarity index 100% rename from web3sTests/Account/EthereumAccountTests.swift rename to Tests/Web3SwiftTests/Account/EthereumAccountTests.swift diff --git a/web3sTests/Account/EthereumKeyStorageTests.swift b/Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift similarity index 100% rename from web3sTests/Account/EthereumKeyStorageTests.swift rename to Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift diff --git a/web3sTests/Account/cryptofights_712.json b/Tests/Web3SwiftTests/Account/cryptofights_712.json similarity index 100% rename from web3sTests/Account/cryptofights_712.json rename to Tests/Web3SwiftTests/Account/cryptofights_712.json diff --git a/web3sTests/Account/ethermail_signTypedDataV4.json b/Tests/Web3SwiftTests/Account/ethermail_signTypedDataV4.json similarity index 100% rename from web3sTests/Account/ethermail_signTypedDataV4.json rename to Tests/Web3SwiftTests/Account/ethermail_signTypedDataV4.json diff --git a/web3sTests/Account/real_word_opensea_signTypedDataV4.json b/Tests/Web3SwiftTests/Account/real_word_opensea_signTypedDataV4.json similarity index 100% rename from web3sTests/Account/real_word_opensea_signTypedDataV4.json rename to Tests/Web3SwiftTests/Account/real_word_opensea_signTypedDataV4.json diff --git a/web3sTests/Address/EthereumAddressTests.swift b/Tests/Web3SwiftTests/Address/EthereumAddressTests.swift similarity index 100% rename from web3sTests/Address/EthereumAddressTests.swift rename to Tests/Web3SwiftTests/Address/EthereumAddressTests.swift diff --git a/web3sTests/Client/EthereumClientTests.swift b/Tests/Web3SwiftTests/Client/EthereumClientTests.swift similarity index 100% rename from web3sTests/Client/EthereumClientTests.swift rename to Tests/Web3SwiftTests/Client/EthereumClientTests.swift diff --git a/web3sTests/Contract/ABIDecoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift similarity index 100% rename from web3sTests/Contract/ABIDecoderTests.swift rename to Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift diff --git a/web3sTests/Contract/ABIEncoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift similarity index 100% rename from web3sTests/Contract/ABIEncoderTests.swift rename to Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift diff --git a/web3sTests/Contract/ABIEventTests.swift b/Tests/Web3SwiftTests/Contract/ABIEventTests.swift similarity index 100% rename from web3sTests/Contract/ABIEventTests.swift rename to Tests/Web3SwiftTests/Contract/ABIEventTests.swift diff --git a/web3sTests/Contract/ABIFunctionEncoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift similarity index 100% rename from web3sTests/Contract/ABIFunctionEncoderTests.swift rename to Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift diff --git a/web3sTests/Contract/ABIFunctionTests.swift b/Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift similarity index 100% rename from web3sTests/Contract/ABIFunctionTests.swift rename to Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift diff --git a/web3sTests/ENS/ENSOffchainTests.swift b/Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift similarity index 100% rename from web3sTests/ENS/ENSOffchainTests.swift rename to Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift diff --git a/web3sTests/ENS/ENSTests.swift b/Tests/Web3SwiftTests/ENS/ENSTests.swift similarity index 100% rename from web3sTests/ENS/ENSTests.swift rename to Tests/Web3SwiftTests/ENS/ENSTests.swift diff --git a/web3sTests/ERC1271/ERC1271Tests.swift b/Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift similarity index 100% rename from web3sTests/ERC1271/ERC1271Tests.swift rename to Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift diff --git a/web3sTests/ERC165/ERC165Tests.swift b/Tests/Web3SwiftTests/ERC165/ERC165Tests.swift similarity index 100% rename from web3sTests/ERC165/ERC165Tests.swift rename to Tests/Web3SwiftTests/ERC165/ERC165Tests.swift diff --git a/web3sTests/ERC20/ERC20Tests.swift b/Tests/Web3SwiftTests/ERC20/ERC20Tests.swift similarity index 100% rename from web3sTests/ERC20/ERC20Tests.swift rename to Tests/Web3SwiftTests/ERC20/ERC20Tests.swift diff --git a/web3sTests/ERC721/ERC721Tests.swift b/Tests/Web3SwiftTests/ERC721/ERC721Tests.swift similarity index 100% rename from web3sTests/ERC721/ERC721Tests.swift rename to Tests/Web3SwiftTests/ERC721/ERC721Tests.swift diff --git a/web3sTests/Extensions/ByteExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift similarity index 100% rename from web3sTests/Extensions/ByteExtensionsTests.swift rename to Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift diff --git a/web3sTests/Extensions/Data+RandomTests.swift b/Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift similarity index 100% rename from web3sTests/Extensions/Data+RandomTests.swift rename to Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift diff --git a/web3sTests/Extensions/HexExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift similarity index 100% rename from web3sTests/Extensions/HexExtensionsTests.swift rename to Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift diff --git a/web3sTests/Extensions/KeccakExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift similarity index 100% rename from web3sTests/Extensions/KeccakExtensionsTests.swift rename to Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift diff --git a/web3sTests/Extensions/String+NumericTests.swift b/Tests/Web3SwiftTests/Extensions/String+NumericTests.swift similarity index 100% rename from web3sTests/Extensions/String+NumericTests.swift rename to Tests/Web3SwiftTests/Extensions/String+NumericTests.swift diff --git a/web3sTests/Mocks/TestEthereumKeyStorage.swift b/Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift similarity index 100% rename from web3sTests/Mocks/TestEthereumKeyStorage.swift rename to Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift diff --git a/web3sTests/Multicall/MulticallTests.swift b/Tests/Web3SwiftTests/Multicall/MulticallTests.swift similarity index 100% rename from web3sTests/Multicall/MulticallTests.swift rename to Tests/Web3SwiftTests/Multicall/MulticallTests.swift diff --git a/web3sTests/OffchainLookup/OffchainLookupTests.swift b/Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift similarity index 100% rename from web3sTests/OffchainLookup/OffchainLookupTests.swift rename to Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift diff --git a/web3sTests/Resources/ABITests.sol b/Tests/Web3SwiftTests/Resources/ABITests.sol similarity index 100% rename from web3sTests/Resources/ABITests.sol rename to Tests/Web3SwiftTests/Resources/ABITests.sol diff --git a/web3sTests/Resources/DummyOffchainResolver.sol b/Tests/Web3SwiftTests/Resources/DummyOffchainResolver.sol similarity index 100% rename from web3sTests/Resources/DummyOffchainResolver.sol rename to Tests/Web3SwiftTests/Resources/DummyOffchainResolver.sol diff --git a/web3sTests/Resources/ERC1271Checker.sol b/Tests/Web3SwiftTests/Resources/ERC1271Checker.sol similarity index 100% rename from web3sTests/Resources/ERC1271Checker.sol rename to Tests/Web3SwiftTests/Resources/ERC1271Checker.sol diff --git a/web3sTests/Resources/ERC1271CheckerBool.sol b/Tests/Web3SwiftTests/Resources/ERC1271CheckerBool.sol similarity index 100% rename from web3sTests/Resources/ERC1271CheckerBool.sol rename to Tests/Web3SwiftTests/Resources/ERC1271CheckerBool.sol diff --git a/web3sTests/Resources/ERC165Sample.sol b/Tests/Web3SwiftTests/Resources/ERC165Sample.sol similarity index 100% rename from web3sTests/Resources/ERC165Sample.sol rename to Tests/Web3SwiftTests/Resources/ERC165Sample.sol diff --git a/web3sTests/Resources/ERC721Metadata.json b/Tests/Web3SwiftTests/Resources/ERC721Metadata.json similarity index 100% rename from web3sTests/Resources/ERC721Metadata.json rename to Tests/Web3SwiftTests/Resources/ERC721Metadata.json diff --git a/web3sTests/Resources/Multicall2.sol b/Tests/Web3SwiftTests/Resources/Multicall2.sol similarity index 100% rename from web3sTests/Resources/Multicall2.sol rename to Tests/Web3SwiftTests/Resources/Multicall2.sol diff --git a/web3sTests/Resources/TestERC721.sol b/Tests/Web3SwiftTests/Resources/TestERC721.sol similarity index 100% rename from web3sTests/Resources/TestERC721.sol rename to Tests/Web3SwiftTests/Resources/TestERC721.sol diff --git a/web3sTests/Resources/rlptests.json b/Tests/Web3SwiftTests/Resources/rlptests.json similarity index 100% rename from web3sTests/Resources/rlptests.json rename to Tests/Web3SwiftTests/Resources/rlptests.json diff --git a/web3sTests/SIWE/SIWETests.swift b/Tests/Web3SwiftTests/SIWE/SIWETests.swift similarity index 100% rename from web3sTests/SIWE/SIWETests.swift rename to Tests/Web3SwiftTests/SIWE/SIWETests.swift diff --git a/web3sTests/SIWE/SiweMessageTests.swift b/Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift similarity index 100% rename from web3sTests/SIWE/SiweMessageTests.swift rename to Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift diff --git a/web3sTests/SIWE/SiweVerifierTests.swift b/Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift similarity index 100% rename from web3sTests/SIWE/SiweVerifierTests.swift rename to Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift diff --git a/web3sTests/TestConfig.swift b/Tests/Web3SwiftTests/TestConfig.swift similarity index 100% rename from web3sTests/TestConfig.swift rename to Tests/Web3SwiftTests/TestConfig.swift diff --git a/web3sTests/Transaction/TransactionTests.swift b/Tests/Web3SwiftTests/Transaction/TransactionTests.swift similarity index 100% rename from web3sTests/Transaction/TransactionTests.swift rename to Tests/Web3SwiftTests/Transaction/TransactionTests.swift diff --git a/web3sTests/Utils/AesUtilTests.swift b/Tests/Web3SwiftTests/Utils/AesUtilTests.swift similarity index 100% rename from web3sTests/Utils/AesUtilTests.swift rename to Tests/Web3SwiftTests/Utils/AesUtilTests.swift diff --git a/web3sTests/Utils/HexUtilTests.swift b/Tests/Web3SwiftTests/Utils/HexUtilTests.swift similarity index 100% rename from web3sTests/Utils/HexUtilTests.swift rename to Tests/Web3SwiftTests/Utils/HexUtilTests.swift diff --git a/web3sTests/Utils/KeyDerivationTests.swift b/Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift similarity index 100% rename from web3sTests/Utils/KeyDerivationTests.swift rename to Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift diff --git a/web3sTests/Utils/KeyUtilTests.swift b/Tests/Web3SwiftTests/Utils/KeyUtilTests.swift similarity index 100% rename from web3sTests/Utils/KeyUtilTests.swift rename to Tests/Web3SwiftTests/Utils/KeyUtilTests.swift diff --git a/web3sTests/Utils/KeystoreUtilTests.swift b/Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift similarity index 100% rename from web3sTests/Utils/KeystoreUtilTests.swift rename to Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift diff --git a/web3sTests/Utils/RLPTests.swift b/Tests/Web3SwiftTests/Utils/RLPTests.swift similarity index 100% rename from web3sTests/Utils/RLPTests.swift rename to Tests/Web3SwiftTests/Utils/RLPTests.swift diff --git a/web3sTests/ZKSync/EthereumClient+ZKSyncTests.swift b/Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift similarity index 100% rename from web3sTests/ZKSync/EthereumClient+ZKSyncTests.swift rename to Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift diff --git a/web3sTests/ZKSync/ZKSyncTransactionTests.swift b/Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift similarity index 100% rename from web3sTests/ZKSync/ZKSyncTransactionTests.swift rename to Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift diff --git a/web3swift/lib/CryptoSwift/Array+Extensions.swift b/libs/CryptoSwift/Array+Extensions.swift similarity index 100% rename from web3swift/lib/CryptoSwift/Array+Extensions.swift rename to libs/CryptoSwift/Array+Extensions.swift diff --git a/web3swift/lib/CryptoSwift/BatchedCollection.swift b/libs/CryptoSwift/BatchedCollection.swift similarity index 100% rename from web3swift/lib/CryptoSwift/BatchedCollection.swift rename to libs/CryptoSwift/BatchedCollection.swift diff --git a/web3swift/lib/CryptoSwift/Generics.swift b/libs/CryptoSwift/Generics.swift similarity index 100% rename from web3swift/lib/CryptoSwift/Generics.swift rename to libs/CryptoSwift/Generics.swift diff --git a/web3swift/lib/CryptoSwift/HMAC.swift b/libs/CryptoSwift/HMAC.swift similarity index 100% rename from web3swift/lib/CryptoSwift/HMAC.swift rename to libs/CryptoSwift/HMAC.swift diff --git a/web3swift/lib/CryptoSwift/Int+Extensions.swift b/libs/CryptoSwift/Int+Extensions.swift similarity index 100% rename from web3swift/lib/CryptoSwift/Int+Extensions.swift rename to libs/CryptoSwift/Int+Extensions.swift diff --git a/web3swift/lib/CryptoSwift/PBKDF2.swift b/libs/CryptoSwift/PBKDF2.swift similarity index 100% rename from web3swift/lib/CryptoSwift/PBKDF2.swift rename to libs/CryptoSwift/PBKDF2.swift diff --git a/web3swift/lib/CryptoSwift/SHA2.swift b/libs/CryptoSwift/SHA2.swift similarity index 100% rename from web3swift/lib/CryptoSwift/SHA2.swift rename to libs/CryptoSwift/SHA2.swift diff --git a/web3swift/lib/CryptoSwift/UInt32+Extensions.swift b/libs/CryptoSwift/UInt32+Extensions.swift similarity index 100% rename from web3swift/lib/CryptoSwift/UInt32+Extensions.swift rename to libs/CryptoSwift/UInt32+Extensions.swift diff --git a/web3swift/lib/CryptoSwift/UInt64+Extensions.swift b/libs/CryptoSwift/UInt64+Extensions.swift similarity index 100% rename from web3swift/lib/CryptoSwift/UInt64+Extensions.swift rename to libs/CryptoSwift/UInt64+Extensions.swift diff --git a/web3swift/lib/CryptoSwift/Utils.swift b/libs/CryptoSwift/Utils.swift similarity index 100% rename from web3swift/lib/CryptoSwift/Utils.swift rename to libs/CryptoSwift/Utils.swift diff --git a/web3swift/lib/CryptoSwift/ZeroPadding.swift b/libs/CryptoSwift/ZeroPadding.swift similarity index 100% rename from web3swift/lib/CryptoSwift/ZeroPadding.swift rename to libs/CryptoSwift/ZeroPadding.swift diff --git a/web3swift/lib/aes/aes.c b/libs/aes/aes.c similarity index 100% rename from web3swift/lib/aes/aes.c rename to libs/aes/aes.c diff --git a/web3swift/lib/aes/include/aes.h b/libs/aes/include/aes.h similarity index 100% rename from web3swift/lib/aes/include/aes.h rename to libs/aes/include/aes.h diff --git a/web3swift/lib/aes/module.map b/libs/aes/module.map similarity index 100% rename from web3swift/lib/aes/module.map rename to libs/aes/module.map diff --git a/web3swift/lib/keccak-tiny/.clang-format b/libs/keccak-tiny/.clang-format similarity index 100% rename from web3swift/lib/keccak-tiny/.clang-format rename to libs/keccak-tiny/.clang-format diff --git a/web3swift/lib/keccak-tiny/include/keccak-tiny.h b/libs/keccak-tiny/include/keccak-tiny.h similarity index 100% rename from web3swift/lib/keccak-tiny/include/keccak-tiny.h rename to libs/keccak-tiny/include/keccak-tiny.h diff --git a/web3swift/lib/keccak-tiny/keccak-tiny.c b/libs/keccak-tiny/keccak-tiny.c similarity index 100% rename from web3swift/lib/keccak-tiny/keccak-tiny.c rename to libs/keccak-tiny/keccak-tiny.c diff --git a/web3swift/lib/keccak-tiny/module.map b/libs/keccak-tiny/module.map similarity index 100% rename from web3swift/lib/keccak-tiny/module.map rename to libs/keccak-tiny/module.map diff --git a/scripts/prepareForPush.sh b/scripts/prepareForPush.sh index 5b2b2d38..1339490d 100755 --- a/scripts/prepareForPush.sh +++ b/scripts/prepareForPush.sh @@ -1,7 +1,5 @@ #!/bin/sh -SWIFT_VERSION=5.3 - cd "$(dirname "$0")" ./runSwiftFormat.sh diff --git a/scripts/runSwiftFormat.sh b/scripts/runSwiftFormat.sh index a3e0fbf3..2c944d7f 100755 --- a/scripts/runSwiftFormat.sh +++ b/scripts/runSwiftFormat.sh @@ -1,6 +1,6 @@ #!/bin/sh -SWIFT_VERSION=5.3 +SWIFT_VERSION=5.10 cd "$(dirname "$0")" @@ -17,8 +17,8 @@ if ! which bin/swiftformat >/dev/null; then cd bin rm -r ./* - downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.50.3/swiftformat.artifactbundle.zip" - mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.50.3-macos/bin/swiftformat . + downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.54.3/swiftformat.artifactbundle.zip" + mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.54.3-macos/bin/swiftformat . find . -name "*Tmp" -type d -prune -exec rm -rf '{}' + for entry in ./* do diff --git a/scripts/setupKey.sh b/scripts/setupKey.sh index 49484d92..568be7fb 100755 --- a/scripts/setupKey.sh +++ b/scripts/setupKey.sh @@ -1,4 +1,7 @@ #!/bin/sh -# write first argument to a Test -echo "extension TestConfig {\nstatic let privateKey = \"$1\"\nstatic let publicKey = \"0xE78e5ecb061fE3DD1672dDDA7b5116213B23B99A\"\n}" > web3sTests/TestConfig_private.swift \ No newline at end of file +# Move one directory up from the script directory +cd "$(dirname "$0")/.." + +# Write the first argument to TestConfig_private.swift +echo "extension TestConfig {\nstatic let privateKey = \"$1\"\nstatic let publicKey = \"0xE78e5ecb061fE3DD1672dDDA7b5116213B23B99A\"\n}" > Tests/Web3SwiftTests/TestConfigPrivate.swift diff --git a/web3swift/web3swift.h b/web3swift/web3swift.h deleted file mode 100644 index 10cc9285..00000000 --- a/web3swift/web3swift.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// web3.swift -// Copyright © 2022 Argent Labs Limited. All rights reserved. -// - -#import - -//! Project version number for web3swift. -FOUNDATION_EXPORT double web3swiftVersionNumber; - -//! Project version string for web3swift. -FOUNDATION_EXPORT const unsigned char web3swiftVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - From fce6767898eb33bc2043ad001b9e3a290ac2df9f Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 21:21:41 +0300 Subject: [PATCH 2/8] [CHANGE] SwiftFormat Source Files --- .../EthereumAccount+SignTransaction.swift | 2 +- .../Web3Swift/Account/EthereumAccount.swift | 2 +- .../Account/EthereumKeyStorage+Password.swift | 2 +- .../Account/EthereumKeyStorage.swift | 14 +- Sources/Web3Swift/Account/Signature.swift | 2 +- Sources/Web3Swift/Account/TypedData.swift | 6 +- .../Client/BaseEthereumClient+Call.swift | 10 +- .../Web3Swift/Client/BaseEthereumClient.swift | 8 +- .../Client/HTTP/EthereumHttpClient.swift | 2 +- .../Client/Models/EthereumAddress.swift | 2 +- .../Client/Models/EthereumBlock.swift | 28 +- .../Client/Models/EthereumBlockInfo.swift | 2 +- .../Client/Models/EthereumHeader.swift | 2 +- .../Web3Swift/Client/Models/EthereumLog.swift | 2 +- .../Client/Models/EthereumNetwork.swift | 20 +- .../Client/Models/EthereumSubscription.swift | 10 +- .../Client/Models/EthereumSyncStatus.swift | 2 +- .../Client/Models/EthereumTransaction.swift | 2 +- .../Models/EthereumTransactionReceipt.swift | 2 +- .../EventLoopGroupProvider.swift | 2 +- .../HttpNetworkProvider.swift | 4 +- .../Client/NetworkProviders/JSONRPC.swift | 6 +- .../NetworkProviderProtocol.swift | 4 +- .../WebSocketConfiguration.swift | 2 +- .../WebSocketNetworkProvider.swift | 8 +- .../Protocols/EthereumClientProtocol.swift | 2 +- .../Client/Protocols/EthereumProvider.swift | 19 +- .../Client/RecursiveLogCollector.swift | 8 +- .../Client/WSS/EthereumWebSocketClient.swift | 2 +- Sources/Web3Swift/Contract/ABIDecoder.swift | 16 +- Sources/Web3Swift/Contract/ABIEncoder.swift | 32 +- Sources/Web3Swift/Contract/ABIRawType.swift | 58 ++-- .../Statically Typed/ABIDecoder+Static.swift | 2 +- .../Statically Typed/ABIEncoder+Static.swift | 4 +- .../Contract/Statically Typed/ABIEvent.swift | 2 +- .../Statically Typed/ABIFunction.swift | 2 +- .../ABIFunctionEncodable.swift | 4 +- .../Statically Typed/ABIFunctionEncoder.swift | 6 +- .../Statically Typed/ABIRawType+Static.swift | 4 +- .../Statically Typed/ABIRevertError.swift | 2 +- .../Contract/Statically Typed/ABITuple.swift | 2 +- .../EthereumClient+Static.swift | 10 +- Sources/Web3Swift/ENS/ENSContracts.swift | 27 +- Sources/Web3Swift/ENS/ENSMultiResolver.swift | 4 +- Sources/Web3Swift/ENS/ENSResolver.swift | 16 +- Sources/Web3Swift/ENS/ENSResponses.swift | 2 +- .../Web3Swift/ENS/EthereumNameService.swift | 6 +- Sources/Web3Swift/ERC1271/ERC1271.swift | 2 +- Sources/Web3Swift/ERC1271/ERC1271Error.swift | 2 +- .../Web3Swift/ERC1271/ERC1271Functions.swift | 2 +- .../Web3Swift/ERC1271/ERC1271Responses.swift | 8 +- Sources/Web3Swift/ERC165/ERC165.swift | 2 +- Sources/Web3Swift/ERC20/ERC20.swift | 2 +- Sources/Web3Swift/ERC20/ERC20Events.swift | 2 +- Sources/Web3Swift/ERC20/ERC20Functions.swift | 2 +- Sources/Web3Swift/ERC20/ERC20Responses.swift | 2 +- Sources/Web3Swift/ERC721/ERC721.swift | 6 +- Sources/Web3Swift/ERC721/ERC721Events.swift | 2 +- .../Web3Swift/ERC721/ERC721Functions.swift | 2 +- .../Web3Swift/ERC721/ERC721Responses.swift | 2 +- .../Web3Swift/Extensions/ByteExtensions.swift | 2 +- .../Web3Swift/Extensions/Data+Random.swift | 2 +- Sources/Web3Swift/Extensions/Extensions.swift | 2 +- .../Web3Swift/Extensions/HexExtensions.swift | 2 +- .../Extensions/KeccakExtensions.swift | 2 +- .../Extensions/ResultExtensions.swift | 4 +- .../Web3Swift/Extensions/String+Numeric.swift | 2 +- .../Extensions/URLSessionExtensions.swift | 6 +- Sources/Web3Swift/Multicall/Multicall.swift | 16 +- .../Multicall/MulticallContract.swift | 14 +- .../OffchainLookup/OffchainLookup.swift | 2 +- .../EthereumAccount+SignSIWERequest.swift | 2 +- .../Web3Swift/SIWE/SiweMessage+Codable.swift | 2 +- .../Web3Swift/SIWE/SiweMessage+RegEx.swift | 2 +- .../Web3Swift/SIWE/SiweMessage+String.swift | 10 +- .../SIWE/SiweMessage+Validation.swift | 4 +- Sources/Web3Swift/SIWE/SiweMessage.swift | 2 +- Sources/Web3Swift/SIWE/SiweVerifier.swift | 4 +- Sources/Web3Swift/Utils/AesUtil.swift | 4 +- Sources/Web3Swift/Utils/HexUtil.swift | 2 +- Sources/Web3Swift/Utils/KeyDerivation.swift | 18 +- Sources/Web3Swift/Utils/KeyUtil.swift | 2 +- Sources/Web3Swift/Utils/KeystoreUtil.swift | 2 +- .../Web3Swift/Utils/PropertyWrappers.swift | 2 +- Sources/Web3Swift/Utils/RLP.swift | 18 +- Sources/Web3ZKSync/ABIFunction+ZKSync.swift | 4 +- .../Web3ZKSync/EthereumAccount+ZKSync.swift | 2 +- Sources/Web3ZKSync/ZKSyncProvider.swift | 6 +- Sources/Web3ZKSync/ZKSyncTransaction.swift | 2 +- ...EthereumAccount+SignTransactionTests.swift | 16 +- .../EthereumAccount+SignTypedTests.swift | 39 ++- .../Account/EthereumAccountTests.swift | 24 +- .../Account/EthereumKeyStorageTests.swift | 15 +- .../Address/EthereumAddressTests.swift | 4 +- .../Client/EthereumClientTests.swift | 323 +++++++++--------- .../Contract/ABIDecoderTests.swift | 120 ++++--- .../Contract/ABIEncoderTests.swift | 11 +- .../Contract/ABIEventTests.swift | 35 +- .../Contract/ABIFunctionEncoderTests.swift | 143 ++++---- .../Contract/ABIFunctionTests.swift | 7 +- .../Web3SwiftTests/ENS/ENSOffchainTests.swift | 11 +- Tests/Web3SwiftTests/ENS/ENSTests.swift | 36 +- .../Web3SwiftTests/ERC1271/ERC1271Tests.swift | 5 +- Tests/Web3SwiftTests/ERC165/ERC165Tests.swift | 4 +- Tests/Web3SwiftTests/ERC20/ERC20Tests.swift | 10 +- Tests/Web3SwiftTests/ERC721/ERC721Tests.swift | 30 +- .../Extensions/ByteExtensionsTests.swift | 5 +- .../Extensions/Data+RandomTests.swift | 6 +- .../Extensions/HexExtensionsTests.swift | 9 +- .../Extensions/KeccakExtensionsTests.swift | 5 +- .../Extensions/String+NumericTests.swift | 6 +- .../Mocks/TestEthereumKeyStorage.swift | 35 +- .../Multicall/MulticallTests.swift | 8 +- .../OffchainLookup/OffchainLookupTests.swift | 20 +- Tests/Web3SwiftTests/SIWE/SIWETests.swift | 10 +- .../SIWE/SiweMessageTests.swift | 8 +- .../SIWE/SiweVerifierTests.swift | 6 +- Tests/Web3SwiftTests/TestConfig.swift | 16 +- .../Transaction/TransactionTests.swift | 58 ++-- Tests/Web3SwiftTests/Utils/AesUtilTests.swift | 10 +- Tests/Web3SwiftTests/Utils/HexUtilTests.swift | 22 +- .../Utils/KeyDerivationTests.swift | 11 +- Tests/Web3SwiftTests/Utils/KeyUtilTests.swift | 9 +- .../Utils/KeystoreUtilTests.swift | 23 +- Tests/Web3SwiftTests/Utils/RLPTests.swift | 11 +- .../ZKSync/EthereumClient+ZKSyncTests.swift | 9 +- .../ZKSync/ZKSyncTransactionTests.swift | 20 +- scripts/runSwiftFormat.sh | 4 +- 128 files changed, 863 insertions(+), 835 deletions(-) diff --git a/Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift b/Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift index 297b56e3..22f1b80c 100644 --- a/Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift +++ b/Sources/Web3Swift/Account/EthereumAccount+SignTransaction.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumAccount+SignTransaction.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Account/EthereumAccount.swift b/Sources/Web3Swift/Account/EthereumAccount.swift index 4c78bdf2..40b823ee 100644 --- a/Sources/Web3Swift/Account/EthereumAccount.swift +++ b/Sources/Web3Swift/Account/EthereumAccount.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumAccount.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift b/Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift index 5c085b24..4bee1c89 100644 --- a/Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift +++ b/Sources/Web3Swift/Account/EthereumKeyStorage+Password.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumKeyStorage+Password.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Account/EthereumKeyStorage.swift b/Sources/Web3Swift/Account/EthereumKeyStorage.swift index 377f73d4..68799bb1 100644 --- a/Sources/Web3Swift/Account/EthereumKeyStorage.swift +++ b/Sources/Web3Swift/Account/EthereumKeyStorage.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumKeyStorage.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -32,7 +32,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol { private let localFileName = "ethereumkey" private var addressPath: String? { - guard let address = address else { + guard let address else { return nil } if let url = folderPath { @@ -58,7 +58,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol { private let fileManager = FileManager.default public func storePrivateKey(key: Data) throws { - guard let localPath = localPath else { + guard let localPath else { throw EthereumKeyStorageError.failedToSave } @@ -70,7 +70,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol { } public func loadPrivateKey() throws -> Data { - guard let localPath = localPath else { + guard let localPath else { throw EthereumKeyStorageError.failedToLoad } @@ -84,7 +84,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol { extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol { public func fetchAccounts() throws -> [EthereumAddress] { - guard let folderPath = folderPath else { + guard let folderPath else { throw EthereumKeyStorageError.failedToLoad } @@ -139,7 +139,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol { public func deleteAllKeys() throws { do { - if let folderPath = folderPath { + if let folderPath { let directoryContents = try fileManager.contentsOfDirectory(atPath: folderPath.path) let addresses = directoryContents.filter({ $0.web3.isAddress || $0 == localFileName }) for address in addresses { @@ -154,7 +154,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol { public func deletePrivateKey(for address: EthereumAddress) throws { do { - if let folderPath = folderPath { + if let folderPath { let filePathName = folderPath.appendingPathComponent(address.asString()) try fileManager.removeItem(at: filePathName) } diff --git a/Sources/Web3Swift/Account/Signature.swift b/Sources/Web3Swift/Account/Signature.swift index ee7ecfc0..2726d54b 100644 --- a/Sources/Web3Swift/Account/Signature.swift +++ b/Sources/Web3Swift/Account/Signature.swift @@ -1,5 +1,5 @@ // -// web3.swift +// Signature.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Account/TypedData.swift b/Sources/Web3Swift/Account/TypedData.swift index cdc8d480..01c4383b 100644 --- a/Sources/Web3Swift/Account/TypedData.swift +++ b/Sources/Web3Swift/Account/TypedData.swift @@ -1,5 +1,5 @@ // -// web3.swift +// TypedData.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -61,8 +61,8 @@ extension TypedData { // Whole data blob hash to sign public func signableHash() throws -> Data { var data = Data([0x19, 0x01]) - data.append(try encodeData(data: domain, type: "EIP712Domain").web3.keccak256) - data.append(try encodeData(data: message, type: primaryType).web3.keccak256) + try data.append(encodeData(data: domain, type: "EIP712Domain").web3.keccak256) + try data.append(encodeData(data: message, type: primaryType).web3.keccak256) return data.web3.keccak256 } diff --git a/Sources/Web3Swift/Client/BaseEthereumClient+Call.swift b/Sources/Web3Swift/Client/BaseEthereumClient+Call.swift index fc9bae8d..560f1181 100644 --- a/Sources/Web3Swift/Client/BaseEthereumClient+Call.swift +++ b/Sources/Web3Swift/Client/BaseEthereumClient+Call.swift @@ -1,5 +1,5 @@ // -// web3.swift +// BaseEthereumClient+Call.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -48,7 +48,7 @@ extension BaseEthereumClient { func encode(to encoder: Encoder) throws { var container = encoder.unkeyedContainer() var nested = container.nestedContainer(keyedBy: TransactionCodingKeys.self) - if let from = from { + if let from { try nested.encode(from, forKey: .from) } try nested.encode(to, forKey: .to) @@ -212,11 +212,11 @@ fileprivate extension OffchainReadError { var isNextURLAllowed: Bool { switch self { case let .server(code, _): - return code >= 500 // 4xx responses -> Don't continue with next url + code >= 500 // 4xx responses -> Don't continue with next url case .network, .invalidParams, .invalidResponse: - return true + true case .tooManyRedirections: - return false + false } } } diff --git a/Sources/Web3Swift/Client/BaseEthereumClient.swift b/Sources/Web3Swift/Client/BaseEthereumClient.swift index c3b7e91c..9d6941bb 100644 --- a/Sources/Web3Swift/Client/BaseEthereumClient.swift +++ b/Sources/Web3Swift/Client/BaseEthereumClient.swift @@ -1,5 +1,5 @@ // -// web3.swift +// BaseEthereumClient.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -34,11 +34,11 @@ open class BaseEthereumClient: EthereumClientProtocol { func failureHandler(_ error: Error) -> EthereumClientError { if case let .executionError(result) = error as? JSONRPCError { - return EthereumClientError.executionError(result.error) + EthereumClientError.executionError(result.error) } else if case .executionError = error as? EthereumClientError, let error = error as? EthereumClientError { - return error + error } else { - return EthereumClientError.unexpectedReturnValue + EthereumClientError.unexpectedReturnValue } } } diff --git a/Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift b/Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift index de43b8eb..261c9366 100644 --- a/Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift +++ b/Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumHttpClient.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumAddress.swift b/Sources/Web3Swift/Client/Models/EthereumAddress.swift index 6850d91a..8ae4ec21 100644 --- a/Sources/Web3Swift/Client/Models/EthereumAddress.swift +++ b/Sources/Web3Swift/Client/Models/EthereumAddress.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumAddress.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumBlock.swift b/Sources/Web3Swift/Client/Models/EthereumBlock.swift index 53e29023..12314c0b 100644 --- a/Sources/Web3Swift/Client/Models/EthereumBlock.swift +++ b/Sources/Web3Swift/Client/Models/EthereumBlock.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumBlock.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -14,22 +14,22 @@ public enum EthereumBlock: Hashable { public var stringValue: String { switch self { case .Latest: - return "latest" + "latest" case .Earliest: - return "earliest" + "earliest" case .Pending: - return "pending" + "pending" case let .Number(int): - return int.web3.hexString + int.web3.hexString } } public var intValue: Int? { switch self { case let .Number(int): - return int + int default: - return nil + nil } } @@ -71,21 +71,21 @@ extension EthereumBlock: Comparable { static public func < (lhs: EthereumBlock, rhs: EthereumBlock) -> Bool { switch lhs { case .Earliest: - return false + false case .Latest: - return rhs != .Pending ? true : false + rhs != .Pending ? true : false case .Pending: - return true + true case let .Number(lhsInt): switch rhs { case .Earliest: - return false + false case .Latest: - return true + true case .Pending: - return true + true case let .Number(rhsInt): - return lhsInt < rhsInt + lhsInt < rhsInt } } } diff --git a/Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift b/Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift index b3bb6593..d585bc17 100644 --- a/Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift +++ b/Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumBlockInfo.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumHeader.swift b/Sources/Web3Swift/Client/Models/EthereumHeader.swift index 4a6a23a4..5acf47e7 100644 --- a/Sources/Web3Swift/Client/Models/EthereumHeader.swift +++ b/Sources/Web3Swift/Client/Models/EthereumHeader.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumHeader.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumLog.swift b/Sources/Web3Swift/Client/Models/EthereumLog.swift index 03f3cbe5..9e87784c 100644 --- a/Sources/Web3Swift/Client/Models/EthereumLog.swift +++ b/Sources/Web3Swift/Client/Models/EthereumLog.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumLog.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumNetwork.swift b/Sources/Web3Swift/Client/Models/EthereumNetwork.swift index 6d637b0a..b79a53e8 100644 --- a/Sources/Web3Swift/Client/Models/EthereumNetwork.swift +++ b/Sources/Web3Swift/Client/Models/EthereumNetwork.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumNetwork.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -12,33 +12,33 @@ public enum EthereumNetwork: Equatable, Decodable { public static func fromString(_ networkId: String) -> EthereumNetwork { switch networkId { case "1": - return .mainnet + .mainnet case "11155111": - return .sepolia + .sepolia default: - return .custom(networkId) + .custom(networkId) } } public var stringValue: String { switch self { case .mainnet: - return "1" + "1" case .sepolia: - return "11155111" + "11155111" case let .custom(str): - return str + str } } public var intValue: Int { switch self { case .mainnet: - return 1 + 1 case .sepolia: - return 11155111 + 11155111 case let .custom(str): - return Int(str) ?? 0 + Int(str) ?? 0 } } } diff --git a/Sources/Web3Swift/Client/Models/EthereumSubscription.swift b/Sources/Web3Swift/Client/Models/EthereumSubscription.swift index fc3e3efc..f8a4a1c4 100644 --- a/Sources/Web3Swift/Client/Models/EthereumSubscription.swift +++ b/Sources/Web3Swift/Client/Models/EthereumSubscription.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumSubscription.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -14,13 +14,13 @@ public enum EthereumSubscriptionType: Equatable, Hashable { var params: [EthereumSubscriptionParamElement] { switch self { case .newBlockHeaders: - return [.method("newHeads")] + [.method("newHeads")] case let .logs(params): - return [.method("logs"), .logsParams(params ?? .init(address: nil, topics: nil))] + [.method("logs"), .logsParams(params ?? .init(address: nil, topics: nil))] case .newPendingTransactions: - return [.method("newPendingTransactions")] + [.method("newPendingTransactions")] case .syncing: - return [.method("syncing")] + [.method("syncing")] } } } diff --git a/Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift b/Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift index 6368c855..cb766b32 100644 --- a/Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift +++ b/Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumSyncStatus.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumTransaction.swift b/Sources/Web3Swift/Client/Models/EthereumTransaction.swift index deedf9c4..67d07c96 100644 --- a/Sources/Web3Swift/Client/Models/EthereumTransaction.swift +++ b/Sources/Web3Swift/Client/Models/EthereumTransaction.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumTransaction.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift b/Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift index 05b4a3d5..85f5b575 100644 --- a/Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift +++ b/Sources/Web3Swift/Client/Models/EthereumTransactionReceipt.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumTransactionReceipt.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift index 3c479223..5dbc676b 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/EventLoopGroupProvider.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EventLoopGroupProvider.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift index 616997b7..e6540c45 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/HttpNetworkProvider.swift @@ -1,5 +1,5 @@ // -// web3.swift +// HttpNetworkProvider.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -35,7 +35,7 @@ public class HttpNetworkProvider: NetworkProviderProtocol { request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.addValue("application/json", forHTTPHeaderField: "Accept") - headers.forEach { key, value in + for (key, value) in headers { request.addValue(value, forHTTPHeaderField: key) } diff --git a/Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift b/Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift index 5942f2f0..9c0f083f 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift @@ -1,5 +1,5 @@ // -// web3.swift +// JSONRPC.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -78,9 +78,9 @@ public enum JSONRPCError: Error { public var isExecutionError: Bool { switch self { case .executionError: - return true + true default: - return false + false } } } diff --git a/Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift b/Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift index 900872dd..e44d8f4b 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/NetworkProviderProtocol.swift @@ -1,5 +1,5 @@ // -// web3.swift +// NetworkProviderProtocol.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -18,7 +18,7 @@ public protocol NetworkProviderProtocol { } #if canImport(NIO) - internal protocol WebSocketNetworkProviderProtocol: NetworkProviderProtocol { + protocol WebSocketNetworkProviderProtocol: NetworkProviderProtocol { var delegate: EthereumWebSocketClientDelegate? { get set } var onReconnectCallback: (() -> Void)? { get set } var currentState: WebSocketState { get } diff --git a/Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift b/Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift index 94aeb42b..94d32d7f 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/WebSocketConfiguration.swift @@ -1,5 +1,5 @@ // -// web3.swift +// WebSocketConfiguration.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift b/Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift index bdacab8a..c82a278a 100644 --- a/Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift +++ b/Sources/Web3Swift/Client/NetworkProviders/WebSocketNetworkProvider.swift @@ -1,5 +1,5 @@ // -// web3.swift +// WebSocketNetworkProvider.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -295,7 +295,7 @@ ), on: eventLoopGroup ) { [weak self] ws in - guard let self = self else { + guard let self else { return } @@ -317,7 +317,7 @@ } ws.onText { [weak self] _, string in - guard let self = self else { + guard let self else { return } @@ -361,7 +361,7 @@ } ws.onClose.whenComplete { [weak self] value in - guard let self = self else { + guard let self else { return } diff --git a/Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift b/Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift index 7e6dfc72..b664e034 100644 --- a/Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift +++ b/Sources/Web3Swift/Client/Protocols/EthereumClientProtocol.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumClientProtocol.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Client/Protocols/EthereumProvider.swift b/Sources/Web3Swift/Client/Protocols/EthereumProvider.swift index 03f62fc0..ff48c708 100644 --- a/Sources/Web3Swift/Client/Protocols/EthereumProvider.swift +++ b/Sources/Web3Swift/Client/Protocols/EthereumProvider.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumProvider.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -145,11 +145,10 @@ extension EthereumRPCProtocol { } public func eth_estimateGas(_ transaction: EthereumTransaction) async throws -> BigUInt { - let value: BigUInt? - if let txValue = transaction.value, txValue > .zero { - value = txValue + let value: BigUInt? = if let txValue = transaction.value, txValue > .zero { + txValue } else { - value = nil + nil } let params = EstimateCallParams( @@ -271,11 +270,11 @@ extension EthereumRPCProtocol { func failureHandler(_ error: Error) -> EthereumClientError { if case let .executionError(result) = error as? JSONRPCError { - return EthereumClientError.executionError(result.error) + EthereumClientError.executionError(result.error) } else if case .executionError = error as? EthereumClientError, let error = error as? EthereumClientError { - return error + error } else { - return EthereumClientError.unexpectedReturnValue + EthereumClientError.unexpectedReturnValue } } } @@ -296,7 +295,7 @@ fileprivate struct EstimateCallParams: Encodable { func encode(to encoder: Encoder) throws { var container = encoder.unkeyedContainer() var nested = container.nestedContainer(keyedBy: TransactionCodingKeys.self) - if let from = from { + if let from { try nested.encode(from, forKey: .from) } try nested.encode(to, forKey: .to) @@ -308,7 +307,7 @@ fileprivate struct EstimateCallParams: Encodable { if let value = value.map(jsonRPCAmount) { try nested.encode(value, forKey: .value) } - if let data = data { + if let data { try nested.encode(data, forKey: .data) } } diff --git a/Sources/Web3Swift/Client/RecursiveLogCollector.swift b/Sources/Web3Swift/Client/RecursiveLogCollector.swift index 94ef9f75..4d8f3884 100644 --- a/Sources/Web3Swift/Client/RecursiveLogCollector.swift +++ b/Sources/Web3Swift/Client/RecursiveLogCollector.swift @@ -1,5 +1,5 @@ // -// web3.swift +// RecursiveLogCollector.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -49,11 +49,11 @@ struct RecursiveLogCollector { private func getMiddleBlock(from: EthereumBlock, to: EthereumBlock) async -> EthereumBlock? { func toBlockNumber() async -> Int? { if let toBlockNumber = to.intValue { - return toBlockNumber + toBlockNumber } else if let currentBlock = try? await getCurrentBlock(), let currentBlockNumber = currentBlock.intValue { - return currentBlockNumber + currentBlockNumber } else { - return nil + nil } } diff --git a/Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift b/Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift index c27cb75c..2fdd5e04 100644 --- a/Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift +++ b/Sources/Web3Swift/Client/WSS/EthereumWebSocketClient.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumWebSocketClient.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/ABIDecoder.swift b/Sources/Web3Swift/Contract/ABIDecoder.swift index 618cc38f..e6e30f25 100644 --- a/Sources/Web3Swift/Contract/ABIDecoder.swift +++ b/Sources/Web3Swift/Contract/ABIDecoder.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIDecoder.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -51,10 +51,10 @@ public class ABIDecoder { guard !data.isEmpty else { return [""] } - guard let offsetHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: offset)).first, let newOffset = Int(hex: offsetHex) else { + guard let offsetHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: offset)).first, let newOffset = Int(hex: offsetHex) else { throw ABIError.invalidValue } - guard let sizeHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first, let bint = BigInt(hex: sizeHex.web3.noHexPrefix) else { + guard let sizeHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first, let bint = BigInt(hex: sizeHex.web3.noHexPrefix) else { throw ABIError.invalidValue } let size = Int(bint) @@ -116,13 +116,13 @@ public class ABIDecoder { var result: [String] = [] var currentOffset = offset - guard let offsetHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: currentOffset)).first else { + guard let offsetHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: currentOffset)).first else { throw ABIError.invalidValue } currentOffset = Int(hex: offsetHex) ?? currentOffset - guard let lengthHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: currentOffset)).first else { + guard let lengthHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: currentOffset)).first else { throw ABIError.invalidValue } guard let length = Int(hex: lengthHex) else { @@ -140,12 +140,12 @@ public class ABIDecoder { var result: [String] = [] var newOffset = offset - guard let offsetHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first else { + guard let offsetHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first else { throw ABIError.invalidValue } newOffset = Int(hex: offsetHex) ?? newOffset - guard let sizeHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first else { + guard let sizeHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: newOffset)).first else { throw ABIError.invalidValue } guard var size = Int(hex: sizeHex) else { @@ -159,7 +159,7 @@ public class ABIDecoder { var result: [String] = [] if type.isDynamic { - guard let offsetHex = (try decode(data, forType: ABIRawType.FixedUInt(256), offset: offset)).first else { + guard let offsetHex = try (decode(data, forType: ABIRawType.FixedUInt(256), offset: offset)).first else { throw ABIError.invalidValue } diff --git a/Sources/Web3Swift/Contract/ABIEncoder.swift b/Sources/Web3Swift/Contract/ABIEncoder.swift index 78656ce7..f31ccc4e 100644 --- a/Sources/Web3Swift/Contract/ABIEncoder.swift +++ b/Sources/Web3Swift/Contract/ABIEncoder.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIEncoder.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -14,30 +14,30 @@ public class ABIEncoder { public var bytes: [UInt8] { switch self { case let .value(bytes: encoded, _, _): - return encoded + encoded case let .container(values, _, _): - return values.flatMap(\.bytes) + values.flatMap(\.bytes) } } var isDynamic: Bool { switch self { case let .value(_, isDynamic, _): - return isDynamic + isDynamic case let .container(_, isDynamic, _): - return isDynamic + isDynamic } } var staticLength: Int { switch self { case let .value(_, _, staticLength): - return staticLength + staticLength case let .container(values, isDynamic, _): if isDynamic { - return 32 + 32 } else { - return values.map(\.staticLength).reduce(0, +) + values.map(\.staticLength).reduce(0, +) } } } @@ -136,11 +136,10 @@ public class ABIEncoder { throw ABIError.invalidValue } let len = try encodeRaw(String(bytes.count), forType: ABIRawType.FixedUInt(256)).bytes - let pack: Int - if bytes.isEmpty { - pack = 0 + let pack: Int = if bytes.isEmpty { + 0 } else { - pack = (bytes.count - (bytes.count % 32)) / 32 + 1 + (bytes.count - (bytes.count % 32)) / 32 + 1 } if padded { @@ -174,11 +173,10 @@ public class ABIEncoder { } let len = try encodeRaw(String(size), forType: ABIRawType.FixedUInt(256)).bytes - let pack: Int - if bytes.isEmpty { - pack = 0 + let pack: Int = if bytes.isEmpty { + 0 } else { - pack = (bytes.count - (bytes.count % 32)) / 32 + 1 + (bytes.count - (bytes.count % 32)) / 32 + 1 } encoded = len + bytes + [UInt8](repeating: 0x00, count: pack * 32 - bytes.count) @@ -214,7 +212,7 @@ extension Array where Element == ABIEncoder.EncodedValue { try forEach { element in switch element { case let .container(values, isDynamic, size): - try encode(try values.encoded(isDynamic: isDynamic), isDynamic, size) + try encode(values.encoded(isDynamic: isDynamic), isDynamic, size) case let .value(bytes, isDynamic, _): try encode(bytes, isDynamic, nil) } diff --git a/Sources/Web3Swift/Contract/ABIRawType.swift b/Sources/Web3Swift/Contract/ABIRawType.swift index d16be910..7772fbac 100644 --- a/Sources/Web3Swift/Contract/ABIRawType.swift +++ b/Sources/Web3Swift/Contract/ABIRawType.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIRawType.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -97,82 +97,82 @@ extension ABIRawType: RawRepresentable { public var rawValue: String { switch self { - case let .FixedUInt(size): return "uint\(size)" - case let .FixedInt(size): return "int\(size)" - case .FixedAddress: return "address" - case .FixedBool: return "bool" - case let .FixedBytes(size): return "bytes\(size)" - case .DynamicBytes: return "bytes" - case .DynamicString: return "string" - case let .FixedArray(type, size): return "\(type.rawValue)[\(size)]" - case let .DynamicArray(type): return "\(type.rawValue)[]" - case let .Tuple(types): return "(\(types.map(\.rawValue).joined(separator: ",")))" + case let .FixedUInt(size): "uint\(size)" + case let .FixedInt(size): "int\(size)" + case .FixedAddress: "address" + case .FixedBool: "bool" + case let .FixedBytes(size): "bytes\(size)" + case .DynamicBytes: "bytes" + case .DynamicString: "string" + case let .FixedArray(type, size): "\(type.rawValue)[\(size)]" + case let .DynamicArray(type): "\(type.rawValue)[]" + case let .Tuple(types): "(\(types.map(\.rawValue).joined(separator: ",")))" } } var isDynamic: Bool { switch self { case .DynamicBytes, .DynamicString, .DynamicArray: - return true + true case let .Tuple(types): - return !types.filter(\.isDynamic).isEmpty + !types.filter(\.isDynamic).isEmpty default: - return false + false } } var isArray: Bool { switch self { case .FixedArray, .DynamicArray: - return true + true default: - return false + false } } var isTuple: Bool { switch self { case .Tuple: - return true + true default: - return false + false } } var isPaddedInDynamic: Bool { switch self { case .FixedUInt, .FixedInt: - return true + true default: - return false + false } } var size: Int { switch self { case .FixedBool: - return 8 + 8 case .FixedAddress: - return 160 + 160 case let .FixedUInt(size), let .FixedInt(size): - return size / 8 + size / 8 case let .FixedBytes(size), let .FixedArray(_, size): - return size + size case .DynamicArray: - return -1 + -1 default: - return 0 + 0 } } var memory: Int { switch self { case let .FixedArray(type, size): - return type.memory * size + type.memory * size case let .Tuple(types): - return types.map(\.memory).reduce(0, +) + types.map(\.memory).reduce(0, +) default: - return 32 + 32 } } } diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift index 92c6480d..e44c61bb 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIDecoder+Static.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIDecoder+Static.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift index bdf37918..9cf95289 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIEncoder+Static.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIEncoder+Static.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -97,7 +97,7 @@ extension ABIEncoder { case let value as Data32: return try ABIEncoder.encodeRaw(String(bytes: value.rawData.web3.bytes), forType: Data32.rawType, padded: !packed) case let data as Data: - if let staticSize = staticSize { + if let staticSize { return try ABIEncoder.encodeRaw(String(bytes: data.web3.bytes), forType: .FixedBytes(staticSize), padded: !packed) } else { return try ABIEncoder.encodeRaw(String(bytes: data.web3.bytes), forType: type, padded: !packed) diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift index 1ced18b4..a85efc90 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIEvent.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIEvent.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift index 9cfe55d0..426e689d 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIFunction.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIFunction.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift index ab2bf3f3..6fb98876 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncodable.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIFunctionEncodable.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -19,7 +19,7 @@ extension ABIFunctionEncodable { let encoder = ABIFunctionEncoder(Self.name) try encode(to: encoder) let rawTypes = encoder.types - let methodId = String(hexFromBytes: try ABIFunctionEncoder.methodId(name: Self.name, types: rawTypes)) + let methodId = try String(hexFromBytes: ABIFunctionEncoder.methodId(name: Self.name, types: rawTypes)) var raw = data.web3.hexString guard raw.hasPrefix(methodId) else { diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift index 6cb58d50..b44f7f11 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIFunctionEncoder.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIFunctionEncoder.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -42,7 +42,7 @@ public class ABIFunctionEncoder { types.append(.DynamicArray(T.rawType)) } - internal var encodedValues = [ABIEncoder.EncodedValue]() + var encodedValues = [ABIEncoder.EncodedValue]() public init(_ name: String) { self.name = name @@ -50,7 +50,7 @@ public class ABIFunctionEncoder { public func encoded() throws -> Data { let methodId = try Self.methodId(name: name, types: types) - let allBytes = methodId + (try encodedValues.encoded(isDynamic: false)) + let allBytes = try methodId + (encodedValues.encoded(isDynamic: false)) return Data(allBytes) } diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift index 9a50d993..b368a649 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIRawType+Static.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIRawType+Static.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -119,7 +119,7 @@ extension URL: ABIType { extension ABITuple { public static var rawType: ABIRawType { - .Tuple(Self.types.map { $0.rawType }) + .Tuple(types.map { $0.rawType }) } public static var parser: ParserFunction { diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift b/Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift index f8df6d1f..726443b2 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABIRevertError.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIRevertError.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift b/Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift index 30655ab8..109636bd 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/ABITuple.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABITuple.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift b/Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift index e80384c0..87925b3b 100644 --- a/Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift +++ b/Sources/Web3Swift/Contract/Statically Typed/EthereumClient+Static.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumClient+Static.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -58,18 +58,18 @@ extension CallResolution { var failOnExecutionError: Bool { switch self { case let .noOffchain(fail): - return fail + fail case .offchainAllowed: - return true + true } } var allowsOffchain: Bool { switch self { case .noOffchain: - return false + false case .offchainAllowed: - return true + true } } } diff --git a/Sources/Web3Swift/ENS/ENSContracts.swift b/Sources/Web3Swift/ENS/ENSContracts.swift index fd82a67f..346993f0 100644 --- a/Sources/Web3Swift/ENS/ENSContracts.swift +++ b/Sources/Web3Swift/ENS/ENSContracts.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ENSContracts.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -14,11 +14,11 @@ public enum ENSContracts { public static func registryAddress(for network: EthereumNetwork) -> EthereumAddress? { switch network { case .mainnet: - return ENSContracts.RegistryAddress + ENSContracts.RegistryAddress case .sepolia: - return ENSContracts.RegistryAddress + ENSContracts.RegistryAddress default: - return nil + nil } } @@ -27,14 +27,13 @@ public enum ENSContracts { case name(String) var nameHash: Data { - let nameHash: String - switch self { + let nameHash: String = switch self { case let .address(address): - nameHash = ENSContracts.nameHash( + ENSContracts.nameHash( name: address.asString().web3.noHexPrefix + ".addr.reverse" ) case let .name(ens): - nameHash = ENSContracts.nameHash(name: ens) + ENSContracts.nameHash(name: ens) } return nameHash.web3.hexData ?? Data() } @@ -42,29 +41,29 @@ public enum ENSContracts { var dnsEncoded: Data { switch self { case let .address(address): - return ENSContracts.dnsEncode( + ENSContracts.dnsEncode( name: address.asString().web3.noHexPrefix + ".addr.reverse" ) case let .name(name): - return ENSContracts.dnsEncode(name: name) + ENSContracts.dnsEncode(name: name) } } var name: String? { switch self { case let .name(ens): - return ens + ens case .address: - return nil + nil } } var address: EthereumAddress? { switch self { case let .address(address): - return address + address case .name: - return nil + nil } } } diff --git a/Sources/Web3Swift/ENS/ENSMultiResolver.swift b/Sources/Web3Swift/ENS/ENSMultiResolver.swift index 8e2722f2..16f3bf5a 100644 --- a/Sources/Web3Swift/ENS/ENSMultiResolver.swift +++ b/Sources/Web3Swift/ENS/ENSMultiResolver.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ENSMultiResolver.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -190,7 +190,7 @@ extension EthereumNameService { private func resolveQueries(registryOutput: RegistryOutput) async throws -> [ResolverOutput] { var aggegator = Multicall.Aggregator() - registryOutput.queries.forEach { query in + for query in registryOutput.queries { switch query.parameter { case let .address(address): guard let registryOutput = registryOutput as? RegistryOutput else { diff --git a/Sources/Web3Swift/ENS/ENSResolver.swift b/Sources/Web3Swift/ENS/ENSResolver.swift index 50e0630f..788b8725 100644 --- a/Sources/Web3Swift/ENS/ENSResolver.swift +++ b/Sources/Web3Swift/ENS/ENSResolver.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ENSResolver.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -28,11 +28,10 @@ class ENSResolver { name: String, supportingWildcard mustSupportWildCard: Bool ) async throws -> EthereumAddress { - let wildcardResolution: Bool - if let supportsWildCard = supportsWildCard { - wildcardResolution = supportsWildCard + let wildcardResolution: Bool = if let supportsWildCard { + supportsWildCard } else { - wildcardResolution = try await supportsWildcard() + try await supportsWildcard() } supportsWildCard = wildcardResolution @@ -67,11 +66,10 @@ class ENSResolver { func resolve( address: EthereumAddress ) async throws -> String { - let wildcardResolution: Bool - if let supportsWildCard = supportsWildCard { - wildcardResolution = supportsWildCard + let wildcardResolution: Bool = if let supportsWildCard { + supportsWildCard } else { - wildcardResolution = try await supportsWildcard() + try await supportsWildcard() } supportsWildCard = wildcardResolution diff --git a/Sources/Web3Swift/ENS/ENSResponses.swift b/Sources/Web3Swift/ENS/ENSResponses.swift index 4164819e..f9307e83 100644 --- a/Sources/Web3Swift/ENS/ENSResponses.swift +++ b/Sources/Web3Swift/ENS/ENSResponses.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ENSResponses.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ENS/EthereumNameService.swift b/Sources/Web3Swift/ENS/EthereumNameService.swift index fd035782..69d90f76 100644 --- a/Sources/Web3Swift/ENS/EthereumNameService.swift +++ b/Sources/Web3Swift/ENS/EthereumNameService.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumNameService.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -155,9 +155,9 @@ fileprivate extension ResolutionMode { func callResolution(maxRedirects: Int) -> CallResolution { switch self { case .allowOffchainLookup: - return .offchainAllowed(maxRedirects: maxRedirects) + .offchainAllowed(maxRedirects: maxRedirects) case .onchain: - return .noOffchain(failOnExecutionError: true) + .noOffchain(failOnExecutionError: true) } } } diff --git a/Sources/Web3Swift/ERC1271/ERC1271.swift b/Sources/Web3Swift/ERC1271/ERC1271.swift index 3745ca7f..5103bcb6 100644 --- a/Sources/Web3Swift/ERC1271/ERC1271.swift +++ b/Sources/Web3Swift/ERC1271/ERC1271.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC1271.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC1271/ERC1271Error.swift b/Sources/Web3Swift/ERC1271/ERC1271Error.swift index c84e986b..5d65c774 100644 --- a/Sources/Web3Swift/ERC1271/ERC1271Error.swift +++ b/Sources/Web3Swift/ERC1271/ERC1271Error.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC1271Error.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC1271/ERC1271Functions.swift b/Sources/Web3Swift/ERC1271/ERC1271Functions.swift index 37896e27..92c110ca 100644 --- a/Sources/Web3Swift/ERC1271/ERC1271Functions.swift +++ b/Sources/Web3Swift/ERC1271/ERC1271Functions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC1271Functions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC1271/ERC1271Responses.swift b/Sources/Web3Swift/ERC1271/ERC1271Responses.swift index 62f204a0..c5b9c164 100644 --- a/Sources/Web3Swift/ERC1271/ERC1271Responses.swift +++ b/Sources/Web3Swift/ERC1271/ERC1271Responses.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC1271Responses.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -37,11 +37,11 @@ public enum ERC1271Responses { { data in switch data.first ?? "" { case "0x0000000000000000000000000000000000000000000000000000000000000000": - return EitherBoolOrData4.bool(false) + EitherBoolOrData4.bool(false) case "0x0000000000000000000000000000000000000000000000000000000000000001": - return EitherBoolOrData4.bool(true) + EitherBoolOrData4.bool(true) case let data: - return EitherBoolOrData4.data(try ABIDecoder.decode(data, to: Data.self).web3.bytes4) + try EitherBoolOrData4.data(ABIDecoder.decode(data, to: Data.self).web3.bytes4) } } } diff --git a/Sources/Web3Swift/ERC165/ERC165.swift b/Sources/Web3Swift/ERC165/ERC165.swift index eec491c2..e6bf3872 100644 --- a/Sources/Web3Swift/ERC165/ERC165.swift +++ b/Sources/Web3Swift/ERC165/ERC165.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC165.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC20/ERC20.swift b/Sources/Web3Swift/ERC20/ERC20.swift index 8810d0d9..fecdd8d4 100644 --- a/Sources/Web3Swift/ERC20/ERC20.swift +++ b/Sources/Web3Swift/ERC20/ERC20.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC20.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC20/ERC20Events.swift b/Sources/Web3Swift/ERC20/ERC20Events.swift index ad902bf2..2a15580f 100644 --- a/Sources/Web3Swift/ERC20/ERC20Events.swift +++ b/Sources/Web3Swift/ERC20/ERC20Events.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC20Events.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC20/ERC20Functions.swift b/Sources/Web3Swift/ERC20/ERC20Functions.swift index 451acabb..574b9e82 100644 --- a/Sources/Web3Swift/ERC20/ERC20Functions.swift +++ b/Sources/Web3Swift/ERC20/ERC20Functions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC20Functions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC20/ERC20Responses.swift b/Sources/Web3Swift/ERC20/ERC20Responses.swift index 6ffd0fdc..16a003a8 100644 --- a/Sources/Web3Swift/ERC20/ERC20Responses.swift +++ b/Sources/Web3Swift/ERC20/ERC20Responses.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC20Responses.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC721/ERC721.swift b/Sources/Web3Swift/ERC721/ERC721.swift index b577964e..9f4be0bd 100644 --- a/Sources/Web3Swift/ERC721/ERC721.swift +++ b/Sources/Web3Swift/ERC721/ERC721.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC721.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -68,7 +68,7 @@ open class ERC721: ERC165 { public class ERC721Metadata: ERC721 { public struct Token: Equatable, Decodable { - public typealias PropertyType = Equatable & Decodable + public typealias PropertyType = Decodable & Equatable public struct Property: Equatable, Decodable { public var description: T } @@ -98,7 +98,7 @@ public class ERC721Metadata: ERC721 { self.type = try? container.decode(String.self, forKey: .type) let properties = try? container.decode(Properties.self, forKey: .properties) - if let properties = properties { + if let properties { self.properties = properties } else { // try decoding properties from root directly diff --git a/Sources/Web3Swift/ERC721/ERC721Events.swift b/Sources/Web3Swift/ERC721/ERC721Events.swift index 3f5e2a88..1a668dfe 100644 --- a/Sources/Web3Swift/ERC721/ERC721Events.swift +++ b/Sources/Web3Swift/ERC721/ERC721Events.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC721Events.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC721/ERC721Functions.swift b/Sources/Web3Swift/ERC721/ERC721Functions.swift index 5ef44dd9..68ddc8c7 100644 --- a/Sources/Web3Swift/ERC721/ERC721Functions.swift +++ b/Sources/Web3Swift/ERC721/ERC721Functions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC721Functions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/ERC721/ERC721Responses.swift b/Sources/Web3Swift/ERC721/ERC721Responses.swift index 0886e143..c5ac6ce1 100644 --- a/Sources/Web3Swift/ERC721/ERC721Responses.swift +++ b/Sources/Web3Swift/ERC721/ERC721Responses.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ERC721Responses.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/ByteExtensions.swift b/Sources/Web3Swift/Extensions/ByteExtensions.swift index b951c8bb..e04f7a1d 100644 --- a/Sources/Web3Swift/Extensions/ByteExtensions.swift +++ b/Sources/Web3Swift/Extensions/ByteExtensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ByteExtensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/Data+Random.swift b/Sources/Web3Swift/Extensions/Data+Random.swift index c01cdfcc..5df0b0c3 100644 --- a/Sources/Web3Swift/Extensions/Data+Random.swift +++ b/Sources/Web3Swift/Extensions/Data+Random.swift @@ -1,5 +1,5 @@ // -// web3.swift +// Data+Random.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/Extensions.swift b/Sources/Web3Swift/Extensions/Extensions.swift index 8eabc16b..56aafede 100644 --- a/Sources/Web3Swift/Extensions/Extensions.swift +++ b/Sources/Web3Swift/Extensions/Extensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// Extensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/HexExtensions.swift b/Sources/Web3Swift/Extensions/HexExtensions.swift index 8d38f292..63279d34 100644 --- a/Sources/Web3Swift/Extensions/HexExtensions.swift +++ b/Sources/Web3Swift/Extensions/HexExtensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// HexExtensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/KeccakExtensions.swift b/Sources/Web3Swift/Extensions/KeccakExtensions.swift index 4f1728db..2b4a1580 100644 --- a/Sources/Web3Swift/Extensions/KeccakExtensions.swift +++ b/Sources/Web3Swift/Extensions/KeccakExtensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// KeccakExtensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/ResultExtensions.swift b/Sources/Web3Swift/Extensions/ResultExtensions.swift index 33936421..8e8f65c1 100644 --- a/Sources/Web3Swift/Extensions/ResultExtensions.swift +++ b/Sources/Web3Swift/Extensions/ResultExtensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ResultExtensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -8,7 +8,7 @@ import Foundation extension Result where Failure == JSONRPCError { init(catching body: () throws -> Success) { do { - self = .success(try body()) + self = try .success(body()) } catch { self = .failure(error as! JSONRPCError) } diff --git a/Sources/Web3Swift/Extensions/String+Numeric.swift b/Sources/Web3Swift/Extensions/String+Numeric.swift index 1f7e3657..5edef517 100644 --- a/Sources/Web3Swift/Extensions/String+Numeric.swift +++ b/Sources/Web3Swift/Extensions/String+Numeric.swift @@ -1,5 +1,5 @@ // -// web3.swift +// String+Numeric.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Extensions/URLSessionExtensions.swift b/Sources/Web3Swift/Extensions/URLSessionExtensions.swift index 66259a11..f57335b5 100644 --- a/Sources/Web3Swift/Extensions/URLSessionExtensions.swift +++ b/Sources/Web3Swift/Extensions/URLSessionExtensions.swift @@ -1,5 +1,5 @@ // -// web3.swift +// URLSessionExtensions.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -13,7 +13,7 @@ extension URLSession { func data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) { try await withCheckedThrowingContinuation { continuation in let task = self.dataTask(with: request) { data, response, error in - guard let data = data, let response = response else { + guard let data, let response else { let error = error ?? URLError(.badServerResponse) return continuation.resume(throwing: error) } @@ -28,7 +28,7 @@ extension URLSession { func data(from url: URL) async throws -> (Data, URLResponse) { try await withCheckedThrowingContinuation { continuation in let task = self.dataTask(with: url) { data, response, error in - guard let data = data, let response = response else { + guard let data, let response else { let error = error ?? URLError(.badServerResponse) return continuation.resume(throwing: error) } diff --git a/Sources/Web3Swift/Multicall/Multicall.swift b/Sources/Web3Swift/Multicall/Multicall.swift index b2ec2767..69143478 100644 --- a/Sources/Web3Swift/Multicall/Multicall.swift +++ b/Sources/Web3Swift/Multicall/Multicall.swift @@ -1,5 +1,5 @@ // -// web3.swift +// Multicall.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -32,10 +32,9 @@ public struct Multicall { fatalError("Outputs do not match the number of calls done") } - zip(calls, data.outputs) - .forEach { call, output in - try? call.handler?(output) - } + for (call, output) in zip(calls, data.outputs) { + try? call.handler?(output) + } return data } catch { throw MulticallError.executionFailed(error) @@ -51,10 +50,9 @@ public struct Multicall { do { let data = try await function.call(withClient: client, responseType: Multicall2Response.self) - zip(calls, data.outputs) - .forEach { call, output in - try? call.handler?(output) - } + for (call, output) in zip(calls, data.outputs) { + try? call.handler?(output) + } return data } catch { throw MulticallError.executionFailed(error) diff --git a/Sources/Web3Swift/Multicall/MulticallContract.swift b/Sources/Web3Swift/Multicall/MulticallContract.swift index cf64f633..1e12c188 100644 --- a/Sources/Web3Swift/Multicall/MulticallContract.swift +++ b/Sources/Web3Swift/Multicall/MulticallContract.swift @@ -1,5 +1,5 @@ // -// web3.swift +// MulticallContract.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -21,22 +21,22 @@ extension Multicall { public static func registryAddress(for network: EthereumNetwork) -> EthereumAddress? { switch network { case .mainnet: - return Multicall.Contract.Registry.mainnet + Multicall.Contract.Registry.mainnet case .sepolia: - return Multicall.Contract.Registry.sepolia + Multicall.Contract.Registry.sepolia default: - return nil + nil } } public static func multicall2Address(for network: EthereumNetwork) -> EthereumAddress? { switch network { case .mainnet: - return Multicall.Contract.Multicall2.mainnet + Multicall.Contract.Multicall2.mainnet case .sepolia: - return Multicall.Contract.Multicall2.sepolia + Multicall.Contract.Multicall2.sepolia default: - return nil + nil } } diff --git a/Sources/Web3Swift/OffchainLookup/OffchainLookup.swift b/Sources/Web3Swift/OffchainLookup/OffchainLookup.swift index f34025d4..383c559a 100644 --- a/Sources/Web3Swift/OffchainLookup/OffchainLookup.swift +++ b/Sources/Web3Swift/OffchainLookup/OffchainLookup.swift @@ -1,5 +1,5 @@ // -// web3.swift +// OffchainLookup.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift b/Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift index 4dde7bb3..957b67c7 100644 --- a/Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift +++ b/Sources/Web3Swift/SIWE/EthereumAccount+SignSIWERequest.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumAccount+SignSIWERequest.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/SIWE/SiweMessage+Codable.swift b/Sources/Web3Swift/SIWE/SiweMessage+Codable.swift index ce741de9..82fdc185 100644 --- a/Sources/Web3Swift/SIWE/SiweMessage+Codable.swift +++ b/Sources/Web3Swift/SIWE/SiweMessage+Codable.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessage+Codable.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift b/Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift index e58765b7..6508f96b 100644 --- a/Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift +++ b/Sources/Web3Swift/SIWE/SiweMessage+RegEx.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessage+RegEx.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/SIWE/SiweMessage+String.swift b/Sources/Web3Swift/SIWE/SiweMessage+String.swift index 9ec51146..1304c94f 100644 --- a/Sources/Web3Swift/SIWE/SiweMessage+String.swift +++ b/Sources/Web3Swift/SIWE/SiweMessage+String.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessage+String.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -45,16 +45,16 @@ extension SiweMessage: CustomStringConvertible { "Issued At: \(SiweMessage.dateFormatter.string(from: issuedAt))" ] - if let expirationTime = expirationTime { + if let expirationTime { fields.append("Expiration Time: \(SiweMessage.dateFormatter.string(from: expirationTime))") } - if let notBefore = notBefore { + if let notBefore { fields.append("Not Before: \(SiweMessage.dateFormatter.string(from: notBefore))") } - if let requestId = requestId { + if let requestId { fields.append("Request ID: \(requestId)") } - if let resources = resources { + if let resources { fields.append("Resources:") fields.append(contentsOf: resources.map { "- \($0.absoluteString)" }) } diff --git a/Sources/Web3Swift/SIWE/SiweMessage+Validation.swift b/Sources/Web3Swift/SIWE/SiweMessage+Validation.swift index e01314f0..60a6fc06 100644 --- a/Sources/Web3Swift/SIWE/SiweMessage+Validation.swift +++ b/Sources/Web3Swift/SIWE/SiweMessage+Validation.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessage+Validation.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -47,7 +47,7 @@ extension SiweMessage { throw ValidationError.invalidNonce } - if let requestId = requestId { + if let requestId { guard !requestId.isEmpty, requestId.matches(regex: "[-._~!$&'()*+,;=:@%a-zA-Z0-9]*") else { diff --git a/Sources/Web3Swift/SIWE/SiweMessage.swift b/Sources/Web3Swift/SIWE/SiweMessage.swift index 4ab04e7e..2c99eaa6 100644 --- a/Sources/Web3Swift/SIWE/SiweMessage.swift +++ b/Sources/Web3Swift/SIWE/SiweMessage.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessage.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/SIWE/SiweVerifier.swift b/Sources/Web3Swift/SIWE/SiweVerifier.swift index 551c5766..b02a9d6d 100644 --- a/Sources/Web3Swift/SIWE/SiweVerifier.swift +++ b/Sources/Web3Swift/SIWE/SiweVerifier.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweVerifier.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -80,7 +80,7 @@ public class SiweVerifier { throw Error.invalidSignature } - let address = EthereumAddress(try KeyUtil.recoverPublicKey(message: messageHash, signature: signatureData)) + let address = try EthereumAddress(KeyUtil.recoverPublicKey(message: messageHash, signature: signatureData)) if address.toChecksumAddress() == message.address { return true } else { diff --git a/Sources/Web3Swift/Utils/AesUtil.swift b/Sources/Web3Swift/Utils/AesUtil.swift index fb991e29..f81f2c95 100644 --- a/Sources/Web3Swift/Utils/AesUtil.swift +++ b/Sources/Web3Swift/Utils/AesUtil.swift @@ -1,5 +1,5 @@ // -// web3.swift +// AesUtil.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -23,7 +23,7 @@ class Aes128Util { let keyPtr = (key as NSData).bytes.assumingMemoryBound(to: UInt8.self) - if let iv = iv { + if let iv { let ivPtr = (iv as NSData).bytes.assumingMemoryBound(to: UInt8.self) AES_init_ctx_iv(ctx, keyPtr, ivPtr) } else { diff --git a/Sources/Web3Swift/Utils/HexUtil.swift b/Sources/Web3Swift/Utils/HexUtil.swift index 451b5eb7..9950bbaa 100644 --- a/Sources/Web3Swift/Utils/HexUtil.swift +++ b/Sources/Web3Swift/Utils/HexUtil.swift @@ -1,5 +1,5 @@ // -// web3.swift +// HexUtil.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Utils/KeyDerivation.swift b/Sources/Web3Swift/Utils/KeyDerivation.swift index 7b7b45d3..47b57dd0 100644 --- a/Sources/Web3Swift/Utils/KeyDerivation.swift +++ b/Sources/Web3Swift/Utils/KeyDerivation.swift @@ -1,5 +1,5 @@ // -// web3.swift +// KeyDerivation.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -19,9 +19,9 @@ enum KeyDerivationAlgorithm { func ccAlgorithm() -> CCAlgorithm { switch self { case .pbkdf2sha256: - return CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256) + CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256) case .pbkdf2sha512: - return CCPBKDFAlgorithm(kCCPRFHmacAlgSHA512) + CCPBKDFAlgorithm(kCCPRFHmacAlgSHA512) } } #endif @@ -29,27 +29,27 @@ enum KeyDerivationAlgorithm { func function() -> String { switch self { case .pbkdf2sha256: - return "pbkdf2" + "pbkdf2" case .pbkdf2sha512: - return "pbkdf2" + "pbkdf2" } } func hash() -> String { switch self { case .pbkdf2sha256: - return "hmac-sha256" + "hmac-sha256" case .pbkdf2sha512: - return "hmac-sha512" + "hmac-sha512" } } fileprivate func hmacVariant() -> HMAC.Variant { switch self { case .pbkdf2sha256: - return .sha256 + .sha256 case .pbkdf2sha512: - return .sha512 + .sha512 } } } diff --git a/Sources/Web3Swift/Utils/KeyUtil.swift b/Sources/Web3Swift/Utils/KeyUtil.swift index 787b119f..f07a308a 100644 --- a/Sources/Web3Swift/Utils/KeyUtil.swift +++ b/Sources/Web3Swift/Utils/KeyUtil.swift @@ -1,5 +1,5 @@ // -// web3.swift +// KeyUtil.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Utils/KeystoreUtil.swift b/Sources/Web3Swift/Utils/KeystoreUtil.swift index b36a1a80..1deae9be 100644 --- a/Sources/Web3Swift/Utils/KeystoreUtil.swift +++ b/Sources/Web3Swift/Utils/KeystoreUtil.swift @@ -1,5 +1,5 @@ // -// web3.swift +// KeystoreUtil.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Utils/PropertyWrappers.swift b/Sources/Web3Swift/Utils/PropertyWrappers.swift index d4646ef3..85e1cfc8 100644 --- a/Sources/Web3Swift/Utils/PropertyWrappers.swift +++ b/Sources/Web3Swift/Utils/PropertyWrappers.swift @@ -1,5 +1,5 @@ // -// web3.swift +// PropertyWrappers.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3Swift/Utils/RLP.swift b/Sources/Web3Swift/Utils/RLP.swift index 70d47b87..5dfa83a3 100644 --- a/Sources/Web3Swift/Utils/RLP.swift +++ b/Sources/Web3Swift/Utils/RLP.swift @@ -1,5 +1,5 @@ // -// web3.swift +// RLP.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -10,21 +10,21 @@ public struct RLP { public static func encode(_ item: Any) -> Data? { switch item { case let int as Int: - return encodeInt(int) + encodeInt(int) case let string as String: - return encodeString(string) + encodeString(string) case let bint as BigInt: - return encodeBigInt(bint) + encodeBigInt(bint) case let array as [Any]: - return encodeArray(array) + encodeArray(array) case let buint as BigUInt: - return encodeBigUInt(buint) + encodeBigUInt(buint) case let data as Data: - return encodeData(data) + encodeData(data) case let address as EthereumAddress: - return encodeAddress(address) + encodeAddress(address) default: - return nil + nil } } diff --git a/Sources/Web3ZKSync/ABIFunction+ZKSync.swift b/Sources/Web3ZKSync/ABIFunction+ZKSync.swift index e26595d3..5abca720 100644 --- a/Sources/Web3ZKSync/ABIFunction+ZKSync.swift +++ b/Sources/Web3ZKSync/ABIFunction+ZKSync.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ABIFunction+ZKSync.swift // Copyright © 2023 Argent Labs Limited. All rights reserved. // @@ -15,7 +15,7 @@ extension ABIFunction { chainId: Int? = nil, nonce: Int? = nil ) throws -> ZKSyncTransaction { - guard let from = from else { + guard let from else { throw ABIError.invalidValue } diff --git a/Sources/Web3ZKSync/EthereumAccount+ZKSync.swift b/Sources/Web3ZKSync/EthereumAccount+ZKSync.swift index fdb7799f..1a1190f0 100644 --- a/Sources/Web3ZKSync/EthereumAccount+ZKSync.swift +++ b/Sources/Web3ZKSync/EthereumAccount+ZKSync.swift @@ -1,5 +1,5 @@ // -// web3.swift +// EthereumAccount+ZKSync.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Sources/Web3ZKSync/ZKSyncProvider.swift b/Sources/Web3ZKSync/ZKSyncProvider.swift index 17eaba89..66430790 100644 --- a/Sources/Web3ZKSync/ZKSyncProvider.swift +++ b/Sources/Web3ZKSync/ZKSyncProvider.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ZKSyncProvider.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -104,7 +104,7 @@ struct EstimateGasParams: Encodable { func encode(to encoder: Encoder) throws { var container = encoder.unkeyedContainer() var nested = container.nestedContainer(keyedBy: TransactionCodingKeys.self) - if let from = from { + if let from { try nested.encode(from, forKey: .from) } try nested.encode(to, forKey: .to) @@ -122,7 +122,7 @@ struct EstimateGasParams: Encodable { if let value = value.map(jsonRPCAmount) { try nested.encode(value, forKey: .value) } - if let data = data { + if let data { try nested.encode(data, forKey: .data) } } diff --git a/Sources/Web3ZKSync/ZKSyncTransaction.swift b/Sources/Web3ZKSync/ZKSyncTransaction.swift index 4b4ed42e..636aa366 100644 --- a/Sources/Web3ZKSync/ZKSyncTransaction.swift +++ b/Sources/Web3ZKSync/ZKSyncTransaction.swift @@ -1,5 +1,5 @@ // -// web3.swift +// ZKSyncTransaction.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // diff --git a/Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift index 79a8acfe..17082d12 100644 --- a/Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift +++ b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTransactionTests.swift @@ -1,14 +1,13 @@ // -// web3.swift +// EthereumAccount+SignTransactionTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class EthereumAccount_SignTransactionTests: XCTestCase { - override func setUp() { super.setUp() } @@ -18,7 +17,7 @@ class EthereumAccount_SignTransactionTests: XCTestCase { } func testTransaction2Sign() { - //https://medium.com/@codetractio/walkthrough-of-an-ethereum-improvement-proposal-eip-6fda3966d171 + // https://medium.com/@codetractio/walkthrough-of-an-ethereum-improvement-proposal-eip-6fda3966d171 let nonce = 9 let gasPrice = BigUInt(20000000000) @@ -29,7 +28,7 @@ class EthereumAccount_SignTransactionTests: XCTestCase { let tx = EthereumTransaction(from: nil, to: to, value: value, data: nil, nonce: nonce, gasPrice: gasPrice, gasLimit: gasLimit, chainId: chainID) - let account = try! EthereumAccount.init(keyStorage: TestEthereumKeyStorage(privateKey: "0x4646464646464646464646464646464646464646464646464646464646464646")) + let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "0x4646464646464646464646464646464646464646464646464646464646464646")) let signed = try! account.sign(transaction: tx) let v = signed.v.web3.hexString @@ -39,26 +38,23 @@ class EthereumAccount_SignTransactionTests: XCTestCase { XCTAssertEqual(v, "0x25") XCTAssertEqual(r, "0x28ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276") XCTAssertEqual(s, "0x67cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83") - } func testTransactionVitalik1Raw() { - let nonce = Int(hex: "0x00")! let gasPrice = BigUInt(hex: "0x04a817c800")! let gasLimit = BigUInt(hex: "0x5208")! let to = EthereumAddress("0x3535353535353535353535353535353535353535") let value = BigUInt(hex: "0x0")! let signature = "0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d25".web3.hexData! - + let tx = EthereumTransaction(from: nil, to: to, value: value, data: nil, nonce: nonce, gasPrice: gasPrice, gasLimit: gasLimit, chainId: 37) let signed = SignedTransaction(transaction: tx, signature: signature) - + let raw = signed.raw!.web3.hexString let hash = signed.hash!.web3.hexString XCTAssertEqual(raw, "0xf864808504a817c800825208943535353535353535353535353535353535353535808025a0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116da0044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d") XCTAssertEqual(hash, "0xb1e2188bc490908a78184e4818dca53684167507417fdb4c09c2d64d32a9896a") } - } diff --git a/Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift index 12c006f8..78bd6acf 100644 --- a/Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift +++ b/Tests/Web3SwiftTests/Account/EthereumAccount+SignTypedTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// EthereumAccount+SignTypedTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest // https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.js // https://github.com/dicether/js-eth-personal-sign-examples @@ -203,26 +203,34 @@ class EthereumAccount_SignTypedTests: XCTestCase { func test_GivenSmallerExample_ItEncodesCorrectly() { let typedData = try! decoder.decode(TypedData.self, from: example2) - XCTAssertEqual(try! typedData.encodeData(data: typedData.message, type: typedData.primaryType).web3.hexString, - "0x432c2e85cd4fb1991e30556bafe6d78422c6eeb812929bc1d2d4c7053998a4099c0257114eb9399a2985f8e75dad7600c5d89fe3824ffa99ec1c3eb8bf3b0501bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000001") + XCTAssertEqual( + try! typedData.encodeData(data: typedData.message, type: typedData.primaryType).web3.hexString, + "0x432c2e85cd4fb1991e30556bafe6d78422c6eeb812929bc1d2d4c7053998a4099c0257114eb9399a2985f8e75dad7600c5d89fe3824ffa99ec1c3eb8bf3b0501bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000001" + ) } func test_GivenWalletConnectExample_ItEncodesCorrectly() { let typedData = try! decoder.decode(TypedData.self, from: example3) - XCTAssertEqual(try! typedData.encodeData(data: typedData.message, type: typedData.primaryType).web3.hexString, - "0x2ff8cad9fc52c931beef9178a726d1ab6280a9c2b6a6396450a181819cf1e5400000000000000000000000009cf40ef3d1622efe270fe6fe720585b4be4eeeffa9485354dd9d340e02789cfc540c6c4a2ff5511beb414b64634a5e11c6a7168cff9bf07e24e6ff0943eadc198a43500e4016d41517b01c92d4b2217909610371b070fcfff74c07b7820d93159a2fd5cb8e2fdf060ee7b42e79f1b4414bccccc1") + XCTAssertEqual( + try! typedData.encodeData(data: typedData.message, type: typedData.primaryType).web3.hexString, + "0x2ff8cad9fc52c931beef9178a726d1ab6280a9c2b6a6396450a181819cf1e5400000000000000000000000009cf40ef3d1622efe270fe6fe720585b4be4eeeffa9485354dd9d340e02789cfc540c6c4a2ff5511beb414b64634a5e11c6a7168cff9bf07e24e6ff0943eadc198a43500e4016d41517b01c92d4b2217909610371b070fcfff74c07b7820d93159a2fd5cb8e2fdf060ee7b42e79f1b4414bccccc1" + ) } func test_GivenWalletConnectExample_ItHashesCorrectly() { let typedData = try! decoder.decode(TypedData.self, from: example3) - XCTAssertEqual(try! typedData.signableHash().web3.hexString, - "0xabc79f527273b9e7bca1b3f1ac6ad1a8431fa6dc34ece900deabcd6969856b5e") + XCTAssertEqual( + try! typedData.signableHash().web3.hexString, + "0xabc79f527273b9e7bca1b3f1ac6ad1a8431fa6dc34ece900deabcd6969856b5e" + ) } func test_GivenNoDomain_ItHashesCorrectly() { let typedData = try! decoder.decode(TypedData.self, from: noDomain) - XCTAssertEqual(try! typedData.signableHash().web3.hexString, - "0x34091011761262618af3045f97715b4a73eb6737c9396353b85b757201e3ad9f") + XCTAssertEqual( + try! typedData.signableHash().web3.hexString, + "0x34091011761262618af3045f97715b4a73eb6737c9396353b85b757201e3ad9f" + ) } func test_GivenProdExample_ItHashesCorrectly() { @@ -231,13 +239,13 @@ class EthereumAccount_SignTypedTests: XCTestCase { let typedData = try! decoder.decode(TypedData.self, from: data) XCTAssertEqual(try! typedData.signableHash().web3.hexString, "0xdb12328a6d193965801548e1174936c3aa7adbe1b54b3535a3c905bd4966467c") } - + func test_GivenCustomTypeArray_V4_ItHashesCorrectly() { let simpleUrl = Bundle.module.url(forResource: "ethermail_signTypedDataV4", withExtension: "json")! let simpleData = try! Data(contentsOf: simpleUrl) let simpleTypedData = try! decoder.decode(TypedData.self, from: simpleData) XCTAssertEqual(try! simpleTypedData.signableHash().web3.hexString, "0x8a2c45f690057d91a9738b313da3f65916327e1d5b9a1348b9fc1cff0dc4091e") - + let realWorldUrl = Bundle.module.url(forResource: "real_word_opensea_signTypedDataV4", withExtension: "json")! let realWorldData = try! Data(contentsOf: realWorldUrl) let realWorldTypedData = try! decoder.decode(TypedData.self, from: realWorldData) @@ -246,9 +254,10 @@ class EthereumAccount_SignTypedTests: XCTestCase { func test_givenExampleWithDynamicData_ItHashesCorrectly() { let typedData = try! decoder.decode(TypedData.self, from: example4) - XCTAssertEqual(try! typedData.signableHash().web3.hexString, - "0x1f177092c4fbedf53f392389d4512f0a61babf07acc05303a4f1ef7e90b67d92") - + XCTAssertEqual( + try! typedData.signableHash().web3.hexString, + "0x1f177092c4fbedf53f392389d4512f0a61babf07acc05303a4f1ef7e90b67d92" + ) } func test_givenExample_ItSignsCorrectly() { diff --git a/Tests/Web3SwiftTests/Account/EthereumAccountTests.swift b/Tests/Web3SwiftTests/Account/EthereumAccountTests.swift index 6b0f0f8f..76ddfb47 100644 --- a/Tests/Web3SwiftTests/Account/EthereumAccountTests.swift +++ b/Tests/Web3SwiftTests/Account/EthereumAccountTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// EthereumAccountTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class EthereumAccountTests: XCTestCase { override func setUp() { @@ -14,7 +14,7 @@ class EthereumAccountTests: XCTestCase { override func tearDown() { super.tearDown() } - + func testLoadAccountAndAddress() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: TestConfig.privateKey)) XCTAssertEqual(account.address, EthereumAddress(TestConfig.publicKey), "Failed to load private key. Ensure key is valid in TestConfig.swift") @@ -31,7 +31,7 @@ class EthereumAccountTests: XCTestCase { let account = try? EthereumAccount.create(replacing: storage, keystorePassword: "PASSWORD") XCTAssertNotNil(account, "Failed to create account. Ensure key is valid in TestConfig.swift") } - + func testCreateAccountMultiple() { let storage = EthereumKeyLocalStorage() let account = try? EthereumAccount.create(addingTo: storage, keystorePassword: "PASSWORD") @@ -44,21 +44,21 @@ class EthereumAccountTests: XCTestCase { XCTAssertEqual(account.address, "0x675f5810feb3b09528e5cd175061b4eb8de69075") } - + func testImportAccountMultiple() { let storage = EthereumKeyLocalStorage() let account = try! EthereumAccount.importAccount(addingTo: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD") XCTAssertEqual(account.address, "0x675f5810feb3b09528e5cd175061b4eb8de69075") } - + func testFetchAccounts() { let storage = EthereumKeyLocalStorage() let account = try! EthereumAccount.importAccount(addingTo: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD") let accounts = try! storage.fetchAccounts() XCTAssertTrue(accounts.contains(account.address)) } - + func testDeleteAccount() { let storage = EthereumKeyLocalStorage() let account = try! EthereumAccount.importAccount(addingTo: storage, privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", keystorePassword: "PASSWORD") @@ -67,7 +67,7 @@ class EthereumAccountTests: XCTestCase { let accounts = try! storage.fetchAccounts() XCTAssertTrue(!accounts.contains(account.address)) } - + func testSignMessage() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173")) let signature = try! account.sign(message: "Hello message!") @@ -76,7 +76,7 @@ class EthereumAccountTests: XCTestCase { XCTAssertEqual(signature.web3.hexString.web3.noHexPrefix, expectedSignature) } - + func testSignData() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173")) let signature = try! account.sign(data: "Hello message!".data(using: .utf8)!) @@ -85,7 +85,7 @@ class EthereumAccountTests: XCTestCase { XCTAssertEqual(signature.web3.hexString.web3.noHexPrefix, expectedSignature) } - + func testSignHash() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "774681694ad86635346b6e9b92fa8aa4806265336dc6766623029a6264a162c1")) let signature = try! account.sign(hash: "0x9dd2c369a187b4e6b9c402f030e50743e619301ea62aa4c0737d4ef7e10a3d49") @@ -94,7 +94,7 @@ class EthereumAccountTests: XCTestCase { XCTAssertEqual(signature.web3.hexString.web3.noHexPrefix, expectedSignature) } - + func testSignHex() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173")) let signature = try! account.sign(hex: "0xe5808504a817c80082520894f59fc5a335e75060ff18beed2d6c8fbbbdab0dc2843b9aca0080") @@ -111,7 +111,7 @@ class EthereumAccountTests: XCTestCase { XCTAssertEqual(signature.web3.hexString.web3.noHexPrefix, expectedSignature) } - + func test_toChecksumAddress() { let add1: EthereumAddress = "0x12ae66cdc592e10b60f9097a7b0d3c59fce29876" let add2: EthereumAddress = "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1" diff --git a/Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift b/Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift index 92b5f824..1f8c7568 100644 --- a/Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift +++ b/Tests/Web3SwiftTests/Account/EthereumKeyStorageTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// EthereumKeyStorageTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class EthereumKeyStorageTests: XCTestCase { - override func setUp() { super.setUp() } @@ -40,7 +39,7 @@ class EthereumKeyStorageTests: XCTestCase { XCTFail("Failed to save private key. Ensure key is valid in TestConfig.swift") } } - + func testEncryptAndStorePrivateKey() { let randomData = Data.randomOfLength(256)! let keyStorage = EthereumKeyLocalStorage() as EthereumSingleKeyStorageProtocol @@ -50,7 +49,7 @@ class EthereumKeyStorageTests: XCTestCase { try keyStorage.encryptAndStorePrivateKey(key: randomData, keystorePassword: password) let decrypted = try keyStorage.loadAndDecryptPrivateKey(keystorePassword: password) XCTAssertEqual(decrypted, randomData) - } catch let error { + } catch { XCTFail("Failed to encrypt and store private key with error: \(error)") } } @@ -67,11 +66,11 @@ class EthereumKeyStorageTests: XCTestCase { let address = KeyUtil.generateAddress(from: publicKey) let decrypted = try keyStorage.loadAndDecryptPrivateKey(for: address, keystorePassword: password) XCTAssertEqual(decrypted, randomData) - } catch let error { + } catch { XCTFail("Failed to encrypt and store private key with error: \(error)") } } - + func testDeleteAllPrivateKeys() { let keyStorage = EthereumKeyLocalStorage() do { @@ -81,7 +80,7 @@ class EthereumKeyStorageTests: XCTestCase { try keyStorage.deleteAllKeys() let countAfterDeleting = try keyStorage.fetchAccounts() XCTAssertEqual(countAfterDeleting.count, 0) - } catch let error { + } catch { XCTFail("Failed to delete all private keys: \(error)") } } diff --git a/Tests/Web3SwiftTests/Address/EthereumAddressTests.swift b/Tests/Web3SwiftTests/Address/EthereumAddressTests.swift index 4e3cbea7..21383f24 100644 --- a/Tests/Web3SwiftTests/Address/EthereumAddressTests.swift +++ b/Tests/Web3SwiftTests/Address/EthereumAddressTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// EthereumAddressTests.swift // Copyright © 2023 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class EthereumAddressTests: XCTestCase { private var values: Set! diff --git a/Tests/Web3SwiftTests/Client/EthereumClientTests.swift b/Tests/Web3SwiftTests/Client/EthereumClientTests.swift index e8070401..7a88c1b8 100644 --- a/Tests/Web3SwiftTests/Client/EthereumClientTests.swift +++ b/Tests/Web3SwiftTests/Client/EthereumClientTests.swift @@ -1,16 +1,16 @@ // -// web3.swift +// EthereumClientTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import BigInt import NIO -import XCTest @testable import web3 +import BigInt +import XCTest struct TransferMatchingSignatureEvent: ABIEvent { public static let name = "Transfer" - public static let types: [ABIType.Type] = [ EthereumAddress.self, EthereumAddress.self, BigUInt.self] + public static let types: [ABIType.Type] = [EthereumAddress.self, EthereumAddress.self, BigUInt.self] public static let typesIndexed = [true, true, false] public let log: EthereumLog @@ -32,7 +32,7 @@ struct TransferMatchingSignatureEvent: ABIEvent { class EthereumClientTests: XCTestCase { var client: EthereumClientProtocol? var account: EthereumAccount? - + override func setUp() { super.setUp() client = EthereumHttpClient(url: URL(string: TestConfig.clientUrl)!, network: TestConfig.network) @@ -234,11 +234,13 @@ class EthereumClientTests: XCTestCase { do { let to = try! ABIEncoder.encode(EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41")) - let eventsResult = try await client?.getEvents(addresses: nil, - topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], - fromBlock: .Earliest, - toBlock: .Latest, - eventTypes: [ERC20Events.Transfer.self]) + let eventsResult = try await client?.getEvents( + addresses: nil, + topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], + fromBlock: .Earliest, + toBlock: .Latest, + eventTypes: [ERC20Events.Transfer.self] + ) XCTAssertEqual(eventsResult?.logs.count, 4) XCTAssertEqual(eventsResult?.events.count, 5) } catch { @@ -250,11 +252,13 @@ class EthereumClientTests: XCTestCase { do { let to = try! ABIEncoder.encode(EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41")) - let eventsResult = try await client?.getEvents(addresses: nil, - topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], - fromBlock: .Earliest, - toBlock: .Latest, - eventTypes: [ERC20Events.Transfer.self, TransferMatchingSignatureEvent.self]) + let eventsResult = try await client?.getEvents( + addresses: nil, + topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], + fromBlock: .Earliest, + toBlock: .Latest, + eventTypes: [ERC20Events.Transfer.self, TransferMatchingSignatureEvent.self] + ) XCTAssertEqual(eventsResult?.logs.count, 8) XCTAssertEqual(eventsResult?.events.count, 10) } catch { @@ -269,11 +273,13 @@ class EthereumClientTests: XCTestCase { EventFilter(type: ERC20Events.Transfer.self, allowedSenders: ["0xF31B086459C2cdaC006Feedd9080223964a9cDdB"]) ] - let eventsResult = try await client?.getEvents(addresses: nil, - topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], - fromBlock: .Earliest, - toBlock: .Latest, - matching: filters) + let eventsResult = try await client?.getEvents( + addresses: nil, + topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], + fromBlock: .Earliest, + toBlock: .Latest, + matching: filters + ) XCTAssertEqual(eventsResult?.logs.count, 7) XCTAssertEqual(eventsResult?.events.count, 2) } catch { @@ -289,11 +295,13 @@ class EthereumClientTests: XCTestCase { EventFilter(type: TransferMatchingSignatureEvent.self, allowedSenders: ["0xB2a6874c2F71fD4481674BaC945D5407A2318b3E"]) ] - let eventsResult = try await client?.getEvents(addresses: nil, - topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], - fromBlock: .Earliest, - toBlock: .Latest, - matching: filters) + let eventsResult = try await client?.getEvents( + addresses: nil, + topics: [try! ERC20Events.Transfer.signature(), nil, to.hexString, nil], + fromBlock: .Earliest, + toBlock: .Latest, + matching: filters + ) XCTAssertEqual(eventsResult?.logs.count, 16) XCTAssertEqual(eventsResult?.events.count, 6) } catch { @@ -317,7 +325,8 @@ class EthereumClientTests: XCTestCase { let function = InvalidMethodA(param: .zero) _ = try await function.call( withClient: client!, - responseType: InvalidMethodA.BoolResponse.self) + responseType: InvalidMethodA.BoolResponse.self + ) XCTFail("Expected to throw while awaiting, but succeeded") } catch { XCTAssertEqual( @@ -331,13 +340,15 @@ class EthereumClientTests: XCTestCase { func test_GivenValidTransaction_ThenEstimatesGas() async { do { - let function = TransferToken(wallet: "0xD18dE36e6FB4a5A069f673723Fab71cc00C6CE5F", - token: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", - to: "0x2A6295C34b4136F2C3c1445c6A0338D784fe0ddd", - amount: 1, - data: Data(), - gasPrice: nil, - gasLimit: nil) + let function = TransferToken( + wallet: "0xD18dE36e6FB4a5A069f673723Fab71cc00C6CE5F", + token: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", + to: "0x2A6295C34b4136F2C3c1445c6A0338D784fe0ddd", + amount: 1, + data: Data(), + gasPrice: nil, + gasLimit: nil + ) let value = try await client!.eth_estimateGas(try! function.transaction()) XCTAssert(value != 0) @@ -348,12 +359,14 @@ class EthereumClientTests: XCTestCase { func test_ValueWithLeadingZero_EstimatesGas() async { do { - let tx = EthereumTransaction(from: EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41"), - to: EthereumAddress("0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793"), - value: BigUInt(5000000000), - data: Data(), - gasPrice: BigUInt(0), - gasLimit: BigUInt(0)) + let tx = EthereumTransaction( + from: EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41"), + to: EthereumAddress("0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793"), + value: BigUInt(5000000000), + data: Data(), + gasPrice: BigUInt(0), + gasLimit: BigUInt(0) + ) let value = try await client!.eth_estimateGas(tx) XCTAssert(value != 0) } catch { @@ -375,12 +388,10 @@ struct GetDynamicArray: ABIFunction { init?(values: [ABIDecoder.DecodedValue]) throws { self.addresses = try values[0].decodedArray() - } } - func encode(to encoder: ABIFunctionEncoder) throws { - } + func encode(to encoder: ABIFunctionEncoder) throws {} } struct TransferToken: ABIFunction { @@ -424,8 +435,7 @@ struct InvalidMethodA: ABIFunction { } } - func encode(to encoder: ABIFunctionEncoder) throws { - } + func encode(to encoder: ABIFunctionEncoder) throws {} } class EthereumWebSocketClientTests: EthereumClientTests { @@ -434,150 +444,149 @@ class EthereumWebSocketClientTests: EthereumClientTests { override func setUp() { super.setUp() client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, configuration: TestConfig.webSocketConfig, network: TestConfig.network) - - } -#if os(Linux) -// On Linux some tests are fail. Need investigation -#else - func testWebSocketNoAutomaticOpen() { - self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, configuration: .init(automaticOpen: false), network: TestConfig.network) - - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } - - XCTAssertEqual(client.currentState, WebSocketState.closed) } + #if os(Linux) + // On Linux some tests are fail. Need investigation + #else + func testWebSocketNoAutomaticOpen() { + self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, configuration: .init(automaticOpen: false), network: TestConfig.network) - func testWebSocketConnect() { - self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, configuration: .init(automaticOpen: false), network: TestConfig.network) + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return + XCTAssertEqual(client.currentState, WebSocketState.closed) } - XCTAssertEqual(client.currentState, WebSocketState.closed) - - client.connect() - - XCTAssertEqual(client.currentState, WebSocketState.open) - } + func testWebSocketConnect() { + self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, configuration: .init(automaticOpen: false), network: TestConfig.network) - func testWebSocketPendingTransactions() async { - do { guard let client = client as? EthereumWebSocketClient else { XCTFail("Expected client to be EthereumWebSocketClient") return } - var expectation: XCTestExpectation? = self.expectation(description: "Pending Transaction") - let subscription = try await client.pendingTransactions { _ in - expectation?.fulfill() - expectation = nil - } + XCTAssertEqual(client.currentState, WebSocketState.closed) - await waitForExpectations(timeout: 5, handler: nil) + client.connect() - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, .newPendingTransactions) - } catch { - XCTFail("Expected subscription but failed \(error).") + XCTAssertEqual(client.currentState, WebSocketState.open) } - } - func testWebSocketNewBlockHeaders() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } + func testWebSocketPendingTransactions() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } - var expectation: XCTestExpectation? = self.expectation(description: "New Block Headers") - let subscription = try await client.newBlockHeaders { _ in - expectation?.fulfill() - expectation = nil - } + var expectation: XCTestExpectation? = self.expectation(description: "Pending Transaction") + let subscription = try await client.pendingTransactions { _ in + expectation?.fulfill() + expectation = nil + } - // we need a high timeout as new block might take a while - await waitForExpectations(timeout: 2500, handler: nil) + await waitForExpectations(timeout: 5, handler: nil) - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, .newBlockHeaders) - } catch { - XCTFail("Expected subscription but failed \(error).") + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, .newPendingTransactions) + } catch { + XCTFail("Expected subscription but failed \(error).") + } } - } - func testWebSocketLogs() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } + func testWebSocketNewBlockHeaders() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } - var expectation: XCTestExpectation? = self.expectation(description: "Logs") - let type = EthereumSubscriptionType.logs(nil) - let subscription = try await client.logs { log in - print(log) - expectation?.fulfill() - expectation = nil - } + var expectation: XCTestExpectation? = self.expectation(description: "New Block Headers") + let subscription = try await client.newBlockHeaders { _ in + expectation?.fulfill() + expectation = nil + } - // we need a high timeout as new block might take a while - await waitForExpectations(timeout: 2500, handler: nil) + // we need a high timeout as new block might take a while + await waitForExpectations(timeout: 2500, handler: nil) - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, type) - } catch { - XCTFail("Expected subscription but failed \(error).") + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, .newBlockHeaders) + } catch { + XCTFail("Expected subscription but failed \(error).") + } } - } - func testWebSocketSubscribe() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return + func testWebSocketLogs() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + + var expectation: XCTestExpectation? = self.expectation(description: "Logs") + let type = EthereumSubscriptionType.logs(nil) + let subscription = try await client.logs { log in + print(log) + expectation?.fulfill() + expectation = nil + } + + // we need a high timeout as new block might take a while + await waitForExpectations(timeout: 2500, handler: nil) + + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, type) + } catch { + XCTFail("Expected subscription but failed \(error).") } - client.delegate = self - - delegateExpectation = expectation(description: "onNewPendingTransaction delegate call") - var subscription = try await client.subscribe(type: .newPendingTransactions) - await waitForExpectations(timeout: 10) - _ = try await client.unsubscribe(subscription) - - delegateExpectation = expectation(description: "onNewBlockHeader delegate call") - subscription = try await client.subscribe(type: .newBlockHeaders) - await waitForExpectations(timeout: 2500) - _ = try await client.unsubscribe(subscription) - - delegateExpectation = expectation(description: "onLogs delegate call") - let type = EthereumSubscriptionType.logs(nil) - subscription = try await client.subscribe(type: type) - await waitForExpectations(timeout: 2500) - _ = try await client.unsubscribe(subscription) - } catch { - XCTFail("Expected subscription but failed \(error).") } - } - func testWebSocketUnsubscribe() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return + func testWebSocketSubscribe() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + client.delegate = self + + delegateExpectation = expectation(description: "onNewPendingTransaction delegate call") + var subscription = try await client.subscribe(type: .newPendingTransactions) + await waitForExpectations(timeout: 10) + _ = try await client.unsubscribe(subscription) + + delegateExpectation = expectation(description: "onNewBlockHeader delegate call") + subscription = try await client.subscribe(type: .newBlockHeaders) + await waitForExpectations(timeout: 2500) + _ = try await client.unsubscribe(subscription) + + delegateExpectation = expectation(description: "onLogs delegate call") + let type = EthereumSubscriptionType.logs(nil) + subscription = try await client.subscribe(type: type) + await waitForExpectations(timeout: 2500) + _ = try await client.unsubscribe(subscription) + } catch { + XCTFail("Expected subscription but failed \(error).") } + } - let subscription = try await client.subscribe(type: .newBlockHeaders) - let result = try await client.unsubscribe(subscription) - XCTAssertTrue(result) - } catch { - XCTFail("Expected subscription but failed \(error).") + func testWebSocketUnsubscribe() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + + let subscription = try await client.subscribe(type: .newBlockHeaders) + let result = try await client.unsubscribe(subscription) + XCTAssertTrue(result) + } catch { + XCTFail("Expected subscription but failed \(error).") + } } - } -#endif + #endif } extension EthereumWebSocketClientTests: EthereumWebSocketClientDelegate { diff --git a/Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift index 18ceedfc..b34b899c 100644 --- a/Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift +++ b/Tests/Web3SwiftTests/Contract/ABIDecoderTests.swift @@ -1,18 +1,18 @@ // -// web3.swift +// ABIDecoderTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ABIDecoderTests: XCTestCase { func testDecodeUint32() { do { let decoded = try ABIDecoder.decodeData("0x000000000000000000000000000000000000000000000000000000000000002a", types: [BigUInt.self]) XCTAssertEqual(try decoded[0].decoded(), BigInt(42)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -22,7 +22,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003", types: [ABIArray.self]) XCTAssertEqual(try decoded[0].decodedArray(), [BigInt(1), BigInt(2), BigInt(3)]) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -32,11 +32,10 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x00000000000000000000000021397c1a1f4acd9132fe36df011610564b87e24b", types: [EthereumAddress.self]) XCTAssertEqual(try decoded[0].decoded(), EthereumAddress("0x21397c1a1f4acd9132fe36df011610564b87e24b")) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } - } func testDecodeString() { @@ -44,29 +43,27 @@ class ABIDecoderTests: XCTestCase { let decoded = try ABIDecoder.decodeData("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000147665726f6e696b612e617267656e742e74657374000000000000000000000000", types: [String.self]) let result: String = try decoded[0].decoded() XCTAssertEqual(result.web3.stringValue, "veronika.argent.test") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } - } func testDecodeAddressArray() { do { let decoded = try ABIDecoder.decodeData("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a77b0f3aae325cb2ec1bdb4a3548d816a83b8ca3", types: [ABIArray.self]) XCTAssertEqual(try decoded[0].decodedArray(), [.zero, EthereumAddress("0xa77b0f3aae325cb2ec1bdb4a3548d816a83b8ca3")]) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } - } func testDecodeFixedBytes1() { do { let decoded = try ABIDecoder.decodeData("0x63000000000000000000000000000000000000000000000000000000000000", types: [Data1.self]) XCTAssertEqual(try decoded[0].decoded(), Data(hex: "0x63")!) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -76,7 +73,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x6162630000000000000000000000000000000000000000000000000000000000", types: [Data3.self]) XCTAssertEqual(try decoded[0].decoded(), Data(hex: "0x616263")!) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -86,7 +83,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x0200000000000000000000000050000000000000000000000000000000616263", types: [Data32.self]) XCTAssertEqual(try decoded[0].decoded(), Data(hex: "0x0200000000000000000000000050000000000000000000000000000000616263")!) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -96,7 +93,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff38", types: [BigInt.self]) XCTAssertEqual(try decoded[0].decoded(), BigInt(-200)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -106,7 +103,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x00000000000000000000000000000000000000000000000000000000000000c8", types: [BigInt.self]) XCTAssertEqual(try decoded[0].decoded(), BigInt(200)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -116,7 +113,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decodeData("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", types: [Data.self]) XCTAssertEqual(try decoded[0].decoded(), Data()) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -127,7 +124,7 @@ class ABIDecoderTests: XCTestCase { let decoded = try ABIDecoder.decodeData("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000", types: [Data.self]) XCTAssertEqual(try decoded[0].decoded(), Data(hex: "0x48656c6c6f2c20776f726c6421")!) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -136,13 +133,14 @@ class ABIDecoderTests: XCTestCase { func testDecodeBytesArray() { do { let decoded = try ABIDecoder.decodeData( - "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e5800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012", types: [ABIArray.self], asArray: false) + "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e5800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012", types: [ABIArray.self], asArray: false + ) XCTAssertEqual(try ERC20Responses.nameResponse(data: decoded[0].entry[0])?.value, "Synthetix Network Token") XCTAssertEqual(try ERC20Responses.symbolResponse(data: decoded[0].entry[1])?.value, "SNX") XCTAssertEqual(try ERC20Responses.balanceResponse(data: decoded[0].entry[2])?.value, BigUInt(integerLiteral: 0)) XCTAssertEqual(try ERC20Responses.decimalsResponse(data: decoded[0].entry[3])?.value, 18) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -151,14 +149,15 @@ class ABIDecoderTests: XCTestCase { func testDecodeMulticallOutputWithoutFailures() { do { let decoded = try ABIDecoder.decodeData( - "0x0000000000000000000000000000000000000000000000000000000000a9f60c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e5800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012", types: [BigUInt.self, ABIArray.self]) + "0x0000000000000000000000000000000000000000000000000000000000a9f60c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e5800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012", types: [BigUInt.self, ABIArray.self] + ) XCTAssertEqual(try decoded[0].decoded(), BigUInt(integerLiteral: 11138572)) XCTAssertEqual(try ERC20Responses.nameResponse(data: decoded[1].entry[0])?.value, "Synthetix Network Token") XCTAssertEqual(try ERC20Responses.symbolResponse(data: decoded[1].entry[1])?.value, "SNX") XCTAssertEqual(try ERC20Responses.balanceResponse(data: decoded[1].entry[2])?.value, BigUInt(integerLiteral: 0)) XCTAssertEqual(try ERC20Responses.decimalsResponse(data: decoded[1].entry[3])?.value, 18) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -167,14 +166,15 @@ class ABIDecoderTests: XCTestCase { func testDecodeMulticallOutputWithOneFailure() { do { let decoded = try ABIDecoder.decodeData( - "0x0000000000000000000000000000000000000000000000000000000000a9f60c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e580000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020aface4ed2e287b2f681c32da24383f2fb691f0b6962be5ae7950a5dd793e61ad", types: [BigUInt.self, ABIArray.self]) + "0x0000000000000000000000000000000000000000000000000000000000a9f60c0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001753796e746865746978204e6574776f726b20546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003534e580000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020aface4ed2e287b2f681c32da24383f2fb691f0b6962be5ae7950a5dd793e61ad", types: [BigUInt.self, ABIArray.self] + ) XCTAssertEqual(try decoded[0].decoded(), BigUInt(integerLiteral: 11138572)) XCTAssertEqual(try ERC20Responses.nameResponse(data: decoded[1].entry[0])?.value, "Synthetix Network Token") XCTAssertEqual(try ERC20Responses.symbolResponse(data: decoded[1].entry[1])?.value, "SNX") XCTAssertEqual(try ERC20Responses.balanceResponse(data: decoded[1].entry[2])?.value, BigUInt(integerLiteral: 0)) XCTAssertEqual(decoded[1].entry[3], Multicall.Response.multicallFailedError) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -184,7 +184,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decode("68747470733a2f2f7777772e617267656e742e78797a", to: URL.self) XCTAssertEqual(decoded.absoluteString, "https://www.argent.xyz") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -194,7 +194,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decode("68747470733a2f2f7777772e617267656e742e78797a0000000000000000", to: URL.self) XCTAssertEqual(decoded.absoluteString, "https://www.argent.xyz") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -204,7 +204,7 @@ class ABIDecoderTests: XCTestCase { do { let decoded = try ABIDecoder.decode("68747470733a2f2f7777772e63727970746f61746f6d732e6f72672f637265732f7572692f3333300000000000000000000000000000000000000000000000000000000000", to: URL.self) XCTAssertEqual(decoded.absoluteString, "https://www.cryptoatoms.org/cres/uri/330") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -212,15 +212,17 @@ class ABIDecoderTests: XCTestCase { func test_GivenDynamicArrayOfAddresses_ThenDecodesCorrectly() { do { - let addresses: [EthereumAddress] = ["0x26fc876db425b44bf6c377a7beef65e9ebad0ec3", - "0x25a01a05c188dacbcf1d61af55d4a5b4021f7eed", - "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", - "0x8c2dc702371d73febc50c6e6ced100bf9dbcb029", - "0x007eedb5044ed5512ed7b9f8b42fe3113452491e"] + let addresses: [EthereumAddress] = [ + "0x26fc876db425b44bf6c377a7beef65e9ebad0ec3", + "0x25a01a05c188dacbcf1d61af55d4a5b4021f7eed", + "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "0x8c2dc702371d73febc50c6e6ced100bf9dbcb029", + "0x007eedb5044ed5512ed7b9f8b42fe3113452491e" + ] let result = try ABIDecoder.decodeData("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000026fc876db425b44bf6c377a7beef65e9ebad0ec300000000000000000000000025a01a05c188dacbcf1d61af55d4a5b4021f7eed000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000008c2dc702371d73febc50c6e6ced100bf9dbcb029000000000000000000000000007eedb5044ed5512ed7b9f8b42fe3113452491e", types: [ABIArray.self]) XCTAssertEqual(try result[0].decodedArray(), addresses) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -232,7 +234,7 @@ class ABIDecoderTests: XCTestCase { let result = try ABIDecoder.decodeData("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003", types: [ABIArray.self]) XCTAssertEqual(try result[0].decodedArray(), values) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -242,7 +244,7 @@ class ABIDecoderTests: XCTestCase { do { let value = try ABIDecoder.decodeData("0x", types: [BigInt.self]) XCTAssertEqual(try value[0].decoded(), BigInt(0)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -252,7 +254,7 @@ class ABIDecoderTests: XCTestCase { do { let value = try ABIDecoder.decodeData("0x", types: [BigUInt.self]) XCTAssertEqual(try value[0].decoded(), BigUInt(0)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -262,7 +264,7 @@ class ABIDecoderTests: XCTestCase { do { let value = try ABIDecoder.decodeData("0x", types: [UInt64.self]) XCTAssertEqual(try value[0].decoded(), UInt64(0)) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -272,7 +274,7 @@ class ABIDecoderTests: XCTestCase { do { _ = try ABIDecoder.decodeData("0x", types: [EthereumAddress.self]) XCTFail() - } catch let error { + } catch { print(error.localizedDescription) } } @@ -281,7 +283,7 @@ class ABIDecoderTests: XCTestCase { do { _ = try ABIDecoder.decodeData("0x", types: [Bool.self]) XCTFail() - } catch let error { + } catch { print(error.localizedDescription) } } @@ -290,7 +292,7 @@ class ABIDecoderTests: XCTestCase { do { let data = try ABIDecoder.decodeData("0x", types: [Data.self]) XCTAssertEqual(try data[0].decoded(), Data()) - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -300,7 +302,7 @@ class ABIDecoderTests: XCTestCase { do { let data = try ABIDecoder.decodeData("0x", types: [String.self]) XCTAssertEqual(try data[0].decoded(), "") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -310,7 +312,7 @@ class ABIDecoderTests: XCTestCase { do { _ = try ABIDecoder.decodeData("0x", types: [String.self, String.self]) XCTFail() - } catch let error { + } catch { print(error.localizedDescription) } } @@ -319,7 +321,7 @@ class ABIDecoderTests: XCTestCase { do { _ = try ABIDecoder.decodeData("0x", types: [String.self], asArray: true) XCTFail() - } catch let error { + } catch { print(error.localizedDescription) } } @@ -350,10 +352,12 @@ class ABIDecoderTests: XCTestCase { do { let value = try ABIDecoder.decodeData("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001007efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790ba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569623774726c746c66353637647171336a766f6b37336b3776706e6b7864713367663665766a326c74657a7a7a7a6871756336656100000000000000000000000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569657a706165676378796c74707733716a6d78746678716961646471627264727a6f79766d62616768716468776875756c6963697900000000000000000000", types: [LongTuple.self]) - XCTAssertEqual(try value[0].decoded(), LongTuple(value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", - value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", - value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, - value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")!)) + XCTAssertEqual(try value[0].decoded(), LongTuple( + value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", + value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", + value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, + value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")! + )) } catch { print(error.localizedDescription) XCTFail() @@ -365,8 +369,9 @@ class ABIDecoderTests: XCTestCase { let value = try ABIDecoder.decodeData("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000064d0ea4fc60f27e74f1a70aa6f39d403bbe56793000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000003c1bd6b420448cf16a389c8b0115ccb3660bb8540000000000000000000000000000000000000000000000000000000000000078", types: [ABIArray.self]) XCTAssertEqual(try value[0].decodedTupleArray(), [ - SimpleTuple(address: "0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793", amount: 30), - SimpleTuple(address: "0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854", amount: 120)]) + SimpleTuple(address: "0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793", amount: 30), + SimpleTuple(address: "0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854", amount: 120) + ]) } catch { print(error.localizedDescription) XCTFail() @@ -377,14 +382,17 @@ class ABIDecoderTests: XCTestCase { do { let value = try ABIDecoder.decodeData("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001007efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790ba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569623774726c746c66353637647171336a766f6b37336b3776706e6b7864713367663665766a326c74657a7a7a7a6871756336656100000000000000000000000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569657a706165676378796c74707733716a6d78746678716961646471627264727a6f79766d62616768716468776875756c6963697900000000000000000000", types: [ABIArray.self]) - XCTAssertEqual(try value[0].decodedTupleArray(), - [ - LongTuple(value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", - value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", - value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, - value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")!) - - ]) + XCTAssertEqual( + try value[0].decodedTupleArray(), + [ + LongTuple( + value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", + value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", + value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, + value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")! + ) + ] + ) } catch { print(error.localizedDescription) XCTFail() diff --git a/Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift index 7540a476..361b3da7 100644 --- a/Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift +++ b/Tests/Web3SwiftTests/Contract/ABIEncoderTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ABIEncoderTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ABIEncoderTests: XCTestCase { func testGivenSmallBigUInt_EncodesCorrectly() { @@ -100,8 +100,10 @@ class ABIEncoderTests: XCTestCase { func testGivenBytes1_EncodesCorrectly() { let encoded = try? ABIEncoder.encode("0x63".web3.hexData!, staticSize: 1) - XCTAssertEqual(encoded?.hexString, - "0x6300000000000000000000000000000000000000000000000000000000000000") + XCTAssertEqual( + encoded?.hexString, + "0x6300000000000000000000000000000000000000000000000000000000000000" + ) } func testGivenBytes3_EncodesCorrectly() { @@ -143,5 +145,4 @@ class ABIEncoderTests: XCTestCase { let encoded = try? ABIEncoder.encode(["hello", "big", "world"]) XCTAssertEqual(encoded?.hexString, "0x000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000362696700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000") } - } diff --git a/Tests/Web3SwiftTests/Contract/ABIEventTests.swift b/Tests/Web3SwiftTests/Contract/ABIEventTests.swift index de1e8b72..7b7d3763 100644 --- a/Tests/Web3SwiftTests/Contract/ABIEventTests.swift +++ b/Tests/Web3SwiftTests/Contract/ABIEventTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ABIEventTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ABIEventTests: XCTestCase { var client: EthereumClientProtocol! @@ -14,16 +14,18 @@ class ABIEventTests: XCTestCase { super.setUp() client = EthereumHttpClient(url: URL(string: TestConfig.clientUrl)!, network: TestConfig.network) } - + func test_givenEventWithData4_ItParsesCorrectly() async { do { let encodedAddress = (try? ABIEncoder.encode(EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F")).bytes) ?? [] - let eventsResult = try await client.getEvents(addresses: nil, - topics: [try? AddressAndData4Event.signature(), String(hexFromBytes: encodedAddress), nil], - fromBlock: .Number(4916814 ), - toBlock: .Number(4916814 ), - eventTypes: [AddressAndData4Event.self]) + let eventsResult = try await client.getEvents( + addresses: nil, + topics: [try? AddressAndData4Event.signature(), String(hexFromBytes: encodedAddress), nil], + fromBlock: .Number(4916814), + toBlock: .Number(4916814), + eventTypes: [AddressAndData4Event.self] + ) let eventFirst = eventsResult.events.first as? AddressAndData4Event XCTAssertEqual(eventFirst?.address, EthereumAddress("0x787411394Ccb38483a6F303FDee075f3EA67D65F")) @@ -39,13 +41,15 @@ class ABIEventTests: XCTestCase { func test_givenEventWithData32_ItParsesCorrectly() async { do { - let eventsResult = try await client.getEvents(addresses: nil, - topics: [try? AddressAndData32Event.signature()], - fromBlock: .Number( - 4916812 ), - toBlock: .Number( - 4916812 ), - eventTypes: [AddressAndData32Event.self]) + let eventsResult = try await client.getEvents( + addresses: nil, + topics: [try? AddressAndData32Event.signature()], + fromBlock: .Number( + 4916812), + toBlock: .Number( + 4916812), + eventTypes: [AddressAndData32Event.self] + ) XCTAssertEqual(eventsResult.events.count, 1) let event = eventsResult.events.first as? AddressAndData32Event @@ -79,7 +83,6 @@ struct AddressAndData4Event: ABIEvent { self.address = try topics[0].decoded() self.data = try topics[1].decoded() - } } diff --git a/Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift b/Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift index 28b05d89..d4b49020 100644 --- a/Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift +++ b/Tests/Web3SwiftTests/Contract/ABIFunctionEncoderTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ABIFunctionEncoderTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ABIFunctionEncoderTests: XCTestCase { var encoder: ABIFunctionEncoder! @@ -99,11 +99,13 @@ class ABIFunctionEncoderTests: XCTestCase { } func testGivenArrayOfAddressses_ThenEncodesCorrectly() { - let addresses: [EthereumAddress] = ["0x26fc876db425b44bf6c377a7beef65e9ebad0ec3", - "0x25a01a05c188dacbcf1d61af55d4a5b4021f7eed", - "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", - "0x8c2dc702371d73febc50c6e6ced100bf9dbcb029", - "0x007eedb5044ed5512ed7b9f8b42fe3113452491e"] + let addresses: [EthereumAddress] = [ + "0x26fc876db425b44bf6c377a7beef65e9ebad0ec3", + "0x25a01a05c188dacbcf1d61af55d4a5b4021f7eed", + "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "0x8c2dc702371d73febc50c6e6ced100bf9dbcb029", + "0x007eedb5044ed5512ed7b9f8b42fe3113452491e" + ] XCTAssertNoThrow(try encoder.encode(addresses)) let encoded = try! encoder.encoded() @@ -130,7 +132,7 @@ class ABIFunctionEncoderTests: XCTestCase { let exec = RelayerWithData32Execute(from: nil, gasPrice: nil, gasLimit: nil, signatures: signatures) let execData = try! exec.transaction().data! - XCTAssertEqual(execData.web3.hexString, "0x8af7c64900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002450298c35b4713c9722b9b771f67d004ece1d25cbd33534e5932ea88172d23e97efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790") + XCTAssertEqual(execData.web3.hexString, "0x8af7c64900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002450298c35b4713c9722b9b771f67d004ece1d25cbd33534e5932ea88172d23e97efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790") } func testGivenArrayOfBigUInt_ThenEncodesCorrectly() { @@ -158,7 +160,7 @@ class ABIFunctionEncoderTests: XCTestCase { do { try encoder.encode(tuple) XCTAssertEqual(try encoder.encoded().web3.hexString, "0xba71720c00000000000000000000000064d0ea4fc60f27e74f1a70aa6f39d403bbe56793000000000000000000000000000000000000000000000000000000000000001e") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -170,7 +172,7 @@ class ABIFunctionEncoderTests: XCTestCase { do { try encoder.encode(tuple) XCTAssertEqual(try encoder.encoded().web3.hexString, "0xd6c9f12a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000") - } catch let error { + } catch { print(error.localizedDescription) XCTFail() } @@ -182,32 +184,37 @@ class ABIFunctionEncoderTests: XCTestCase { do { try encoder.encode(tuple) try encoder.encode(BigUInt(1)) - XCTAssertEqual(try encoder.encoded().web3.hexString, - "0x969569a200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000") - } catch let error { + XCTAssertEqual( + try encoder.encoded().web3.hexString, + "0x969569a200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000036162630000000000000000000000000000000000000000000000000000000000" + ) + } catch { print(error.localizedDescription) XCTFail() } } func test_GivenLongTupleArgument_ThenEncodesCorrectly() { - let tuple = LongTuple(value1: "https://ethereum.org/abcde", - value2: "https://ethereum.org/xyz", - value3: Data(hex: "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8")!, - value4: Data(hex: "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0")!) + let tuple = LongTuple( + value1: "https://ethereum.org/abcde", + value2: "https://ethereum.org/xyz", + value3: Data(hex: "0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8")!, + value4: Data(hex: "0x8452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0")! + ) let encoder = ABIFunctionEncoder("TestLongTuple") try? encoder.encode(tuple) XCTAssertEqual(try? encoder.encoded().web3.hexString, "0xfe83fc010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c01c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac88452c9b9140222b08593a26daa782707297be9f7b3e8281d7b4974769f19afd0000000000000000000000000000000000000000000000000000000000000001a68747470733a2f2f657468657265756d2e6f72672f6162636465000000000000000000000000000000000000000000000000000000000000000000000000001868747470733a2f2f657468657265756d2e6f72672f78797a0000000000000000") - } func test_GivenSomeArgumentsAndLongTuple_ThenEncodesCorrectly() { - let tuple = LongTuple(value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", - value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", - value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, - value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")!) + let tuple = LongTuple( + value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", + value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", + value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, + value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")! + ) let encoder = ABIFunctionEncoder("TestLongTuple") try? encoder.encode(tuple) @@ -215,19 +222,21 @@ class ABIFunctionEncoderTests: XCTestCase { try? encoder.encode(BigUInt(hex: "0xa688906bd8b00000")!) try? encoder.encode(BigUInt(hex: "0x4c53ecdc18a600000")!) XCTAssertEqual(try? encoder.encoded().web3.hexString, "0x51746d2300000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a688906bd8b00000000000000000000000000000000000000000000000000004c53ecdc18a600000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001007efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790ba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569623774726c746c66353637647171336a766f6b37336b3776706e6b7864713367663665766a326c74657a7a7a7a6871756336656100000000000000000000000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569657a706165676378796c74707733716a6d78746678716961646471627264727a6f79766d62616768716468776875756c6963697900000000000000000000") - } func testGivenArrayOfTuples_ThenEncodesCorrectly() { let tuples = [ SimpleTuple(address: "0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793", amount: 30), - SimpleTuple(address: "0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854", amount: 120)] + SimpleTuple(address: "0x3C1Bd6B420448Cf16A389C8b0115CCB3660bB854", amount: 120) + ] do { try encoder.encode(tuples) - XCTAssertEqual(try encoder.encoded().web3.hexString, - "0xae4f5efa0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000064d0ea4fc60f27e74f1a70aa6f39d403bbe56793000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000003c1bd6b420448cf16a389c8b0115ccb3660bb8540000000000000000000000000000000000000000000000000000000000000078") - } catch let error { + XCTAssertEqual( + try encoder.encoded().web3.hexString, + "0xae4f5efa0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000064d0ea4fc60f27e74f1a70aa6f39d403bbe56793000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000003c1bd6b420448cf16a389c8b0115ccb3660bb8540000000000000000000000000000000000000000000000000000000000000078" + ) + } catch { print(error.localizedDescription) XCTFail() } @@ -242,8 +251,10 @@ class ABIFunctionEncoderTests: XCTestCase { try encoder.encode([UInt32]([0x456, 0x789])) try encoder.encode("1234567890".data(using: .utf8)!, staticSize: 10) try encoder.encode("Hello, world!".data(using: .utf8)!) - XCTAssertEqual(try encoder.encoded().web3.hexString, - "0x8be6524600000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000") + XCTAssertEqual( + try encoder.encoded().web3.hexString, + "0x8be6524600000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000" + ) } catch { XCTFail() } @@ -254,8 +265,10 @@ class ABIFunctionEncoderTests: XCTestCase { let tuple = ComplexTupleWithArray(address: "0xdF136715f7bafD40881cFb16eAa5595C2562972b", amount: 2, owners: [SimpleTuple(address: "0xdF136715f7bafD40881cFb16eAa5595C2562972b", amount: 100)]) try encoder.encode([tuple]) - XCTAssertEqual(try encoder.encoded().web3.hexString, - "0x07e0fd75000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b0000000000000000000000000000000000000000000000000000000000000064") + XCTAssertEqual( + try encoder.encoded().web3.hexString, + "0x07e0fd75000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b0000000000000000000000000000000000000000000000000000000000000064" + ) } catch { XCTFail() } @@ -266,28 +279,33 @@ class ABIFunctionEncoderTests: XCTestCase { let tuple1 = ComplexTupleWithArray(address: "0xdF136715f7bafD40881cFb16eAa5595C2562972b", amount: 2, owners: [SimpleTuple(address: "0x4bf21a47b608841e974ff4147fd1a005da7fdf9b", amount: 100)]) let tuple2 = ComplexTupleWithArray(address: "0x69F84b91E7107206E841748C2B52294A1176D45e", amount: 3, owners: [SimpleTuple(address: "0xc07d381fFadB957e0FC9218AaBa88556f5C4BB7a", amount: 200)]) try encoder.encode([tuple1, tuple2]) - XCTAssertEqual(try encoder.encoded().web3.hexString, - "0x07e0fd750000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000004bf21a47b608841e974ff4147fd1a005da7fdf9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000069f84b91e7107206e841748c2b52294a1176d45e000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c07d381ffadb957e0fc9218aaba88556f5c4bb7a00000000000000000000000000000000000000000000000000000000000000c8") + XCTAssertEqual( + try encoder.encoded().web3.hexString, + "0x07e0fd750000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100000000000000000000000000df136715f7bafd40881cfb16eaa5595c2562972b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000004bf21a47b608841e974ff4147fd1a005da7fdf9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000069f84b91e7107206e841748c2b52294a1176d45e000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c07d381ffadb957e0fc9218aaba88556f5c4bb7a00000000000000000000000000000000000000000000000000000000000000c8" + ) } catch { XCTFail() } } func test_GivenLongTupleAndSimpleTupleOfTuples_EncodesCorrectly() { - let tuple = LongTuple(value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", - value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", - value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, - value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")!) - - let tupleOfTuples = TupleOfTuples(value1: NumberTuple(value: 0), - value2: NumberTuple(value: BigUInt(hex: "0xa688906bd8b00000")!), - value3: NumberTuple(value: BigUInt(hex: "0x4c53ecdc18a600000")!)) + let tuple = LongTuple( + value1: "https://ipfs.fleek.co/ipfs/bafybeib7trltlf567dqq3jvok73k7vpnkxdq3gf6evj2ltezzzzhquc6ea", + value2: "https://ipfs.fleek.co/ipfs/bafybeiezpaegcxyltpw3qjmxtfxqiaddqbrdrzoyvmbaghqdhwhuuliciy", + value3: Data(hex: "0x7efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790")!, + value4: Data(hex: "0xba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029")! + ) + + let tupleOfTuples = TupleOfTuples( + value1: NumberTuple(value: 0), + value2: NumberTuple(value: BigUInt(hex: "0xa688906bd8b00000")!), + value3: NumberTuple(value: BigUInt(hex: "0x4c53ecdc18a600000")!) + ) let encoder = ABIFunctionEncoder("mint") try? encoder.encode(tuple) try? encoder.encode(tupleOfTuples) XCTAssertEqual(try? encoder.encoded().web3.hexString, "0x2cca323700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a688906bd8b00000000000000000000000000000000000000000000000000004c53ecdc18a600000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001007efef35dcd300eec8819c4ce5cb6b57be685254d583954273c5cc16edee83790ba42a7d804d9eff383efb1864514f5f15c82f1c333a777dd8f76dba1c1977029000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569623774726c746c66353637647171336a766f6b37336b3776706e6b7864713367663665766a326c74657a7a7a7a6871756336656100000000000000000000000000000000000000000000000000000000000000000000000000000000005668747470733a2f2f697066732e666c65656b2e636f2f697066732f62616679626569657a706165676378796c74707733716a6d78746678716961646471627264727a6f79766d62616768716468776875756c6963697900000000000000000000") - } } @@ -297,8 +315,10 @@ struct SimpleTuple: ABITuple, Equatable { var address: EthereumAddress var amount: BigUInt - init(address: EthereumAddress, - amount: BigUInt) { + init( + address: EthereumAddress, + amount: BigUInt + ) { self.address = address self.amount = amount } @@ -324,10 +344,12 @@ struct LongTuple: ABITuple, Equatable { var value3: Data var value4: Data - init(value1: String, - value2: String, - value3: Data, - value4: Data) { + init( + value1: String, + value2: String, + value3: Data, + value4: Data + ) { self.value1 = value1 self.value2 = value2 self.value3 = value3 @@ -378,9 +400,11 @@ private struct ComplexTupleWithArray: ABITuple { var amount: BigUInt var owners: [SimpleTuple] - init(address: EthereumAddress, - amount: BigUInt, - owners: [SimpleTuple]) { + init( + address: EthereumAddress, + amount: BigUInt, + owners: [SimpleTuple] + ) { self.address = address self.amount = amount self.owners = owners @@ -411,9 +435,7 @@ private struct RelayerExecute: ABIFunction { struct Response: ABIResponse { static var types: [ABIType.Type] = [] - init?(values: [ABIDecoder.DecodedValue]) throws { - - } + init?(values: [ABIDecoder.DecodedValue]) throws {} } let wallet: EthereumAddress @@ -443,9 +465,7 @@ private struct RelayerWithData32Execute: ABIFunction { struct Response: ABIResponse { static var types: [ABIType.Type] = [] - init?(values: [ABIDecoder.DecodedValue]) throws { - - } + init?(values: [ABIDecoder.DecodedValue]) throws {} } let signatures: [Data32] @@ -455,7 +475,6 @@ private struct RelayerWithData32Execute: ABIFunction { } } - struct NumberTuple: ABITuple, Equatable { func encode(to encoder: ABIFunctionEncoder) throws { try encoder.encode(value) @@ -489,9 +508,11 @@ struct TupleOfTuples: ABITuple { var value2: NumberTuple var value3: NumberTuple - init(value1: NumberTuple, - value2: NumberTuple, - value3: NumberTuple) { + init( + value1: NumberTuple, + value2: NumberTuple, + value3: NumberTuple + ) { self.value1 = value1 self.value2 = value2 self.value3 = value3 diff --git a/Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift b/Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift index 08c914b8..47099907 100644 --- a/Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift +++ b/Tests/Web3SwiftTests/Contract/ABIFunctionTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ABIFunctionTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 struct Deposit_NoParameter: ABIFunction { static let name = "deposit" @@ -14,8 +14,7 @@ struct Deposit_NoParameter: ABIFunction { var contract: EthereumAddress = "0xFFB9239F43673068E3c8D7664382Dd6Fdd6e40cb" let from: EthereumAddress? = nil - func encode(to encoder: ABIFunctionEncoder) throws { - } + func encode(to encoder: ABIFunctionEncoder) throws {} } struct BalanceOf_Parameter: ABIFunction { diff --git a/Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift b/Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift index 7713451b..0f7cb9a7 100644 --- a/Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift +++ b/Tests/Web3SwiftTests/ENS/ENSOffchainTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// ENSOffchainTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class ENSOffchainTests: XCTestCase { var account: EthereumAccount? @@ -19,15 +19,14 @@ class ENSOffchainTests: XCTestCase { XCTAssertEqual( EthereumNameService.dnsEncode(name: "offchainexample.eth").web3.hexString, "0x0f6f6666636861696e6578616d706c650365746800" - ) + ) XCTAssertEqual( EthereumNameService.dnsEncode(name: "1.offchainexample.eth").web3.hexString, "0x01310f6f6666636861696e6578616d706c650365746800" - ) - + ) } - // TODO [Tests] Disabled until we can test with proper offchain ENS set up + // TODO: [Tests] Disabled until we can test with proper offchain ENS set up // func testGivenRegistry_WhenResolvingOffchainENS_ResolvesCorrectly() async { // do { // let nameService = EthereumNameService(client: client!) diff --git a/Tests/Web3SwiftTests/ENS/ENSTests.swift b/Tests/Web3SwiftTests/ENS/ENSTests.swift index aede4b3b..753cdd36 100644 --- a/Tests/Web3SwiftTests/ENS/ENSTests.swift +++ b/Tests/Web3SwiftTests/ENS/ENSTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// ENSTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class ENSTests: XCTestCase { var account: EthereumAccount? @@ -30,7 +30,7 @@ class ENSTests: XCTestCase { let tx = try function.transaction() let dataStr = try await client?.eth_call(tx, resolution: .noOffchain(failOnExecutionError: true), block: .Latest) - guard let dataStr = dataStr else { + guard let dataStr else { XCTFail() return } @@ -154,9 +154,10 @@ class ENSTests: XCTestCase { .couldNotBeResolved(.ensUnknown), .resolved("darthmike.eth") ] - ) } catch { - XCTFail("Expected resolutions but failed \(error).") - } + ) + } catch { + XCTFail("Expected resolutions but failed \(error).") + } } func testGivenRegistry_ThenResolvesSingleAddressWithMultiCall() async { @@ -176,9 +177,10 @@ class ENSTests: XCTestCase { [ .resolved("darhmike.eth") ] - ) } catch { - XCTFail("Expected resolutions but failed \(error).") - } + ) + } catch { + XCTFail("Expected resolutions but failed \(error).") + } } func testGivenRegistry_WhenAddressHasSubdomain_ThenResolvesSingleAddressWithMultiCall() async { @@ -198,9 +200,10 @@ class ENSTests: XCTestCase { [ .resolved("subdomain.darhmike.eth") ] - ) } catch { - XCTFail("Expected resolutions but failed \(error).") - } + ) + } catch { + XCTFail("Expected resolutions but failed \(error).") + } } func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenDoesNotResolveSingleAddressWithMultiCall() async { @@ -220,9 +223,10 @@ class ENSTests: XCTestCase { [ .couldNotBeResolved(.ensUnknown) ] - ) } catch { - XCTFail("Expected resolutions but failed \(error).") - } + ) + } catch { + XCTFail("Expected resolutions but failed \(error).") + } } func testGivenRegistry_WhenAddressHasSubdomain_AndReverseRecordNotSet_ThenResolvesENSWithMultiCall() async { @@ -269,7 +273,7 @@ class ENSTests: XCTestCase { } } - // TODO [Tests] Temporarily removed until set up for offchain ENS is done + // TODO: [Tests] Temporarily removed until set up for offchain ENS is done // func testGivenMainnetRegistry_WhenWildcardSupported_AndAddressHasSubdomain_ThenResolvesExampleCorrectly() async { // do { // let nameService = EthereumNameService(client: client!) diff --git a/Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift b/Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift index fe00773e..338914fd 100644 --- a/Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift +++ b/Tests/Web3SwiftTests/ERC1271/ERC1271Tests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// ERC1271Tests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class ERC1271Tests: XCTestCase { var client: EthereumClientProtocol! @@ -103,7 +103,6 @@ class ERC1271Tests: XCTestCase { } final class ERC1271WebSocketTests: ERC1271Tests { - override func setUp() { if self.client == nil { self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, network: TestConfig.network) diff --git a/Tests/Web3SwiftTests/ERC165/ERC165Tests.swift b/Tests/Web3SwiftTests/ERC165/ERC165Tests.swift index 690c198a..cff3d45c 100644 --- a/Tests/Web3SwiftTests/ERC165/ERC165Tests.swift +++ b/Tests/Web3SwiftTests/ERC165/ERC165Tests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ERC165Tests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ERC165Tests: XCTestCase { var client: EthereumClientProtocol! diff --git a/Tests/Web3SwiftTests/ERC20/ERC20Tests.swift b/Tests/Web3SwiftTests/ERC20/ERC20Tests.swift index 49b2cf5f..d747b371 100644 --- a/Tests/Web3SwiftTests/ERC20/ERC20Tests.swift +++ b/Tests/Web3SwiftTests/ERC20/ERC20Tests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ERC20Tests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ERC20Tests: XCTestCase { var client: EthereumClientProtocol? @@ -62,10 +62,10 @@ class ERC20Tests: XCTestCase { do { let result = try! ABIEncoder.encode(EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41")) let sig = try! ERC20Events.Transfer.signature() - let topics = [ sig, result.hexString] + let topics = [sig, result.hexString] let eventResults = try await client?.getEvents(addresses: nil, topics: topics, fromBlock: .Earliest, toBlock: .Latest, eventTypes: [ERC20Events.Transfer.self]) - XCTAssert(eventResults!.events.count > 0) + XCTAssert(!eventResults!.events.isEmpty) } catch { XCTFail("Expected eventResults but failed \(error).") } @@ -74,7 +74,7 @@ class ERC20Tests: XCTestCase { func testGivenAddressWithInTransfers_ThenGetsTheTransferEvents() async { do { let events = try await erc20?.transferEventsTo(recipient: "0x162142f0508F557C02bEB7C473682D7C91Bcef41", fromBlock: .Earliest, toBlock: .Latest) - XCTAssert(events!.count > 0) + XCTAssert(!events!.isEmpty) } catch { XCTFail("Expected events but failed \(error).") } diff --git a/Tests/Web3SwiftTests/ERC721/ERC721Tests.swift b/Tests/Web3SwiftTests/ERC721/ERC721Tests.swift index 32a1ecc1..fb93c894 100644 --- a/Tests/Web3SwiftTests/ERC721/ERC721Tests.swift +++ b/Tests/Web3SwiftTests/ERC721/ERC721Tests.swift @@ -1,14 +1,14 @@ // -// web3.swift +// ERC721Tests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 #if canImport(FoundationNetworking) -import FoundationNetworking + import FoundationNetworking #endif let tokenOwner = EthereumAddress("0x162142f0508F557C02bEB7C473682D7C91Bcef41") @@ -66,11 +66,13 @@ class ERC721Tests: XCTestCase { func test_GivenAddressWithTransfer_FindsInTransferEvent() async { do { - let events = try await erc721.transferEventsTo(recipient: tokenOwner, - fromBlock: .Number( - 4916900 ), - toBlock: .Number( - 4916900 )) + let events = try await erc721.transferEventsTo( + recipient: tokenOwner, + fromBlock: .Number( + 4916900), + toBlock: .Number( + 4916900) + ) XCTAssertEqual(events.first?.from, previousOwner) XCTAssertEqual(events.first?.to, tokenOwner) XCTAssertEqual(events.first?.tokenId, 0) @@ -81,11 +83,13 @@ class ERC721Tests: XCTestCase { func test_GivenAddressWithTransfer_FindsOutTransferEvent() async { do { - let events = try await erc721.transferEventsFrom(sender: previousOwner, - fromBlock: .Number( - 4916900), - toBlock: .Number( - 4916900)) + let events = try await erc721.transferEventsFrom( + sender: previousOwner, + fromBlock: .Number( + 4916900), + toBlock: .Number( + 4916900) + ) XCTAssertEqual(events.first?.to, tokenOwner) XCTAssertEqual(events.first?.from, previousOwner) XCTAssertEqual(events.first?.tokenId, 0) diff --git a/Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift index 544b77b1..9a51981c 100644 --- a/Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift +++ b/Tests/Web3SwiftTests/Extensions/ByteExtensionsTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ByteExtensionsTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class ByteExtensionsTests: XCTestCase { func testBytesFromBigInt() { @@ -95,5 +95,4 @@ class ByteExtensionsTests: XCTestCase { let result = dataA ^ dataB XCTAssertEqual(result.web3.hexString, "0x5b5e139fc6568dcbe817e85f5006fe073fedbf54f63f8f5c5db6f4b41a3451") } - } diff --git a/Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift b/Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift index 4e55d5d6..2726c25e 100644 --- a/Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift +++ b/Tests/Web3SwiftTests/Extensions/Data+RandomTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// Data+RandomTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class Data_RandomTests: XCTestCase { - override func setUp() { super.setUp() } @@ -25,5 +24,4 @@ class Data_RandomTests: XCTestCase { let data = Data.randomOfLength(32)! XCTAssertEqual(data.count, 32) } - } diff --git a/Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift index 4104e484..cd23ff4d 100644 --- a/Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift +++ b/Tests/Web3SwiftTests/Extensions/HexExtensionsTests.swift @@ -1,14 +1,13 @@ // -// web3.swift +// HexExtensionsTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class HexExtensionsTests: XCTestCase { - override func setUp() { super.setUp() } @@ -93,13 +92,13 @@ class HexExtensionsTests: XCTestCase { func testHexStringToData() { let hexString = "2b6f" let data = hexString.web3.hexData - XCTAssertEqual(data, Data( [43, 111])) + XCTAssertEqual(data, Data([43, 111])) } func testHexStringToDataPrefix() { let hexString = "0x2b6f" let data = hexString.web3.hexData - XCTAssertEqual(data, Data( [43, 111])) + XCTAssertEqual(data, Data([43, 111])) } func testHexStringFromBytes() { diff --git a/Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift b/Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift index 2c67fc7e..4ab1d435 100644 --- a/Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift +++ b/Tests/Web3SwiftTests/Extensions/KeccakExtensionsTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// KeccakExtensionsTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class KeccakExtensionsTests: XCTestCase { override func setUp() { @@ -35,5 +35,4 @@ class KeccakExtensionsTests: XCTestCase { let keccak = data.web3.keccak256 XCTAssertEqual(keccak.web3.hexString, "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad") } - } diff --git a/Tests/Web3SwiftTests/Extensions/String+NumericTests.swift b/Tests/Web3SwiftTests/Extensions/String+NumericTests.swift index 7337a3dc..fb0748a0 100644 --- a/Tests/Web3SwiftTests/Extensions/String+NumericTests.swift +++ b/Tests/Web3SwiftTests/Extensions/String+NumericTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// String+NumericTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class String_NumericTests: XCTestCase { - override func setUp() { super.setUp() } @@ -28,5 +27,4 @@ class String_NumericTests: XCTestCase { XCTAssertFalse("!9043".web3.isNumeric) XCTAssertFalse("#42044".web3.isNumeric) } - } diff --git a/Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift b/Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift index 542bd6e4..40214f70 100644 --- a/Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift +++ b/Tests/Web3SwiftTests/Mocks/TestEthereumKeyStorage.swift @@ -1,56 +1,49 @@ // -// web3.swift +// TestEthereumKeyStorage.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import Foundation @testable import web3 +import Foundation class TestEthereumKeyStorage: EthereumSingleKeyStorageProtocol { - private var privateKey: String init(privateKey: String) { self.privateKey = privateKey } - func storePrivateKey(key: Data) throws { - } + func storePrivateKey(key: Data) throws {} func loadPrivateKey() throws -> Data { - return privateKey.web3.hexData! + privateKey.web3.hexData! } } class TestEthereumMultipleKeyStorage: EthereumMultipleKeyStorageProtocol { - private var privateKey: String - + init(privateKey: String) { self.privateKey = privateKey } - - func storePrivateKey(key: Data) throws -> Void { - } + + func storePrivateKey(key: Data) throws {} func loadPrivateKey() throws -> Data { - return privateKey.web3.hexData! + privateKey.web3.hexData! } - + func fetchAccounts() throws -> [EthereumAddress] { - return [] + [] } - func storePrivateKey(key: Data, with address: EthereumAddress) throws -> Void { - } + func storePrivateKey(key: Data, with address: EthereumAddress) throws {} func loadPrivateKey(for address: EthereumAddress) throws -> Data { - return privateKey.web3.hexData! + privateKey.web3.hexData! } - func deletePrivateKey(for address: EthereumAddress) throws { - } + func deletePrivateKey(for address: EthereumAddress) throws {} - func deleteAllKeys() throws { - } + func deleteAllKeys() throws {} } diff --git a/Tests/Web3SwiftTests/Multicall/MulticallTests.swift b/Tests/Web3SwiftTests/Multicall/MulticallTests.swift index c12de471..cb39780e 100644 --- a/Tests/Web3SwiftTests/Multicall/MulticallTests.swift +++ b/Tests/Web3SwiftTests/Multicall/MulticallTests.swift @@ -1,10 +1,10 @@ // -// web3.swift +// MulticallTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class MulticallTests: XCTestCase { var client: EthereumClientProtocol! @@ -38,7 +38,7 @@ class MulticallTests: XCTestCase { do { let response = try await multicall.aggregate(calls: aggregator.calls) - let symbol = try ERC20Responses.symbolResponse(data: try response.outputs[2].get())?.value + let symbol = try ERC20Responses.symbolResponse(data: response.outputs[2].get())?.value XCTAssertEqual(symbol, "USDC") } catch { XCTFail("Unexpected failure while handling output") @@ -47,7 +47,7 @@ class MulticallTests: XCTestCase { XCTAssertEqual(decimals, 6) XCTAssertEqual(name, "USD Coin") } - + func testNameAndSymbolMulticall2() async throws { var aggregator = Multicall.Aggregator() diff --git a/Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift b/Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift index 74003637..3554cd34 100644 --- a/Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift +++ b/Tests/Web3SwiftTests/OffchainLookup/OffchainLookupTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// OffchainLookupTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 struct DummyOffchainENSResolve: ABIFunction { static var name: String = "resolver" @@ -130,10 +130,10 @@ enum EthersTestContract { extension EthereumClientError { var executionError: JSONRPCErrorDetail? { switch self { - case .executionError(let detail): - return detail + case let .executionError(detail): + detail default: - return nil + nil } } } @@ -142,7 +142,7 @@ class OffchainLookupTests: XCTestCase { var client: EthereumClientProtocol! var account: EthereumAccount! var offchainLookup = OffchainLookup(address: .zero, urls: [], callData: Data(), callbackFunction: Data(), extraData: Data()) - + override func setUp() { super.setUp() client = EthereumHttpClient(url: URL(string: TestConfig.clientUrl)!, network: TestConfig.network) @@ -159,7 +159,7 @@ class OffchainLookupTests: XCTestCase { do { _ = try await client.eth_call(tx, resolution: .noOffchain(failOnExecutionError: true), block: .Latest) XCTFail("Expecting error, not return value") - } catch let error { + } catch { let error = (error as? EthereumClientError)?.executionError let decoded = try? error?.decode(error: offchainLookup) @@ -172,7 +172,7 @@ class OffchainLookupTests: XCTestCase { } } - // TODO [Tests] Disabled for now until we reimplement on our side (ethers.js tests setup using goerli) + // TODO: [Tests] Disabled for now until we reimplement on our side (ethers.js tests setup using goerli) // func test_GivenTestFunction_WhenLookupCorrect_ThenDecodesRetrievesValue() async throws { // let function = EthersTestContract.TestGet(data: "0x1234".web3.hexData!) // @@ -324,8 +324,8 @@ private func expectedResponse( senderData.web3.bytes, [UInt8(data.count)], data.web3.bytes - ] - .flatMap { $0 } + ] + .flatMap { $0 } ).web3.keccak256.web3.hexString } diff --git a/Tests/Web3SwiftTests/SIWE/SIWETests.swift b/Tests/Web3SwiftTests/SIWE/SIWETests.swift index e48895c8..e1258a63 100644 --- a/Tests/Web3SwiftTests/SIWE/SIWETests.swift +++ b/Tests/Web3SwiftTests/SIWE/SIWETests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// SIWETests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class SIWETests: XCTestCase { - var client: EthereumClientProtocol! var verifier: SiweVerifier! @@ -20,7 +19,7 @@ class SIWETests: XCTestCase { } func testEndToEnd() async { - let account = try! EthereumAccount.init(keyStorage: TestEthereumKeyStorage(privateKey: "0x4646464646464646464646464646464646464646464646464646464646464646")) + let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "0x4646464646464646464646464646464646464646464646464646464646464646")) let message = try! SiweMessage( """ login.xyz wants you to sign in with your Ethereum account: @@ -42,7 +41,7 @@ class SIWETests: XCTestCase { """ ) - var signature: String = "" + var signature = "" XCTAssertNoThrow(signature = try account.signSIWERequest(message)) var isValid = false do { @@ -55,7 +54,6 @@ class SIWETests: XCTestCase { } final class SIWEWebSocketTests: SIWETests { - override func setUp() { if self.client == nil { self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, network: TestConfig.network) diff --git a/Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift b/Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift index 17402f79..9b661885 100644 --- a/Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift +++ b/Tests/Web3SwiftTests/SIWE/SiweMessageTests.swift @@ -1,5 +1,5 @@ // -// web3.swift +// SiweMessageTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // @@ -7,7 +7,6 @@ import XCTest @testable import web3 final class SiweMessageTests: XCTestCase { - private static let dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.timeZone = TimeZone(identifier: "UTC") @@ -482,8 +481,9 @@ private extension Data { func asJson(with writingOptions: JSONSerialization.WritingOptions) -> Data { guard let object = try? JSONSerialization.jsonObject(with: self, options: []), - let data = try? JSONSerialization.data(withJSONObject: object, options: writingOptions) - else { return self } + let data = try? JSONSerialization.data(withJSONObject: object, options: writingOptions) else { + return self + } return data } } diff --git a/Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift b/Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift index 7476e1d0..382f36e3 100644 --- a/Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift +++ b/Tests/Web3SwiftTests/SIWE/SiweVerifierTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// SiweVerifierTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class SiweVerifierTests: XCTestCase { - var client: EthereumClientProtocol! override func setUp() { @@ -223,7 +222,6 @@ class SiweVerifierTests: XCTestCase { } final class SiweVerifierWebSocketTests: SiweVerifierTests { - override func setUp() { if self.client == nil { self.client = EthereumWebSocketClient(url: URL(string: TestConfig.wssUrl)!, network: TestConfig.network) diff --git a/Tests/Web3SwiftTests/TestConfig.swift b/Tests/Web3SwiftTests/TestConfig.swift index ee1af851..1b85d930 100644 --- a/Tests/Web3SwiftTests/TestConfig.swift +++ b/Tests/Web3SwiftTests/TestConfig.swift @@ -1,10 +1,10 @@ // -// web3.swift +// TestConfig.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import Foundation import web3 +import Foundation struct TestConfig { // This is the proxy URL for connecting to the Blockchain. For testing we usually use the Sepolia network on Infura. Using free tier, so might hit rate limits @@ -35,15 +35,15 @@ struct TestConfig { static let network = EthereumNetwork.sepolia - enum ZKSync { - static let chainId = 280 - static let network = EthereumNetwork.custom("\(280)") - static let clientURL = URL(string: "https://zksync2-testnet.zksync.dev")! + enum ZKSync { + static let chainId = 280 + static let network = EthereumNetwork.custom("\(280)") + static let clientURL = URL(string: "https://zksync2-testnet.zksync.dev")! } } - -@discardableResult public func with(_ root: Root, _ block: (inout Root) throws -> Void) rethrows -> Root { +@discardableResult +public func with(_ root: Root, _ block: (inout Root) throws -> Void) rethrows -> Root { var copy = root try block(©) return copy diff --git a/Tests/Web3SwiftTests/Transaction/TransactionTests.swift b/Tests/Web3SwiftTests/Transaction/TransactionTests.swift index d5a8c467..3ebd6646 100644 --- a/Tests/Web3SwiftTests/Transaction/TransactionTests.swift +++ b/Tests/Web3SwiftTests/Transaction/TransactionTests.swift @@ -1,46 +1,54 @@ // -// web3.swift +// TransactionTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class TransactionTests: XCTestCase { - let withoutChainID: EthereumTransaction = EthereumTransaction(from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", - to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", - value: 0, - data: Data(), - nonce: 1, - gasPrice: 10, - gasLimit: 400000, - chainId: nil) + let withoutChainID: EthereumTransaction = .init( + from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", + to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", + value: 0, + data: Data(), + nonce: 1, + gasPrice: 10, + gasLimit: 400000, + chainId: nil + ) func test_GivenLocalTransaction_WhenTransactionOnlyWithToAndData_HashIsNil() { - let transaction = EthereumTransaction(to: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", - data: Data()) + let transaction = EthereumTransaction( + to: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", + data: Data() + ) XCTAssertNil(transaction.hash) } func test_GivenLocalTransaction_WhenTransactionDoesNotHaveNonce_HashIsNil() { - let transaction = EthereumTransaction(from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", - to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", - data: Data(), - gasPrice: 10, - gasLimit: 400000) + let transaction = EthereumTransaction( + from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", + to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", + data: Data(), + gasPrice: 10, + gasLimit: 400000 + ) XCTAssertNil(transaction.hash) } func test_GivenLocalTransaction_WhenTransactionWithNonce_HashIsCorrect() { - let transaction = EthereumTransaction(from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", - to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", - value: 0, - data: Data(), - nonce: 1, - gasPrice: 10, - gasLimit: 400000, - chainId: 5) + let transaction = EthereumTransaction( + from: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173", + to: "0x1639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7174", + value: 0, + data: Data(), + nonce: 1, + gasPrice: 10, + gasLimit: 400000, + chainId: 5 + ) XCTAssertEqual(transaction.hash?.web3.hexString, "0xec010a83061a80a01639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde71748080058080") } diff --git a/Tests/Web3SwiftTests/Utils/AesUtilTests.swift b/Tests/Web3SwiftTests/Utils/AesUtilTests.swift index 9a43ba7f..d0a172c1 100644 --- a/Tests/Web3SwiftTests/Utils/AesUtilTests.swift +++ b/Tests/Web3SwiftTests/Utils/AesUtilTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// AesUtilTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class AesUtilTests: XCTestCase { - override func setUp() { super.setUp() } @@ -22,13 +21,12 @@ class AesUtilTests: XCTestCase { let aes = Aes128Util(key: key, iv: iv) - let input = Data( [0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26, 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce, 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff, 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff, 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e, 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab, 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1, 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee]) + let input = Data([0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26, 0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce, 0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff, 0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff, 0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e, 0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab, 0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1, 0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee]) let output = aes.xcrypt(input: input) - let expected = Data( [0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10]) + let expected = Data([0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10]) XCTAssertEqual(output, expected) } - } diff --git a/Tests/Web3SwiftTests/Utils/HexUtilTests.swift b/Tests/Web3SwiftTests/Utils/HexUtilTests.swift index d69f5ce6..ba39ed25 100644 --- a/Tests/Web3SwiftTests/Utils/HexUtilTests.swift +++ b/Tests/Web3SwiftTests/Utils/HexUtilTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// HexUtilTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class HexUtilTests: XCTestCase { - override func setUp() { super.setUp() } @@ -17,16 +16,24 @@ class HexUtilTests: XCTestCase { } func testByteArray() { - guard let array = try? HexUtil.byteArray(fromHex: "") else { return XCTFail() } + guard let array = try? HexUtil.byteArray(fromHex: "") else { + return XCTFail() + } XCTAssertEqual(array, []) - guard let array1 = try? HexUtil.byteArray(fromHex: "00") else { return XCTFail() } + guard let array1 = try? HexUtil.byteArray(fromHex: "00") else { + return XCTFail() + } XCTAssertEqual(array1, [0]) - guard let array2 = try? HexUtil.byteArray(fromHex: "B6AB541600") else { return XCTFail() } + guard let array2 = try? HexUtil.byteArray(fromHex: "B6AB541600") else { + return XCTFail() + } XCTAssertEqual(array2, [182, 171, 84, 22, 0]) - guard let array3 = try? HexUtil.byteArray(fromHex: "68656c6c6f20776f726c6421") else { return XCTFail() } + guard let array3 = try? HexUtil.byteArray(fromHex: "68656c6c6f20776f726c6421") else { + return XCTFail() + } XCTAssertEqual(array3, [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]) } @@ -37,5 +44,4 @@ class HexUtilTests: XCTestCase { XCTAssertEqual(error as? HexConversionError, HexConversionError.stringNotEven) } } - } diff --git a/Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift b/Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift index 89d14826..fa1bbf36 100644 --- a/Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift +++ b/Tests/Web3SwiftTests/Utils/KeyDerivationTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// KeyDerivationTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class KeyDerivationTests: XCTestCase { - override func setUp() { super.setUp() } @@ -20,7 +19,7 @@ class KeyDerivationTests: XCTestCase { let derivator = KeyDerivator(algorithm: .pbkdf2sha256, dklen: 32, round: 4096) let result = derivator.deriveKey(key: "password", salt: "salt")! - let expected = Data( [0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41, 0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d, 0x96, 0x28, 0x93, 0xa0, 0x01, 0xce, 0x4e, 0x11, 0xa4, 0x96, 0x38, 0x73, 0xaa, 0x98, 0x13, 0x4a]) + let expected = Data([0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41, 0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d, 0x96, 0x28, 0x93, 0xa0, 0x01, 0xce, 0x4e, 0x11, 0xa4, 0x96, 0x38, 0x73, 0xaa, 0x98, 0x13, 0x4a]) XCTAssertEqual(result, expected) } @@ -29,7 +28,7 @@ class KeyDerivationTests: XCTestCase { let derivator = KeyDerivator(algorithm: .pbkdf2sha256, dklen: 64, round: 80000) let result = derivator.deriveKey(key: "Password", salt: "NaCl")! - let expected = Data( [0x4d, 0xdc, 0xd8, 0xf6, 0x0b, 0x98, 0xbe, 0x21, 0x83, 0x0c, 0xee, 0x5e, 0xf2, 0x27, 0x01, 0xf9, 0x64, 0x1a, 0x44, 0x18, 0xd0, 0x4c, 0x04, 0x14, 0xae, 0xff, 0x08, 0x87, 0x6b, 0x34, 0xab, 0x56, 0xa1, 0xd4, 0x25, 0xa1, 0x22, 0x58, 0x33, 0x54, 0x9a, 0xdb, 0x84, 0x1b, 0x51, 0xc9, 0xb3, 0x17, 0x6a, 0x27, 0x2b, 0xde, 0xbb, 0xa1, 0xd0, 0x78, 0x47, 0x8f, 0x62, 0xb3, 0x97, 0xf3, 0x3c, 0x8d]) + let expected = Data([0x4d, 0xdc, 0xd8, 0xf6, 0x0b, 0x98, 0xbe, 0x21, 0x83, 0x0c, 0xee, 0x5e, 0xf2, 0x27, 0x01, 0xf9, 0x64, 0x1a, 0x44, 0x18, 0xd0, 0x4c, 0x04, 0x14, 0xae, 0xff, 0x08, 0x87, 0x6b, 0x34, 0xab, 0x56, 0xa1, 0xd4, 0x25, 0xa1, 0x22, 0x58, 0x33, 0x54, 0x9a, 0xdb, 0x84, 0x1b, 0x51, 0xc9, 0xb3, 0x17, 0x6a, 0x27, 0x2b, 0xde, 0xbb, 0xa1, 0xd0, 0x78, 0x47, 0x8f, 0x62, 0xb3, 0x97, 0xf3, 0x3c, 0x8d]) XCTAssertEqual(result, expected) } @@ -40,7 +39,7 @@ class KeyDerivationTests: XCTestCase { let derivator = KeyDerivator(algorithm: .pbkdf2sha256, dklen: 32, round: 4096) let result = derivator.deriveKey(key: "password", salt: "salt", forceCryptoSwiftImplementation: true)! - let expected = Data( [0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41, 0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d, 0x96, 0x28, 0x93, 0xa0, 0x01, 0xce, 0x4e, 0x11, 0xa4, 0x96, 0x38, 0x73, 0xaa, 0x98, 0x13, 0x4a]) + let expected = Data([0xc5, 0xe4, 0x78, 0xd5, 0x92, 0x88, 0xc8, 0x41, 0xaa, 0x53, 0x0d, 0xb6, 0x84, 0x5c, 0x4c, 0x8d, 0x96, 0x28, 0x93, 0xa0, 0x01, 0xce, 0x4e, 0x11, 0xa4, 0x96, 0x38, 0x73, 0xaa, 0x98, 0x13, 0x4a]) XCTAssertEqual(result, expected) } diff --git a/Tests/Web3SwiftTests/Utils/KeyUtilTests.swift b/Tests/Web3SwiftTests/Utils/KeyUtilTests.swift index 8e353de6..f46aef6e 100644 --- a/Tests/Web3SwiftTests/Utils/KeyUtilTests.swift +++ b/Tests/Web3SwiftTests/Utils/KeyUtilTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// KeyUtilTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class KeyUtilTests: XCTestCase { - override func setUp() { super.setUp() } @@ -47,7 +46,7 @@ class KeyUtilTests: XCTestCase { XCTAssertEqual(address, "0x751e735a83a8142c1b9dc722ef559b898f1d77fa") } - + func testRecoverPublicKey() { let account = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173")) let signature = try! account.sign(message: "Hello message!") @@ -56,7 +55,7 @@ class KeyUtilTests: XCTestCase { XCTAssertEqual(address, account.address.asString().lowercased()) } - + func testRecoverPublicKeyMultiple() { let storage = TestEthereumMultipleKeyStorage(privateKey: "0x2639f727ded571d584643895d43d02a7a190f8249748a2c32200cfc12dde7173") let account = try! EthereumAccount(addressString: TestConfig.publicKey, keyStorage: storage) diff --git a/Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift b/Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift index daaee0bf..7e184c03 100644 --- a/Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift +++ b/Tests/Web3SwiftTests/Utils/KeystoreUtilTests.swift @@ -1,13 +1,12 @@ // -// web3.swift +// KeystoreUtilTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import XCTest @testable import web3 +import XCTest class KeystoreUtilTests: XCTestCase { - override func setUp() { super.setUp() } @@ -26,8 +25,8 @@ class KeystoreUtilTests: XCTestCase { let encryptedFile = try! JSONDecoder().decode(KeystoreFile.self, from: encryptedData) let expectedJson = """ - {"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"address":"0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b","version":3} -""".data(using: .utf8)! + {"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"address":"0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b","version":3} + """.data(using: .utf8)! let expectedFile = try! JSONDecoder().decode(KeystoreFile.self, from: expectedJson) @@ -35,38 +34,36 @@ class KeystoreUtilTests: XCTestCase { } func testKeystoreDecode() { - let jsonData = """ -{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"address":"0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b","version":3} -""".data(using: .utf8)! + {"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"address":"0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b","version":3} + """.data(using: .utf8)! let privateKeyData = try! KeystoreUtil.decode(data: jsonData, password: "testpassword") XCTAssertEqual(privateKeyData.web3.hexString.web3.noHexPrefix, "7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d") } - } extension KeystoreFile: Equatable { public static func == (lhs: KeystoreFile, rhs: KeystoreFile) -> Bool { - return lhs.crypto == rhs.crypto && lhs.address == rhs.address && lhs.version == rhs.version + lhs.crypto == rhs.crypto && lhs.address == rhs.address && lhs.version == rhs.version } } extension KeystoreFileCrypto: Equatable { public static func == (lhs: KeystoreFileCrypto, rhs: KeystoreFileCrypto) -> Bool { - return lhs.cipher == rhs.cipher && lhs.cipherparams == rhs.cipherparams && lhs.ciphertext == rhs.ciphertext && lhs.kdf == rhs.kdf && lhs.kdfparams == rhs.kdfparams && lhs.mac == rhs.mac + lhs.cipher == rhs.cipher && lhs.cipherparams == rhs.cipherparams && lhs.ciphertext == rhs.ciphertext && lhs.kdf == rhs.kdf && lhs.kdfparams == rhs.kdfparams && lhs.mac == rhs.mac } } extension KeystoreFileCryptoCipherParams: Equatable { public static func == (lhs: KeystoreFileCryptoCipherParams, rhs: KeystoreFileCryptoCipherParams) -> Bool { - return lhs.iv == rhs.iv + lhs.iv == rhs.iv } } extension KeystoreFileCryptoKdfParams: Equatable { public static func == (lhs: KeystoreFileCryptoKdfParams, rhs: KeystoreFileCryptoKdfParams) -> Bool { - return lhs.c == rhs.c && lhs.dklen == rhs.dklen && lhs.prf == rhs.prf && lhs.salt == rhs.salt + lhs.c == rhs.c && lhs.dklen == rhs.dklen && lhs.prf == rhs.prf && lhs.salt == rhs.salt } } diff --git a/Tests/Web3SwiftTests/Utils/RLPTests.swift b/Tests/Web3SwiftTests/Utils/RLPTests.swift index 0252d061..a6c5e7cf 100644 --- a/Tests/Web3SwiftTests/Utils/RLPTests.swift +++ b/Tests/Web3SwiftTests/Utils/RLPTests.swift @@ -1,14 +1,13 @@ // -// web3.swift +// RLPTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import BigInt import XCTest -@testable import web3 class RLPTests: XCTestCase { - override func setUp() { super.setUp() } @@ -106,7 +105,6 @@ class RLPTests: XCTestCase { } func testEncodeNestedList() { - let input = [ [], [ @@ -121,7 +119,7 @@ class RLPTests: XCTestCase { ] let encoded = RLP.encode(input)! - let expected = Data( [0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]) + let expected = Data([0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]) XCTAssertEqual(expected, encoded) } @@ -135,7 +133,7 @@ class RLPTests: XCTestCase { var input = value["in"] as Any let output = value["out"] as! String - if let inputStr = input as? String, inputStr.count > 0, let numericString = BigUInt(inputStr) { + if let inputStr = input as? String, !inputStr.isEmpty, let numericString = BigUInt(inputStr) { input = numericString } @@ -145,5 +143,4 @@ class RLPTests: XCTestCase { XCTAssertEqual(expected, encoded.web3.hexString.web3.noHexPrefix, "\(key) failed for \(input)") }) } - } diff --git a/Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift b/Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift index 2e57fe3e..7b705117 100644 --- a/Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift +++ b/Tests/Web3SwiftTests/ZKSync/EthereumClient+ZKSyncTests.swift @@ -1,15 +1,14 @@ // -// web3.swift +// EthereumClient+ZKSyncTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // -import Foundation -@testable import web3_zksync @testable import web3 import XCTest +import Foundation +@testable import web3_zksync import BigInt - final class EthereumClientZKSyncTests: XCTestCase { let eoaAccount = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: TestConfig.privateKey)) let client = ZKSyncClient(url: TestConfig.ZKSync.clientURL, network: TestConfig.ZKSync.network) @@ -20,7 +19,7 @@ final class EthereumClientZKSyncTests: XCTestCase { data: Data(), gasLimit: 300000 ) - + func test_GivenEOATransaction_gasEstimationCorrect() async { do { let estimate = try await client.estimateGas( diff --git a/Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift b/Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift index 25c3a643..8671a2dd 100644 --- a/Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift +++ b/Tests/Web3SwiftTests/ZKSync/ZKSyncTransactionTests.swift @@ -1,11 +1,11 @@ // -// web3.swift +// ZKSyncTransactionTests.swift // Copyright © 2022 Argent Labs Limited. All rights reserved. // +@testable import web3 import XCTest @testable import web3_zksync -@testable import web3 import BigInt final class ZKSyncTransactionTests: XCTestCase { @@ -18,7 +18,7 @@ final class ZKSyncTransactionTests: XCTestCase { let to = EthereumAddress("0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793") let eoaAccount = try! EthereumAccount(keyStorage: TestEthereumKeyStorage(privateKey: TestConfig.privateKey)) - + let eoaTransfer = ZKSyncTransaction( from: .init(TestConfig.publicKey), to: .init("0x64d0eA4FC60f27E74f1a70Aa6f39D403bBe56793"), @@ -29,19 +29,21 @@ final class ZKSyncTransactionTests: XCTestCase { gasPrice: BigUInt(hex: "0x05f5e100")!, gasLimit: BigUInt(hex: "0x080a22")! ) - + func test_GivenETHTransfer_EncodesCorrectly() { let signed = ZKSyncSignedTransaction( transaction: eoaTransfer, signature: .init(raw: signature) ) XCTAssertEqual(signed.raw?.web3.hexString, "0x71f891048405f5e1008405f5e10083080a229464d0ea4fc60f27e74f1a70aa6f39d403bbe56793865af3107a400080820118808082011894e78e5ecb061fe3dd1672ddda7b5116213b23b99a82c350c0b84155943b2228183717fd3be583bde0f6ec168247ea8d304eb13b3e7e76ebf6bf2c3c77734e163711c5963ac25a15f95d9ac63b82c2c427fd4eb011c5e3a22f89221bc0") } - + func test_GivenETHTransfer_WhenSigningWithEOAAccount_ThenSignsAndEncodesCorrectly() { let signed = try? eoaAccount.sign(zkTransaction: eoaTransfer) - - XCTAssertEqual(signed?.raw?.web3.hexString, - "0x71f891048405f5e1008405f5e10083080a229464d0ea4fc60f27e74f1a70aa6f39d403bbe56793865af3107a400080820118808082011894e78e5ecb061fe3dd1672ddda7b5116213b23b99a82c350c0b841c956ba7bfdf54a6d3f3b21c51465ad37df22b6258835b6e162259d6d3eec02ae11f9d17c3aafd47df49bd77e33befed87bbaff44e4c497228bfa8bcc9fa64bc31bc0") + + XCTAssertEqual( + signed?.raw?.web3.hexString, + "0x71f891048405f5e1008405f5e10083080a229464d0ea4fc60f27e74f1a70aa6f39d403bbe56793865af3107a400080820118808082011894e78e5ecb061fe3dd1672ddda7b5116213b23b99a82c350c0b841c956ba7bfdf54a6d3f3b21c51465ad37df22b6258835b6e162259d6d3eec02ae11f9d17c3aafd47df49bd77e33befed87bbaff44e4c497228bfa8bcc9fa64bc31bc0" + ) } func test_GivenERC20Transfer_EncodesCorrectly() { @@ -57,7 +59,6 @@ final class ZKSyncTransactionTests: XCTestCase { nonce: nonce ) - let signed = ZKSyncSignedTransaction( transaction: ercTransfer, signature: .init(raw: signature) ) @@ -97,7 +98,6 @@ final class ZKSyncTransactionTests: XCTestCase { nonce: nonce ) - let signed = ZKSyncSignedTransaction( transaction: ercTransfer, signature: .init(raw: signature) ) diff --git a/scripts/runSwiftFormat.sh b/scripts/runSwiftFormat.sh index 2c944d7f..871e8b27 100755 --- a/scripts/runSwiftFormat.sh +++ b/scripts/runSwiftFormat.sh @@ -38,12 +38,12 @@ cleanup() { } format() { - bin/swiftformat ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION + bin/swiftformat ../Sources/ ../Tests/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION cleanup } lint() { - bin/swiftformat --lint ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION + bin/swiftformat --lint ../Sources/ ../Tests/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION cleanup } From ebe253c44861bbd6c71692cbdf5352ee4d038292 Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 21:26:12 +0300 Subject: [PATCH 3/8] [CHANGE] Update linux container --- .github/workflows/CI.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f969f662..979fefe8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -44,8 +44,7 @@ jobs: runs-on: ubuntu-latest - container: - image: swift:5.9-jammy + container: swift:5.10 env: TESTS_PRIVATEKEY: ${{ secrets.TESTS_PRIVATEKEY }} From 0af8ccd1aa3e1211df8637a6f034a8c7aa304060 Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Wed, 14 Aug 2024 19:09:57 +0300 Subject: [PATCH 4/8] [CHANGE] Pin BigInt to 5.3.0 --- Package.resolved | 195 +++++++++++++++++++++++++++++++---------------- Package.swift | 10 +-- 2 files changed, 133 insertions(+), 72 deletions(-) diff --git a/Package.resolved b/Package.resolved index 8f70f53f..aabd2676 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,70 +1,131 @@ { - "object": { - "pins": [ - { - "package": "BigInt", - "repositoryURL": "https://github.com/attaswift/BigInt", - "state": { - "branch": null, - "revision": "0ed110f7555c34ff468e72e1686e59721f2b0da6", - "version": "5.3.0" - } - }, - { - "package": "GenericJSON", - "repositoryURL": "https://github.com/iwill/generic-json-swift", - "state": { - "branch": null, - "revision": "0a06575f4038b504e78ac330913d920f1630f510", - "version": "2.0.2" - } - }, - { - "package": "secp256k1", - "repositoryURL": "https://github.com/GigaBitcoin/secp256k1.swift.git", - "state": { - "branch": null, - "revision": "1a14e189def5eaa92f839afdd2faad8e43b61a6e", - "version": "0.12.2" - } - }, - { - "package": "swift-log", - "repositoryURL": "https://github.com/apple/swift-log.git", - "state": { - "branch": null, - "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", - "version": "1.4.2" - } - }, - { - "package": "swift-nio", - "repositoryURL": "https://github.com/apple/swift-nio.git", - "state": { - "branch": null, - "revision": "124119f0bb12384cef35aa041d7c3a686108722d", - "version": "2.40.0" - } - }, - { - "package": "swift-nio-ssl", - "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", - "state": { - "branch": null, - "revision": "1750873bce84b4129b5303655cce2c3d35b9ed3a", - "version": "2.19.0" - } - }, - { - "package": "websocket-kit", - "repositoryURL": "https://github.com/vapor/websocket-kit.git", - "state": { - "branch": null, - "revision": "e32033ad3c68ebec1b761bc961be7bd56bad02f8", - "version": "2.3.1" - } + "pins" : [ + { + "identity" : "bigint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/attaswift/BigInt", + "state" : { + "revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6", + "version" : "5.3.0" } - ] - }, - "version": 1 + }, + { + "identity" : "generic-json-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/iwill/generic-json-swift", + "state" : { + "revision" : "0a06575f4038b504e78ac330913d920f1630f510", + "version" : "2.0.2" + } + }, + { + "identity" : "secp256k1.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", + "state" : { + "revision" : "9683e8e311c76d8114cd308b697dad2f9fc58fed", + "version" : "0.17.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d", + "version" : "1.1.2" + } + }, + { + "identity" : "swift-http-types", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-http-types", + "state" : { + "revision" : "ae67c8178eb46944fd85e4dc6dd970e1f3ed6ccd", + "version" : "1.3.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "9cb486020ebf03bfa5b5df985387a14a98744537", + "version" : "1.6.1" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "4c4453b489cf76e6b3b0f300aba663eb78182fad", + "version" : "2.70.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "d1ead62745cc3269e482f1c51f27608057174379", + "version" : "1.24.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "b5f7062b60e4add1e8c343ba4eb8da2e324b3a94", + "version" : "1.34.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "a9fa5efd86e7ce2e5c1b6de113262e58035ca251", + "version" : "2.27.1" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "38ac8221dd20674682148d6451367f89c2652980", + "version" : "1.21.0" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5", + "version" : "1.3.2" + } + }, + { + "identity" : "websocket-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/websocket-kit.git", + "state" : { + "revision" : "4232d34efa49f633ba61afde365d3896fc7f8740", + "version" : "2.15.0" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index a9341cef..f8b222dd 100644 --- a/Package.swift +++ b/Package.swift @@ -13,11 +13,11 @@ let package = Package( .library(name: "web3-zksync.swift", targets: ["web3-zksync"]) ], dependencies: [ - .package(url: "https://github.com/attaswift/BigInt", .upToNextMajor(from: "5.3.0")), - .package(url: "https://github.com/iwill/generic-json-swift", .upToNextMajor(from: "2.0.0")), - .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", .upToNextMajor(from: "0.6.0")), - .package(url: "https://github.com/vapor/websocket-kit.git", .upToNextMajor(from: "2.0.0")), - .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.0.0")) + .package(url: "https://github.com/attaswift/BigInt", exact: "5.3.0"), + .package(url: "https://github.com/iwill/generic-json-swift", from: "2.0.0"), + .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", from: "0.6.0"), + .package(url: "https://github.com/vapor/websocket-kit.git", from: "2.0.0"), + .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0") ], targets: [ .target( From a0100d1e7aef23e1d7174f731aa21bfaa393ce83 Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 21:51:02 +0300 Subject: [PATCH 5/8] [CHANGE] Update .gitignore to ignore renamed TestConfigPrivate.swift --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 08235dd3..184ffe78 100644 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,4 @@ fastlane/screenshots fastlane/test_output scripts/bin/* -TestConfig_private.swift +TestConfigPrivate.swift From 1aba890bc678f4d1060c61f991501caec4e25217 Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 22:14:51 +0300 Subject: [PATCH 6/8] [ADD] swift5.10 manifest to prepare for the StrictConcurrency --- Package.swift | 28 ++++++------- Package@swift-5.10.swift | 89 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 Package@swift-5.10.swift diff --git a/Package.swift b/Package.swift index f8b222dd..7dcd5338 100644 --- a/Package.swift +++ b/Package.swift @@ -23,24 +23,24 @@ let package = Package( .target( name: "web3", dependencies: - [ - .target(name: "keccaktiny"), - .target(name: "aes"), - .target(name: "Internal_CryptoSwift_PBDKF2"), - .product(name: "BigInt", package: "BigInt"), - .product(name: "GenericJSON", package: "generic-json-swift"), - .product(name: "secp256k1", package: "secp256k1.swift"), - .product(name: "WebSocketKit", package: "websocket-kit"), - .product(name: "Logging", package: "swift-log") - ], + [ + .target(name: "keccaktiny"), + .target(name: "aes"), + .target(name: "Internal_CryptoSwift_PBDKF2"), + .product(name: "BigInt", package: "BigInt"), + .product(name: "GenericJSON", package: "generic-json-swift"), + .product(name: "secp256k1", package: "secp256k1.swift"), + .product(name: "WebSocketKit", package: "websocket-kit"), + .product(name: "Logging", package: "swift-log") + ], path: "Sources/Web3Swift" ), - .target( + .target( name: "web3-zksync", dependencies: - [ - .target(name: "web3") - ], + [ + .target(name: "web3") + ], path: "Sources/Web3ZKSync" ), .target( diff --git a/Package@swift-5.10.swift b/Package@swift-5.10.swift new file mode 100644 index 00000000..e3ed05b0 --- /dev/null +++ b/Package@swift-5.10.swift @@ -0,0 +1,89 @@ +// swift-tools-version:5.10 +import PackageDescription + +let package = Package( + name: "web3.swift", + platforms: [ + .iOS(SupportedPlatform.IOSVersion.v13), + .macOS(SupportedPlatform.MacOSVersion.v11), + .watchOS(.v7) + ], + products: [ + .library(name: "web3.swift", targets: ["web3"]), + .library(name: "web3-zksync.swift", targets: ["web3-zksync"]) + ], + dependencies: [ + .package(url: "https://github.com/attaswift/BigInt", exact: "5.3.0"), + .package(url: "https://github.com/iwill/generic-json-swift", from: "2.0.0"), + .package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", from: "0.6.0"), + .package(url: "https://github.com/vapor/websocket-kit.git", from: "2.0.0"), + .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0") + ], + targets: [ + .target( + name: "web3", + dependencies: + [ + .target(name: "keccaktiny"), + .target(name: "aes"), + .target(name: "Internal_CryptoSwift_PBDKF2"), + .product(name: "BigInt", package: "BigInt"), + .product(name: "GenericJSON", package: "generic-json-swift"), + .product(name: "secp256k1", package: "secp256k1.swift"), + .product(name: "WebSocketKit", package: "websocket-kit"), + .product(name: "Logging", package: "swift-log") + ], + path: "Sources/Web3Swift", + swiftSettings: [ + // .concurrencyChecking + ] + ), + .target( + name: "web3-zksync", + dependencies: + [ + .target(name: "web3") + ], + path: "Sources/Web3ZKSync", + swiftSettings: [ + // .concurrencyChecking + ] + ), + .target( + name: "keccaktiny", + dependencies: [], + path: "libs/keccak-tiny", + exclude: ["module.map"] + ), + .target( + name: "aes", + dependencies: [], + path: "libs/aes", + exclude: ["module.map"] + ), + .target( + name: "Internal_CryptoSwift_PBDKF2", + dependencies: [], + path: "libs/CryptoSwift" + ), + .testTarget( + name: "web3swiftTests", + dependencies: ["web3", "web3-zksync"], + path: "Tests/Web3SwiftTests", + resources: [ + .copy("Resources/rlptests.json"), + .copy("Account/cryptofights_712.json"), + .copy("Account/ethermail_signTypedDataV4.json"), + .copy("Account/real_word_opensea_signTypedDataV4.json"), + ] + ) + ] +) + +extension SwiftSetting { + /// Enable complete concurrency checking for a target in a Swift package using Swift 5.9 or Swift 5.10 + /// [Swift Concurrency Documentation](https://www.swift.org/documentation/concurrency/) + static var concurrencyChecking: SwiftSetting { + .enableExperimentalFeature("StrictConcurrency=complete") + } +} From e7e4350115e0af938777442fbc3c9a0b0ed927dc Mon Sep 17 00:00:00 2001 From: Dionysis Karatzas Date: Tue, 13 Aug 2024 23:19:58 +0300 Subject: [PATCH 7/8] [CHANGE] Disable webSocketTests that might fail randomly --- .../Client/EthereumClientTests.swift | 197 +++++++++--------- 1 file changed, 100 insertions(+), 97 deletions(-) diff --git a/Tests/Web3SwiftTests/Client/EthereumClientTests.swift b/Tests/Web3SwiftTests/Client/EthereumClientTests.swift index 7a88c1b8..c891e7e0 100644 --- a/Tests/Web3SwiftTests/Client/EthereumClientTests.swift +++ b/Tests/Web3SwiftTests/Client/EthereumClientTests.swift @@ -474,103 +474,106 @@ class EthereumWebSocketClientTests: EthereumClientTests { XCTAssertEqual(client.currentState, WebSocketState.open) } - func testWebSocketPendingTransactions() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } - - var expectation: XCTestExpectation? = self.expectation(description: "Pending Transaction") - let subscription = try await client.pendingTransactions { _ in - expectation?.fulfill() - expectation = nil - } - - await waitForExpectations(timeout: 5, handler: nil) - - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, .newPendingTransactions) - } catch { - XCTFail("Expected subscription but failed \(error).") - } - } - - func testWebSocketNewBlockHeaders() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } - - var expectation: XCTestExpectation? = self.expectation(description: "New Block Headers") - let subscription = try await client.newBlockHeaders { _ in - expectation?.fulfill() - expectation = nil - } - - // we need a high timeout as new block might take a while - await waitForExpectations(timeout: 2500, handler: nil) - - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, .newBlockHeaders) - } catch { - XCTFail("Expected subscription but failed \(error).") - } - } - - func testWebSocketLogs() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } - - var expectation: XCTestExpectation? = self.expectation(description: "Logs") - let type = EthereumSubscriptionType.logs(nil) - let subscription = try await client.logs { log in - print(log) - expectation?.fulfill() - expectation = nil - } - - // we need a high timeout as new block might take a while - await waitForExpectations(timeout: 2500, handler: nil) - - XCTAssertNotEqual(subscription.id, "") - XCTAssertEqual(subscription.type, type) - } catch { - XCTFail("Expected subscription but failed \(error).") - } - } - - func testWebSocketSubscribe() async { - do { - guard let client = client as? EthereumWebSocketClient else { - XCTFail("Expected client to be EthereumWebSocketClient") - return - } - client.delegate = self - - delegateExpectation = expectation(description: "onNewPendingTransaction delegate call") - var subscription = try await client.subscribe(type: .newPendingTransactions) - await waitForExpectations(timeout: 10) - _ = try await client.unsubscribe(subscription) - - delegateExpectation = expectation(description: "onNewBlockHeader delegate call") - subscription = try await client.subscribe(type: .newBlockHeaders) - await waitForExpectations(timeout: 2500) - _ = try await client.unsubscribe(subscription) - - delegateExpectation = expectation(description: "onLogs delegate call") - let type = EthereumSubscriptionType.logs(nil) - subscription = try await client.subscribe(type: type) - await waitForExpectations(timeout: 2500) - _ = try await client.unsubscribe(subscription) - } catch { - XCTFail("Expected subscription but failed \(error).") - } - } + // These tests may fail if the blockchain isn't producing new blocks within the expected timeframes. + /* + func testWebSocketPendingTransactions() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + + var expectation: XCTestExpectation? = self.expectation(description: "Pending Transaction") + let subscription = try await client.pendingTransactions { _ in + expectation?.fulfill() + expectation = nil + } + + await waitForExpectations(timeout: 5, handler: nil) + + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, .newPendingTransactions) + } catch { + XCTFail("Expected subscription but failed \(error).") + } + } + + func testWebSocketNewBlockHeaders() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + + var expectation: XCTestExpectation? = self.expectation(description: "New Block Headers") + let subscription = try await client.newBlockHeaders { _ in + expectation?.fulfill() + expectation = nil + } + + // we need a high timeout as new block might take a while + await waitForExpectations(timeout: 2500, handler: nil) + + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, .newBlockHeaders) + } catch { + XCTFail("Expected subscription but failed \(error).") + } + } + + func testWebSocketLogs() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + + var expectation: XCTestExpectation? = self.expectation(description: "Logs") + let type = EthereumSubscriptionType.logs(nil) + let subscription = try await client.logs { log in + print(log) + expectation?.fulfill() + expectation = nil + } + + // we need a high timeout as new block might take a while + await waitForExpectations(timeout: 2500, handler: nil) + + XCTAssertNotEqual(subscription.id, "") + XCTAssertEqual(subscription.type, type) + } catch { + XCTFail("Expected subscription but failed \(error).") + } + } + + func testWebSocketSubscribe() async { + do { + guard let client = client as? EthereumWebSocketClient else { + XCTFail("Expected client to be EthereumWebSocketClient") + return + } + client.delegate = self + + delegateExpectation = expectation(description: "onNewPendingTransaction delegate call") + var subscription = try await client.subscribe(type: .newPendingTransactions) + await waitForExpectations(timeout: 10) + _ = try await client.unsubscribe(subscription) + + delegateExpectation = expectation(description: "onNewBlockHeader delegate call") + subscription = try await client.subscribe(type: .newBlockHeaders) + await waitForExpectations(timeout: 2500) + _ = try await client.unsubscribe(subscription) + + delegateExpectation = expectation(description: "onLogs delegate call") + let type = EthereumSubscriptionType.logs(nil) + subscription = try await client.subscribe(type: type) + await waitForExpectations(timeout: 2500) + _ = try await client.unsubscribe(subscription) + } catch { + XCTFail("Expected subscription but failed \(error).") + } + } + */ func testWebSocketUnsubscribe() async { do { From 5febb976103fc70aa2cabf3ad7c391cc3a91f1c3 Mon Sep 17 00:00:00 2001 From: Dionysios Karatzas Date: Mon, 23 Sep 2024 17:46:58 +0300 Subject: [PATCH 8/8] [CHANGE] SwiftFormat Swift version --- Package.resolved | 13 +++++++------ scripts/runSwiftFormat.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Package.resolved b/Package.resolved index aabd2676..6273e8f7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,4 +1,5 @@ { + "originHash" : "3324b139415be85518d19463c6e2531e9bcc17d568a760c8b61de80c16e039db", "pins" : [ { "identity" : "bigint", @@ -41,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d", - "version" : "1.1.2" + "revision" : "9bf03ff58ce34478e66aaee630e491823326fd06", + "version" : "1.1.3" } }, { @@ -68,8 +69,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "4c4453b489cf76e6b3b0f300aba663eb78182fad", - "version" : "2.70.0" + "revision" : "9746cf80e29edfef2a39924a66731249223f42a3", + "version" : "2.72.0" } }, { @@ -95,8 +96,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "a9fa5efd86e7ce2e5c1b6de113262e58035ca251", - "version" : "2.27.1" + "revision" : "7b84abbdcef69cc3be6573ac12440220789dcd69", + "version" : "2.27.2" } }, { diff --git a/scripts/runSwiftFormat.sh b/scripts/runSwiftFormat.sh index 871e8b27..ff05e639 100755 --- a/scripts/runSwiftFormat.sh +++ b/scripts/runSwiftFormat.sh @@ -1,6 +1,6 @@ #!/bin/sh -SWIFT_VERSION=5.10 +SWIFT_VERSION=5.6 cd "$(dirname "$0")"