Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
test example of event parsing with unindexed string parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Vlasov committed Apr 19, 2018
1 parent 949f82e commit a4d4b1e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions web3swiftTests/web3swiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ class web3swiftTests: XCTestCase {
}

func testCombiningPublicKeys() {
let priv1 = Data.randomBytes(length: 32)!
let priv1 = Data(repeating: 0x01, count: 32)
let pub1 = Web3.Utils.privateToPublic(priv1, compressed: true)!
let priv2 = Data.randomBytes(length: 32)!
let priv2 = Data(repeating: 0x02, count: 32)
let pub2 = Web3.Utils.privateToPublic(priv2, compressed: true)!
let combined = SECP256K1.combineSerializedPublicKeys(keys: [pub1, pub2], outputCompressed: true)
XCTAssert(combined != nil)
let compinedPriv = Data(repeating: 0x03, count: 32)
let compinedPub = Web3.Utils.privateToPublic(compinedPriv, compressed: true)
XCTAssert(compinedPub == combined)
}

func testBIP39 () {
Expand Down Expand Up @@ -2063,7 +2065,17 @@ class web3swiftTests: XCTestCase {
}
}


func testUserCaseEventParsing() {
let contractAddress = EthereumAddress("0x7ff546aaccd379d2d1f241e1d29cdd61d4d50778")
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\"}]"
let web3 = Web3.InfuraRinkebyWeb3()
let contract = web3.contract(jsonString, at: contractAddress, abiVersion: 2)
guard let eventParser = contract?.createEventParser("Deposit", filter: nil) else {return XCTFail()}
let present = eventParser.parseBlockByNumber(UInt64(2138657))
guard case .success(let pres) = present else {return XCTFail()}
print(pres)
XCTAssert(pres.count == 1)
}

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

0 comments on commit a4d4b1e

Please sign in to comment.