Skip to content

Commit cac6c6a

Browse files
author
Alex Vlasov
committed
fixed decoding input data for method, added test
1 parent 4c855e9 commit cac6c6a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

web3swift/ABIv2/Classes/ABIv2Elements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ extension ABIv2.Element {
145145
func decodeInputData(_ rawData: Data) -> [String: Any]? {
146146
var data = rawData
147147
var sig: Data? = nil
148-
switch rawData.count % 4 {
148+
switch rawData.count % 32 {
149149
case 0:
150150
break
151151
case 4:
152152
sig = rawData[0 ..< 4]
153-
data = rawData[4 ..< rawData.count]
153+
data = Data(rawData[4 ..< rawData.count])
154154
default:
155155
return nil
156156
}

web3swiftTests/web3swiftTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,13 @@ class web3swiftTests: XCTestCase {
21412141
}
21422142
}
21432143

2144+
func testDecodeInputData() {
2145+
let contract = ContractV2.init(Web3.Utils.erc20ABI)!
2146+
let dataToDecode = Data.fromHex("0xa9059cbb000000000000000000000000cdd45864e794fe5e3e1b0045b77e62f4c43b8bd9000000000000000000000000000000000000000000000224b5f018c3e30142d5")!
2147+
let decoded = contract.decodeInputData("transfer", data: dataToDecode)
2148+
XCTAssert(decoded!["_to"] as? EthereumAddress == EthereumAddress("0xcdd45864e794fe5e3e1b0045b77e62f4c43b8bd9"))
2149+
}
2150+
21442151
func testPerformanceExample() {
21452152
// This is an example of a performance test case.
21462153
self.measure {

0 commit comments

Comments
 (0)