mirror of
https://github.com/luxfi/safe-ios.git
synced 2026-10-30 15:19:20 +00:00
36 lines
1.3 KiB
Swift
36 lines
1.3 KiB
Swift
//
|
|
// File.swift
|
|
//
|
|
//
|
|
// Created by Dmitry Bespalov on 03.01.22.
|
|
//
|
|
|
|
import Foundation
|
|
import Solidity
|
|
import XCTest
|
|
|
|
class FunctionEncodingTests: XCTestCase {
|
|
func testEncode() {
|
|
let value = Sol.Function(address: Sol.Address(storage: Sol.UInt160(0xef)),
|
|
selector: Sol.Bytes4(storage: Data([0x11, 0x22, 0x33, 0x44])))
|
|
let data = value.encode()
|
|
let expected = Data([
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16 bytes
|
|
0x00, 0x00, 0x00, 0xef, 0x11, 0x22, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32 bytes
|
|
])
|
|
XCTAssertEqual(Array(data), Array(expected))
|
|
}
|
|
|
|
func testDecode() throws {
|
|
let expected = Sol.Function(address: Sol.Address(storage: Sol.UInt160(0xef)),
|
|
selector: Sol.Bytes4(storage: Data([0x11, 0x22, 0x33, 0x44])))
|
|
let data = Data([
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16 bytes
|
|
0x00, 0x00, 0x00, 0xef, 0x11, 0x22, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 32 bytes
|
|
])
|
|
var offset = 0
|
|
let value = try Sol.Function(from: data, offset: &offset)
|
|
XCTAssertEqual(value, expected)
|
|
}
|
|
}
|