Skip to content

Commit a4d4b1e

Browse files
author
Alex Vlasov
committed
test example of event parsing with unindexed string parameter
1 parent 949f82e commit a4d4b1e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

web3swiftTests/web3swiftTests.swift

Lines changed: 16 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 () {
@@ -2063,7 +2065,17 @@ class web3swiftTests: XCTestCase {
20632065
}
20642066
}
20652067

2066-
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+
}
20672079

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

0 commit comments

Comments
 (0)