@@ -13,7 +13,7 @@ import Core
13
13
14
14
class ABIEncoderTest : XCTestCase {
15
15
16
- func test_soliditySha3 ( ) throws {
16
+ func testSoliditySha3 ( ) throws {
17
17
var hex = try ABIEncoder . soliditySha3 ( true ) . toHexString ( ) . addHexPrefix ( )
18
18
assert ( hex == " 0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2 " )
19
19
hex = try ABIEncoder . soliditySha3 ( - 10 ) . toHexString ( ) . addHexPrefix ( )
@@ -66,7 +66,7 @@ class ABIEncoderTest: XCTestCase {
66
66
assert ( hex == " 0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955 " )
67
67
}
68
68
69
- func test_soliditySha3Fail_FloatDouble ( ) throws {
69
+ func testSoliditySha3FailFloatDouble ( ) throws {
70
70
assert ( ( try ? ABIEncoder . soliditySha3 ( Float ( 1 ) ) ) == nil )
71
71
assert ( ( try ? ABIEncoder . soliditySha3 ( Double ( 1 ) ) ) == nil )
72
72
assert ( ( try ? ABIEncoder . soliditySha3 ( CGFloat ( 1 ) ) ) == nil )
@@ -78,7 +78,7 @@ class ABIEncoderTest: XCTestCase {
78
78
/// `[AnyObject]` is not allowed to be used directly as input for `solidtySha3`.
79
79
/// `AnyObject` erases type data making it impossible to encode some types correctly,
80
80
/// e.g.: Bool can be treated as Int (8/16/32/64) and 0/1 numbers can be treated as Bool.
81
- func test_soliditySha3Fail_1 ( ) throws {
81
+ func testSoliditySha3Fail_1 ( ) throws {
82
82
var didFail = false
83
83
do {
84
84
_ = try ABIEncoder . soliditySha3 ( [ " " ] as [ AnyObject ] )
@@ -91,7 +91,7 @@ class ABIEncoderTest: XCTestCase {
91
91
/// `AnyObject` is not allowed to be used directly as input for `solidtySha3`.
92
92
/// `AnyObject` erases type data making it impossible to encode some types correctly,
93
93
/// e.g.: Bool can be treated as Int (8/16/32/64) and 0/1 numbers can be treated as Bool.
94
- func test_soliditySha3Fail_2 ( ) throws {
94
+ func testSoliditySha3Fail_2 ( ) throws {
95
95
var didFail = false
96
96
do {
97
97
_ = try ABIEncoder . soliditySha3 ( " " as AnyObject )
@@ -101,7 +101,7 @@ class ABIEncoderTest: XCTestCase {
101
101
XCTAssertTrue ( didFail)
102
102
}
103
103
104
- func test_abiEncoding_emptyValues ( ) {
104
+ func testAbiEncodingEmptyValues ( ) {
105
105
let zeroBytes = ABIEncoder . encode ( types: [ ABI . Element. InOut] ( ) , values: [ AnyObject] ( ) ) !
106
106
XCTAssert ( zeroBytes. count == 0 )
107
107
@@ -114,4 +114,24 @@ class ABIEncoderTest: XCTestCase {
114
114
XCTAssertTrue ( functionWithNoInput. methodEncoding == encodedFunction)
115
115
XCTAssertTrue ( " 0xe16b4a9b " == encodedFunction? . toHexString ( ) . addHexPrefix ( ) . lowercased ( ) )
116
116
}
117
+
118
+ func testAbiEncodingDynamicTypes( ) {
119
+ var encodedValue = ABIEncoder . encode ( types: [ . dynamicBytes] , values: [ Data . fromHex ( " 6761766f66796f726b " ) !] as [ AnyObject ] ) !. toHexString ( )
120
+ XCTAssertEqual ( encodedValue, " 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000 " )
121
+
122
+ encodedValue = ABIEncoder . encode ( types: [ . dynamicBytes] , values: [ Data . fromHex ( " 731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b " ) !] as [ AnyObject ] ) !. toHexString ( )
123
+ XCTAssertEqual ( encodedValue, " 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b " )
124
+
125
+ encodedValue = ABIEncoder . encode ( types: [ . dynamicBytes] , values: [ Data . fromHex ( " fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1 " ) !] as [ AnyObject ] ) !. toHexString ( )
126
+ XCTAssertEqual ( encodedValue, " 0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000009ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff100 " )
127
+
128
+ encodedValue = ABIEncoder . encode ( types: [ . dynamicBytes] , values: [ Data . fromHex ( " c3a40000c3a4 " ) !] as [ AnyObject ] ) !. toHexString ( )
129
+ XCTAssertEqual ( encodedValue, " 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006c3a40000c3a40000000000000000000000000000000000000000000000000000 " )
130
+
131
+ encodedValue = ABIEncoder . encode ( types: [ . string] , values: [ " gavofyork " ] as [ AnyObject ] ) !. toHexString ( )
132
+ XCTAssertEqual ( encodedValue, " 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000096761766f66796f726b0000000000000000000000000000000000000000000000 " )
133
+
134
+ encodedValue = ABIEncoder . encode ( types: [ . string] , values: [ " Heeäööä👅D34ɝɣ24Єͽ-.,äü+#/ " ] as [ AnyObject ] ) !. toHexString ( )
135
+ XCTAssertEqual ( encodedValue, " 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000026486565c3a4c3b6c3b6c3a4f09f9185443334c99dc9a33234d084cdbd2d2e2cc3a4c3bc2b232f0000000000000000000000000000000000000000000000000000 " )
136
+ }
117
137
}
0 commit comments