Skip to content

Commit

Permalink
fix: tests according to updates int/uint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janndriessen committed Apr 7, 2024
1 parent 8b82887 commit da65400
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Tests/web3swiftTests/localTests/ABIEncoderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,21 @@ class ABIEncoderTest: XCTestCase {
XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000047465737400000000000000000000000000000000000000000000000000000000")
hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 0)], values: [[1, 2, 3, 4]])?.toHexString()
XCTAssertEqual(hexData?[0..<64], "0000000000000000000000000000000000000000000000000000000000000020")
XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004")

XCTAssertEqual(hexData, "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000401020304")
// This one shouldn't have data offset
hexData = ABIEncoder.encode(types: [.array(type: .uint(bits: 8), length: 4)], values: [[1, 2, 3, 4]])?.toHexString()
// First 32 bytes are the first value from the array
XCTAssertEqual(hexData?[0..<64], "0000000000000000000000000000000000000000000000000000000000000001")
XCTAssertEqual(hexData, "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004")
// XCTAssertEqual(hexData?[0..<32], "0000000000000000000000000000000000000000000000000000000000000001")
XCTAssertEqual(hexData, "01020304")

let types: [ABI.Element.ParameterType] = [.uint(bits: 8),
.bool,
.array(type: .uint(bits: 8), length: 0),
.bytes(length: 2)]
let values: [Any] = [10, false, [1, 2, 3, 4], Data(count: 2)]
hexData = ABIEncoder.encode(types: types, values: values)?.toHexString()
XCTAssertEqual(hexData?[128..<192], "0000000000000000000000000000000000000000000000000000000000000080")
XCTAssertEqual(hexData, "000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004")
XCTAssertEqual(hexData?[128..<192], "6100000000000000000000000000000000000000000000000000000000000000")
XCTAssertEqual(hexData, "0a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000401020304")
}

/// Test for the expected output when encoding dynamic types.
Expand Down

0 comments on commit da65400

Please sign in to comment.