|
| 1 | +// |
| 2 | +// ABIElementsTest.swift |
| 3 | +// |
| 4 | +// Created by JeneaVranceanu on 28.11.2022. |
| 5 | +// |
| 6 | + |
| 7 | +import Foundation |
| 8 | +import XCTest |
| 9 | +import Core |
| 10 | + |
| 11 | +class ABIElementsTest: XCTestCase { |
| 12 | + typealias EthError = ABI.Element.EthError |
| 13 | + |
| 14 | + /// Function with any parameters should be able to decode `require` and `revert` calls in soliditiy. |
| 15 | + /// Note: `require(expression)` and `revert()` without a message return 0 bytes thus we cannot guarantee |
| 16 | + /// that 0 bytes response will be interpreted correctly. |
| 17 | + private let emptyFunction = ABI.Element.Function(name: "any", |
| 18 | + inputs: [], |
| 19 | + outputs: [], |
| 20 | + constant: false, |
| 21 | + payable: false) |
| 22 | + |
| 23 | + func testErrorRepresentation() { |
| 24 | + XCTAssertEqual(EthError(name: "Error", inputs: []).errorDeclaration, "Error()") |
| 25 | + XCTAssertEqual(EthError(name: "Error", inputs: [.init(name: "", type: .address)]).errorDeclaration, "Error(address)") |
| 26 | + XCTAssertEqual(EthError(name: "Error", inputs: [.init(name: " ", type: .address)]).errorDeclaration, "Error(address)") |
| 27 | + XCTAssertEqual(EthError(name: "Error", inputs: [.init(name: " ", type: .address), .init(name: "", type: .uint(bits: 256))]).errorDeclaration, "Error(address,uint256)") |
| 28 | + XCTAssertEqual(EthError(name: "Error", inputs: [.init(name: "sender", type: .address), .init(name: " ", type: .uint(bits: 256))]).errorDeclaration, "Error(address sender,uint256)") |
| 29 | + let allTypesNamedAndNot: [ABI.Element.InOut] = [ |
| 30 | + .init(name: "sender", type: .address), |
| 31 | + .init(name: "", type: .address), |
| 32 | + .init(name: "", type: .uint(bits: 8)), |
| 33 | + .init(name: "", type: .uint(bits: 16)), |
| 34 | + .init(name: "", type: .uint(bits: 32)), |
| 35 | + .init(name: "", type: .uint(bits: 64)), |
| 36 | + .init(name: "", type: .uint(bits: 128)), |
| 37 | + .init(name: "", type: .uint(bits: 256)), |
| 38 | + .init(name: "my_int_8", type: .int(bits: 8)), |
| 39 | + .init(name: "my_int_16", type: .int(bits: 16)), |
| 40 | + .init(name: "my_int_32", type: .int(bits: 32)), |
| 41 | + .init(name: "my_int_64", type: .int(bits: 64)), |
| 42 | + .init(name: "my_int_128", type: .int(bits: 128)), |
| 43 | + .init(name: "my_int_256", type: .int(bits: 256)), |
| 44 | + .init(name: "someFlag", type: .bool), |
| 45 | + .init(name: "rand_bytes", type: .bytes(length: 123)), |
| 46 | + .init(name: "", type: .dynamicBytes), |
| 47 | + .init(name: "error_message_maybe", type: .string), |
| 48 | + ] |
| 49 | + XCTAssertEqual(EthError(name: "VeryCustomErrorName", |
| 50 | + inputs: allTypesNamedAndNot).errorDeclaration, |
| 51 | + "VeryCustomErrorName(address sender,address,uint8,uint16,uint32,uint64,uint128,uint256,int8 my_int_8,int16 my_int_16,int32 my_int_32,int64 my_int_64,int128 my_int_128,int256 my_int_256,bool someFlag,bytes123 rand_bytes,bytes,string error_message_maybe)") |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments