Skip to content

Commit 0314336

Browse files
authored
Merge pull request #67 from BANKEX/develop
Event parsing example from user case
2 parents 90c963a + a4d4b1e commit 0314336

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

web3swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "web3swift"
3-
s.version = "0.5.4"
3+
s.version = "0.5.5"
44
s.summary = "Web3 implementation in vanilla Swift for iOS ans macOS"
55

66
s.description = <<-DESC

web3swiftTests/web3swiftTests.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ class web3swiftTests: XCTestCase {
8989
}
9090

9191
func testCombiningPublicKeys() {
92-
let priv1 = Data.randomBytes(length: 32)!
92+
let priv1 = Data(repeating: 0x01, count: 32)
9393
let pub1 = Web3.Utils.privateToPublic(priv1, compressed: true)!
94-
let priv2 = Data.randomBytes(length: 32)!
94+
let priv2 = Data(repeating: 0x02, count: 32)
9595
let pub2 = Web3.Utils.privateToPublic(priv2, compressed: true)!
9696
let combined = SECP256K1.combineSerializedPublicKeys(keys: [pub1, pub2], outputCompressed: true)
97-
XCTAssert(combined != nil)
97+
let compinedPriv = Data(repeating: 0x03, count: 32)
98+
let compinedPub = Web3.Utils.privateToPublic(compinedPriv, compressed: true)
99+
XCTAssert(compinedPub == combined)
98100
}
99101

100102
func testBIP39 () {
@@ -2055,14 +2057,25 @@ class web3swiftTests: XCTestCase {
20552057
switch result {
20562058
case .success(let res):
20572059
guard let signer = res["signer"]! as? EthereumAddress else {return XCTFail()}
2060+
print(signer)
20582061
XCTAssert(signer == expectedAddress)
20592062
case .failure(let error):
20602063
print(error)
20612064
XCTFail()
20622065
}
20632066
}
20642067

2065-
2068+
func testUserCaseEventParsing() {
2069+
let contractAddress = EthereumAddress("0x7ff546aaccd379d2d1f241e1d29cdd61d4d50778")
2070+
let jsonString = "[{\"constant\":false,\"inputs\":[{\"name\":\"_id\",\"type\":\"string\"}],\"name\":\"deposit\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_id\",\"type\":\"string\"},{\"indexed\":true,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Deposit\",\"type\":\"event\"}]"
2071+
let web3 = Web3.InfuraRinkebyWeb3()
2072+
let contract = web3.contract(jsonString, at: contractAddress, abiVersion: 2)
2073+
guard let eventParser = contract?.createEventParser("Deposit", filter: nil) else {return XCTFail()}
2074+
let present = eventParser.parseBlockByNumber(UInt64(2138657))
2075+
guard case .success(let pres) = present else {return XCTFail()}
2076+
print(pres)
2077+
XCTAssert(pres.count == 1)
2078+
}
20662079

20672080
func testPerformanceExample() {
20682081
// This is an example of a performance test case.

0 commit comments

Comments
 (0)