Skip to content

Commit d4df888

Browse files
fix: fixed typo in function name testBloomForEventPrecence -> testBloomForEventPresence (typo in word Presence)
1 parent 07d64f8 commit d4df888

File tree

6 files changed

+27
-34
lines changed

6 files changed

+27
-34
lines changed

Sources/web3swift/Contract/ContractProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public protocol ContractProtocol {
106106
/// Attempts to parse given event based on the data from `allEvents`, or in other words based on the given smart contract ABI.
107107
func parseEvent(_ eventLog: EventLog) -> (eventName:String?, eventData:[String: Any]?)
108108

109-
func testBloomForEventPrecence(eventName: String, bloom: EthereumBloomFilter) -> Bool?
109+
func testBloomForEventPresence(eventName: String, bloom: EthereumBloomFilter) -> Bool?
110110
}
111111

112112
extension ContractProtocol {
@@ -223,7 +223,7 @@ extension DefaultContractProtocol {
223223
return (nil, nil)
224224
}
225225

226-
public func testBloomForEventPrecence(eventName: String, bloom: EthereumBloomFilter) -> Bool? {
226+
public func testBloomForEventPresence(eventName: String, bloom: EthereumBloomFilter) -> Bool? {
227227
guard let event = events[eventName] else { return nil }
228228
if event.anonymous {
229229
return true

Sources/web3swift/Contract/EventFiltering.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ internal func parseReceiptForLogs(receipt: TransactionReceipt, contract: Contrac
197197
return [EventParserResultProtocol]()
198198
}
199199
}
200-
guard let eventOfSuchTypeIsPresent = contract.testBloomForEventPrecence(eventName: eventName, bloom: bloom) else {return nil}
200+
guard let eventOfSuchTypeIsPresent = contract.testBloomForEventPresence(eventName: eventName, bloom: bloom) else {return nil}
201201
if (!eventOfSuchTypeIsPresent) {
202202
return [EventParserResultProtocol]()
203203
}

Sources/web3swift/Web3/Web3+EventParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension web3.web3contract.EventParser {
136136
}
137137
}
138138

139-
guard let eventOfSuchTypeIsPresent = self.contract.testBloomForEventPrecence(eventName: self.eventName, bloom: bloom) else {
139+
guard let eventOfSuchTypeIsPresent = self.contract.testBloomForEventPresence(eventName: self.eventName, bloom: bloom) else {
140140
throw Web3Error.processingError(desc: "Error processing bloom for events")
141141
}
142142
if (!eventOfSuchTypeIsPresent) {

Sources/web3swift/Web3/Web3+MutatingTransaction.swift

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,15 @@ import Core
1010

1111
public class WriteTransaction: ReadTransaction {
1212

13-
public func assemblePromise(transactionOptions: TransactionOptions? = nil) async throws -> EthereumTransaction {
13+
public func assembleTransaction(transactionOptions: TransactionOptions? = nil) async throws -> EthereumTransaction {
1414
var assembledTransaction: EthereumTransaction = transaction
15-
let queue = web3.requestDispatcher.queue
16-
let returnPromise = Promise<EthereumTransaction> { seal in
17-
if method != "fallback" {
18-
guard let method = contract.methods[method]?.first else {
19-
seal.reject(Web3Error.inputError(desc: "Contract's ABI does not have such method"))
20-
return
21-
}
22-
23-
if method.constant {
24-
seal.reject(Web3Error.inputError(desc: "Trying to transact to the constant function"))
25-
return
26-
}
27-
}
2815

2916
if self.method != "fallback" {
3017
let function = self.contract.methods[self.method]?.first
3118
if function == nil {
3219
throw Web3Error.inputError(desc: "Contract's ABI does not have such method")
3320
}
34-
if function.constant {
21+
if function!.constant {
3522
throw Web3Error.inputError(desc: "Trying to transact to the constant function")
3623
}
3724
}
@@ -190,24 +177,24 @@ public class WriteTransaction: ReadTransaction {
190177
}
191178

192179
public func send(password: String = "web3swift", transactionOptions: TransactionOptions? = nil) async throws -> TransactionSendingResult {
193-
let transaction = try await self.assembleTransaction(transactionOptions: transactionOptions)
180+
let transaction = try await assembleTransaction(transactionOptions: transactionOptions)
194181
let mergedOptions = self.transactionOptions.merge(transactionOptions)
195182
var cleanedOptions = TransactionOptions()
196183
cleanedOptions.from = mergedOptions.from
197184
cleanedOptions.to = mergedOptions.to
198-
return try await self.web3.eth.send(transaction, transactionOptions: cleanedOptions, password: password)
185+
return try await web3.eth.send(transaction, transactionOptions: cleanedOptions, password: password)
199186
}
200187

201188
public func assemble(transactionOptions: TransactionOptions? = nil) async throws -> EthereumTransaction {
202-
return try await self.assembleTransaction(transactionOptions: transactionOptions)
189+
return try await assembleTransaction(transactionOptions: transactionOptions)
203190
}
204191

205192
func gasEstimate(for policy: TransactionOptions.GasLimitPolicy,
206193
assembledTransaction: EthereumTransaction,
207194
optionsForGasEstimation: TransactionOptions) async throws -> BigUInt {
208195
switch policy {
209196
case .automatic, .withMargin, .limited:
210-
return try await self.web3.eth.estimateGas(for: assembledTransaction, transactionOptions: optionsForGasEstimation)
197+
return try await web3.eth.estimateGas(for: assembledTransaction, transactionOptions: optionsForGasEstimation)
211198
case .manual(let gasLimit):
212199
return gasLimit
213200
}

Tests/web3swiftTests/localTests/EIP681Tests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class EIP681Tests: XCTestCase {
1818
//ethereum:0x8932404A197D84Ec3Ea55971AADE11cdA1dddff1/transfer?address=0x6891dC3962e710f0ff711B9c6acc26133Fd35Cb4&uint256=1
1919

2020
func testEIP681Parsing() async throws {
21-
let parsed = Web3.EIP681CodeParser.parse("ethereum:0x5ffc014343cd971b7eb70732021e26c35b744cc4?value=2.014e18")
21+
let parsed = await Web3.EIP681CodeParser.parse("ethereum:0x5ffc014343cd971b7eb70732021e26c35b744cc4?value=2.014e18")
2222
XCTAssert(parsed != nil)
2323
}
2424

Tests/web3swiftTests/localTests/EthereumContractTest.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
//
88

99
import XCTest
10+
@testable import Core
1011
@testable import web3swift
1112

1213
class EthereumContractTest: LocalTestCase {
1314
private static let eventsOnlyABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"operation\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"ContractCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"dataKey\",\"type\":\"bytes32\"}],\"name\":\"DataChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"operation\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"selector\",\"type\":\"bytes4\"}],\"name\":\"Executed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"typeId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"returnedValue\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"receivedData\",\"type\":\"bytes\"}],\"name\":\"UniversalReceiver\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"ValueReceived\",\"type\":\"event\"}]"
1415

1516
private static let overloadedFunctionsABI = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"operation\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"contractAddress\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"ContractCreated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"dataKey\",\"type\":\"bytes32\"}],\"name\":\"DataChanged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"operation\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"selector\",\"type\":\"bytes4\"}],\"name\":\"Executed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"typeId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"returnedValue\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"receivedData\",\"type\":\"bytes\"}],\"name\":\"UniversalReceiver\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"ValueReceived\",\"type\":\"event\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"inputs\":[{\"internalType\":\"bytes32[]\",\"name\":\"dataKeys\",\"type\":\"bytes32[]\"}],\"name\":\"getData\",\"outputs\":[{\"internalType\":\"bytes[]\",\"name\":\"dataValues\",\"type\":\"bytes[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"dataKey\",\"type\":\"bytes32\"}],\"name\":\"getData\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"dataValue\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"noInputFunction\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32[]\",\"name\":\"dataKeys\",\"type\":\"bytes32[]\"},{\"internalType\":\"bytes[]\",\"name\":\"dataValues\",\"type\":\"bytes[]\"}],\"name\":\"setData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"dataKey\",\"type\":\"bytes32\"},{\"internalType\":\"bytes\",\"name\":\"dataValue\",\"type\":\"bytes\"}],\"name\":\"setData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
1617

17-
func test_decodeEvents() throws {
18-
let contract = ganache.contract(EthereumContractTest.eventsOnlyABI)!
18+
func test_decodeEvents() async throws {
19+
let web3 = try! await Web3.new(LocalTestCase.url)
20+
let contract = web3.contract(EthereumContractTest.eventsOnlyABI)!
1921

2022
XCTAssertTrue(contract.contract.allEvents.count == 6)
2123
XCTAssertNotNil(contract.contract.events["ContractCreated"])
@@ -26,8 +28,9 @@ class EthereumContractTest: LocalTestCase {
2628
XCTAssertNotNil(contract.contract.events["ValueReceived"])
2729
}
2830

29-
func test_decodedAllFunctions() throws {
30-
let contract = ganache.contract(EthereumContractTest.overloadedFunctionsABI)!
31+
func test_decodedAllFunctions() async throws {
32+
let web3 = try! await Web3.new(LocalTestCase.url)
33+
let contract = web3.contract(EthereumContractTest.overloadedFunctionsABI)!
3134

3235
XCTAssertTrue(contract.contract.allMethods.count == 5)
3336

@@ -48,17 +51,19 @@ class EthereumContractTest: LocalTestCase {
4851
XCTAssertTrue(contract.contract.methods[getFuncSignature("noInputFunction()")]?.count == 1)
4952
}
5053

51-
func test_encodeMethodBasedOnNameWithParameters_mustFail() throws {
52-
let contract = ganache.contract(EthereumContractTest.overloadedFunctionsABI)!
54+
func test_encodeMethodBasedOnNameWithParameters_mustFail() async throws {
55+
let web3 = try! await Web3.new(LocalTestCase.url)
56+
let contract = web3.contract(EthereumContractTest.overloadedFunctionsABI)!
5357

5458
/// Encoding method that expects parameters but we are not giving any.
5559
/// Result must be `nil`.
5660
XCTAssertNil(contract.method("setData(bytes32,bytes)"))
5761
XCTAssertNil(contract.method(getFuncSignature("setData(bytes32,bytes)")))
5862
}
5963

60-
func test_encodeMethodBasedOnNameWithParameters() throws {
61-
let contract = ganache.contract(EthereumContractTest.overloadedFunctionsABI,
64+
func test_encodeMethodBasedOnNameWithParameters() async throws {
65+
let web3 = try! await Web3.new(LocalTestCase.url)
66+
let contract = web3.contract(EthereumContractTest.overloadedFunctionsABI,
6267
at: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!)!
6368
let parameters: [AnyObject] = [
6469
[Data.randomBytes(length: 32)!,
@@ -81,8 +86,9 @@ class EthereumContractTest: LocalTestCase {
8186
testDecoding(getFuncSignature(functionNameWithParameters))
8287
}
8388

84-
func test_encodeMethodBasedOnHexSignature() throws {
85-
let contract = ganache.contract(EthereumContractTest.overloadedFunctionsABI,
89+
func test_encodeMethodBasedOnHexSignature() async throws {
90+
let web3 = try! await Web3.new(LocalTestCase.url)
91+
let contract = web3.contract(EthereumContractTest.overloadedFunctionsABI,
8692
at: EthereumAddress("0x6394b37Cf80A7358b38068f0CA4760ad49983a1B")!)!
8793
let parameters: [AnyObject] = [Data.randomBytes(length: 32)!, Data.randomBytes(length: 32)!] as [AnyObject]
8894
let functionSignature = getFuncSignature("setData(bytes32,bytes)")

0 commit comments

Comments
 (0)