libmobilecoin-ios-artifacts/LibMobileCoinExample/Tests/LibMobileCoinExampleTests/StaticLibraryAPI.swift
Adam Mork 1991953d9d
Add SPM support for LibMobileCoin (#61)
* add new recipe to generate things needed for SPM, sort of WIP because not using variables, will adjust when solution is verified working, git-lfs support ?

* use git lfs, update makefile for correct checksum workflow, use standard header file, update template with dependencies

* use git lfs

* update template, fix syntax errors in package.swift

* autocorrect Package.swift

* change dependency names

* relint and recopute framework

* temporarily upload to s3

* redo how checksum saved computed

* update

* update

* update

* update

* update

* update

* update

* update path rules for CoreHTTP

* update path rules for CoreHTTP

* update path rules for CoreHTTP

* reshuffle directories, add package.resolved

* reshuffle directories, add package.resolved

* reshuffle directories, add more targets for individual paths

* regen

* rename dependencies

* reshuffle again

* do correct syntax

* fix import paths

* fix import paths

* fix import paths again

* fix import paths again

* renaming

* renaming

* renaming

* specify extra module imports correctly

* specify extra module imports correctly

* add resources to test vector

* make resource a dir not a path

* make resource a dir not a path

* add test-vectors to source control and into the Sources dir to try and get them loading as resources

* change path of test-vectors

* iterate on bundle resource finding solution

* copy vectors into Sources folder for the target and flatten the directories to make it easier for Bundle search to find

* flatten test vectors

* add macos to makefile targets, fix folder removal

* revert toolchain

* fix directory removal call

* add SCI to primary header

* recompute xcframework after changing libmobilecoin header after finding SCI was missing

* add example project to test all parts of the libmobilecoin SPM

* add test recipe to the makefile

* add GRPC product, remove Product from naming

* create seperate name for the static library target unique from the cocoapods stuff. Will use #canImport in swift code

* change name of xcframework with Library suffix, segregate Bundle helper for SPM in its own file so it can be excluded from cocoapods

* change name of xcframework with Library suffix, segregate Bundle helper for SPM in its own file so it can be excluded from cocoapods

* add sed command to add canImport precondition to GRPC clients

* regenerate HTTP clients after latest protoc-gen-http-swift

* increment version for spm changes

* use v5.0.0-pre2 mobilecoin

* remove macabi from inner makefile

* remove catalyst targets from the xcframework

* checkin new generated stuff, need to figure out why bundle.zip not created, and why certain files not being tracked that were previously.

* regen spm stuff, add cbindgen to tracking in the include folder although probably can remove, add the module.modulemap to tracking unsure why it was removed.

* track the xcframework file in Artifacts, and use it via local path instead of remote

* remove bundle.zip + remote workflow, now replaced with local path solution.

* bring xcframework gen to top-level makefile, better this way cus it can re-generate off the static libs in the Artifacts folder, previously a full-build was required because the paths pulled from the build folder. Do the same for the new test-vector copying thats required by the SPM changes

* remove old xcframework gen recipe from the inner

* remove old recipes also remove cmake patch recipe needed for macabi targets and their script

* we want to setup in the inner Makefile aswell

* remove the bundle zip

* remove clients from the common folder

* add mistyswap clients to network folder

* add static libraries for new mac targets and old targets

* temp removals for cocoapods testing

* add gitlfs attibutes for large files

* move modulemap to its own folder. change makefile to create temporary headers folder, checking xcframework and its innards, update gitattributes to track the large static libs in gitlfs, update podspec to be compatible

* add info plist i guess

* re-add back in cmake patch script, still needed for darwin

* fix indentation makefile

* update circle config to fix type with intel macos build target naming in one of the steps, add apple silicon macos to building, this should fix the copy-artifacts target

* fix naming

* add m1 macos target to dependency

* fix package versions and definitions here too

* increment versions to 5.0.2, also use macos machine for generate step, needed to create the XCFramework, this can be broken into a separate step but for now this makes sense

* fix some imports in the libmobilecoin test project

* use macos machine for generate ?

* rename

* rename

* revert to ubuntu machine for docker, generate xcframework in copy step

* remove xcode version from config

* [skip ci] commit build Artifacts and generated protos from build machine

* add git-lfs installation to the generate job

* [skip ci] commit build Artifacts and generated protos from build machine

---------

Co-authored-by: mobilecoin-ci <mobilecoin-ci@mobilecoin.com>
2023-06-14 15:31:19 -07:00

177 lines
5.6 KiB
Swift

//
// StaticLibraryAPI.swift
//
//
// Created by Adam Mork on 4/26/23.
//
import XCTest
import LibMobileCoin
///
/// Testing one function from each rust file to make sure they're all available in the
/// static library. Some data is invalid and will throw errors, thats ok.
///
final class StaticLibraryAPI: XCTestCase {
func testAttestHeader() throws {
let data = Data()
let _ = data.asMcBuffer({ ptr in
mc_mr_enclave_verifier_create(ptr)
})
XCTAssertTrue(true)
}
func testBip39Header() throws {
let data = Data()
let _ = data.asMcBuffer({ ptr in
mc_bip39_mnemonic_from_entropy(ptr)
})
XCTAssertTrue(true)
}
func testChaCha20Header() throws {
let value = UInt64(0)
var error: UnsafeMutablePointer<McError>?
mc_chacha20_rng_create_with_long(value, &error)
XCTAssertTrue(true)
}
func testCryptoHeader() throws {
let data = Data()
var bool = true
let _ = data.asMcBuffer({ ptr in
mc_ristretto_private_validate(ptr, &bool)
})
XCTAssertTrue(true)
}
func testEncodingsHeader() throws {
let data = Data()
let _ = data.asMcBuffer({ ptr in
mc_printable_wrapper_b58_encode(ptr)
})
XCTAssertTrue(true)
}
func testFogHeader() throws {
let ptr = OpaquePointer(bitPattern: 1)!
let data = Data()
var error: UnsafeMutablePointer<McError>?
let _ = data.asMcBuffer({ reportResponsePtr in
mc_fog_resolver_add_report_response(
ptr,
"reportUrl.url.absoluteString",
reportResponsePtr,
&error)
})
XCTAssertTrue(true)
}
func testKeysHeader() throws {
let viewPrivateKey = Data()
let spendPrivateKey = Data()
let subaddressIndex = UInt64(0)
var subaddressViewPrivateKeyOut = Data()
var subaddressSpendPrivateKeyOut = Data()
let _ = viewPrivateKey.asMcBuffer { viewKeyBufferPtr in
spendPrivateKey.asMcBuffer { spendKeyBufferPtr in
subaddressViewPrivateKeyOut.asMcMutableBuffer { viewPrivateKeyOutPtr in
subaddressSpendPrivateKeyOut.asMcMutableBuffer { spendPrivateKeyOutPtr in
mc_account_key_get_subaddress_private_keys(
viewKeyBufferPtr,
spendKeyBufferPtr,
subaddressIndex,
viewPrivateKeyOutPtr,
spendPrivateKeyOutPtr)
}
}
}
}
XCTAssertTrue(true)
}
func testSCIHeader() throws {
let sci = Data()
var errorPtr: UnsafeMutablePointer<McError>?
let _ = sci.asMcBuffer { sciPtr in
mc_signed_contingent_input_data_is_valid(
sciPtr,
&errorPtr
)
}
XCTAssertTrue(true)
}
func testSlip10Header() throws {
let accountIndex = UInt32(0)
var viewPrivateKeyOut = Data()
var spendPrivateKeyOut = Data()
var errorPtr: UnsafeMutablePointer<McError>?
let _ = viewPrivateKeyOut.asMcMutableBuffer { viewPrivateKeyOutPtr in
spendPrivateKeyOut.asMcMutableBuffer { spendPrivateKeyOutPtr in
mc_slip10_account_private_keys_from_mnemonic(
"mnemonic.phrase",
accountIndex,
viewPrivateKeyOutPtr,
spendPrivateKeyOutPtr,
&errorPtr)
}
}
XCTAssertTrue(true)
}
func testTransactionHeader() throws {
let publicKey = Data()
let viewPrivateKey = Data()
var buffer = Data()
var errorPtr: UnsafeMutablePointer<McError>?
let _ = publicKey.asMcBuffer { publicKeyBufferPtr in
viewPrivateKey.asMcBuffer { viewPrivateKeyPtr in
buffer.asMcMutableBuffer { bufferPtr in
mc_tx_out_get_shared_secret(
viewPrivateKeyPtr,
publicKeyBufferPtr,
bufferPtr,
&errorPtr)
}
}
}
XCTAssertTrue(true)
}
}
extension Data {
func asMcBuffer<T>(_ body: (UnsafePointer<McBuffer>) throws -> T) rethrows -> T {
try self.withUnsafeBytes {
let ptr : UnsafeBufferPointer<UInt8> = $0.bindMemory(to: UInt8.self)
guard let bufferPtr = ptr.baseAddress else {
// This indicates a programming error. Pointer returned from withUnsafeBytes
// shouldn't have a nil baseAddress.
throw TestingError.unknown
}
var buffer = McBuffer(buffer: bufferPtr, len: ptr.count)
return try body(&buffer)
}
}
mutating func asMcMutableBuffer<T>(
_ body: (UnsafeMutablePointer<McMutableBuffer>) throws -> T
) rethrows -> T {
try withUnsafeMutableBytes {
let ptr : UnsafeMutableBufferPointer<UInt8> = $0.bindMemory(to: UInt8.self)
guard let bufferPtr = ptr.baseAddress else {
// This indicates a programming error. Pointer returned from withUnsafeMutableBytes
// shouldn't have a nil baseAddress.
throw TestingError.unknown
}
var buffer = McMutableBuffer(buffer: bufferPtr, len: ptr.count)
return try body(&buffer)
}
}
}
enum TestingError: Error {
case unknown
}