Skip to content

feat: remote tests mocking #701

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/Core/Contract/ContractProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public protocol ContractProtocol {
/// - Returns: `true` if event is possibly present, `false` if definitely not present and `nil` if event with given name
/// is not part of the ``EthereumContract/abi``.
func testBloomForEventPresence(eventName: String, bloom: EthereumBloomFilter) -> Bool?

/// Given the transaction data searches for a match in ``ContractProtocol/methods``.
/// - Parameter data: encoded function call used in transaction data field. Must be at least 4 bytes long.
/// - Returns: function decoded from the ABI of this contract or `nil` if nothing was found.
func getFunctionCalled(_ data: Data) -> ABI.Element.Function?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My dream for 4.0.0 is to create a set of Ethereum only data types that will be accounts all that special cases.

Must be at least 4 bytes long.

Because while we're using some advantages of swift strong typed system in 3.0.0 we're still missing a lot of them, treating those Ethereum rules in a python way, by leaving notes to our future selves.

Nothing to say about rewriting ABI module to generics as well.

}

// MARK: - Overloaded ContractProtocol's functions
Expand Down Expand Up @@ -333,4 +338,9 @@ extension DefaultContractProtocol {
guard let function = methods[methodSignature]?.first else { return nil }
return function.decodeInputData(Data(data[4 ..< data.count]))
}

public func getFunctionCalled(_ data: Data) -> ABI.Element.Function? {
guard data.count >= 4 else { return nil }
return methods[data[0..<4].toHexString().addHexPrefix()]?.first
}
Comment on lines +342 to +345
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see your dirty hack here. This is somewhat that I'd like to be implemented as a protocol. But again this is dream not even about current century.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that dirty I'd say.
We have an array of bytes, we get the first 4 of them and then look them up in the dictionary.
It's pretty straightforward.

}
4 changes: 2 additions & 2 deletions Sources/Core/Web3Error/Web3Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public enum Web3Error: LocalizedError {
return "Server error: \(code)"
case let .clientError(code: code):
return "Client error: \(code)"
case .valueError:
return "You're passing value that doesn't supported by this method."
case .valueError(let errorDescription):
return (errorDescription?.isEmpty ?? true) ? "You're passing value that isn't supported by this method" : errorDescription!
}
}
}
14 changes: 0 additions & 14 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift

This file was deleted.

17 changes: 0 additions & 17 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetAccounts.swift

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBalance.swift

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetCode.swift

This file was deleted.

14 changes: 0 additions & 14 deletions Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetGasPrice.swift

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading