@@ -13,7 +13,7 @@ import Core
1313
1414class ABIEncoderTest : XCTestCase {
1515
16- func test_soliditySha3 ( ) throws {
16+ func testSoliditySha3 ( ) throws {
1717 var hex = try ABIEncoder . soliditySha3 ( true ) . toHexString ( ) . addHexPrefix ( )
1818 assert ( hex == " 0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2 " )
1919 hex = try ABIEncoder . soliditySha3 ( - 10 ) . toHexString ( ) . addHexPrefix ( )
@@ -66,7 +66,7 @@ class ABIEncoderTest: XCTestCase {
6666 assert ( hex == " 0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955 " )
6767 }
6868
69- func test_soliditySha3Fail_FloatDouble ( ) throws {
69+ func testSoliditySha3FailFloatDouble ( ) throws {
7070 assert ( ( try ? ABIEncoder . soliditySha3 ( Float ( 1 ) ) ) == nil )
7171 assert ( ( try ? ABIEncoder . soliditySha3 ( Double ( 1 ) ) ) == nil )
7272 assert ( ( try ? ABIEncoder . soliditySha3 ( CGFloat ( 1 ) ) ) == nil )
@@ -78,7 +78,7 @@ class ABIEncoderTest: XCTestCase {
7878 /// `[AnyObject]` is not allowed to be used directly as input for `solidtySha3`.
7979 /// `AnyObject` erases type data making it impossible to encode some types correctly,
8080 /// 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 {
8282 var didFail = false
8383 do {
8484 _ = try ABIEncoder . soliditySha3 ( [ " " ] as [ AnyObject ] )
@@ -91,7 +91,7 @@ class ABIEncoderTest: XCTestCase {
9191 /// `AnyObject` is not allowed to be used directly as input for `solidtySha3`.
9292 /// `AnyObject` erases type data making it impossible to encode some types correctly,
9393 /// 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 {
9595 var didFail = false
9696 do {
9797 _ = try ABIEncoder . soliditySha3 ( " " as AnyObject )
@@ -101,7 +101,7 @@ class ABIEncoderTest: XCTestCase {
101101 XCTAssertTrue ( didFail)
102102 }
103103
104- func test_abiEncoding_emptyValues ( ) {
104+ func testAbiEncodingEmptyValues ( ) {
105105 let zeroBytes = ABIEncoder . encode ( types: [ ABI . Element. InOut] ( ) , values: [ AnyObject] ( ) ) !
106106 XCTAssert ( zeroBytes. count == 0 )
107107
@@ -114,4 +114,24 @@ class ABIEncoderTest: XCTestCase {
114114 XCTAssertTrue ( functionWithNoInput. methodEncoding == encodedFunction)
115115 XCTAssertTrue ( " 0xe16b4a9b " == encodedFunction? . toHexString ( ) . addHexPrefix ( ) . lowercased ( ) )
116116 }
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+ }
117137}
0 commit comments