Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Sep 23, 2024
1 parent 82e39ee commit f8263d4
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
CARGO_TERM_COLOR: always
VERSION: ${{ github.event.inputs.version || '0.0.8' }}
VERSION: ${{ github.event.inputs.version || '0.0.9' }}
TARGET_BRANCH: ${{ github.ref_name }}

permissions:
Expand Down
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0")
// .package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0")
],
targets: [
.binaryTarget(
Expand All @@ -34,16 +34,16 @@ let package = Package(
.target(
name: "Yttrium",
dependencies: [
"YttriumCore",
.product(name: "SwiftDotenv", package: "swift-dotenv")
"YttriumCore"
// .product(name: "SwiftDotenv", package: "swift-dotenv")
],
path: "platforms/swift/Sources/Yttrium"
),
.testTarget(
name: "YttriumTests",
dependencies: [
"Yttrium",
.product(name: "SwiftDotenv", package: "swift-dotenv")
"Yttrium"
// .product(name: "SwiftDotenv", package: "swift-dotenv")
],
path: "platforms/swift/Tests/YttriumTests"
),
Expand Down
7 changes: 5 additions & 2 deletions crates/ffi/YttriumCore/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ let package = Package(
targets: ["YttriumCore"]
),
],
dependencies: [],
dependencies: [
.package(url: "https://github.com/thebarndog/swift-dotenv.git", from: "2.0.0")
],
targets: [
.binaryTarget(
name: "RustXcframework",
Expand All @@ -23,7 +25,8 @@ let package = Package(
.target(
name: "YttriumCore",
dependencies: [
"RustXcframework"
"RustXcframework",
.product(name: "SwiftDotenv", package: "swift-dotenv")
]
),
.testTarget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public final class AccountClient: AccountClientProtocol {
id: signerId,
onSign: { message in
onSign(message)
.mapError(YttriumCore.SignerError.from(error:))
}
)
register(signer: .native(nativeSigner))
Expand Down Expand Up @@ -143,12 +142,3 @@ extension Transaction {
)
}
}

extension YttriumCore.SignerError {
static func from(error: SignerError) -> Self {
switch error {
case .unknown:
return .unknown
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public final class AccountClient7702 {
id: signerId,
onSign: { message in
onSign(message)
.mapError(YttriumCore.SignerError.from(error:))
}
)
register(signer: .native(nativeSigner))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import YttriumCore

public struct Transaction: Codable, Equatable {
let to: String
Expand All @@ -13,11 +12,6 @@ public struct Transaction: Codable, Equatable {
}
}

public enum SignerError: Error {
case unknown
}

public typealias OnSign = (String) -> Result<String, SignerError>

public protocol AccountClientProtocol {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import YttriumCore

public struct Endpoint {

Expand Down
12 changes: 6 additions & 6 deletions crates/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ mod ffi {
}

extern "Swift" {
type NativeSignerFFI;
pub type NativeSignerFFI;

#[swift_bridge(init)]
fn new(signer_id: String) -> NativeSignerFFI;
pub fn new(signer_id: String) -> NativeSignerFFI;

fn sign(&self, message: String) -> FFIStringResult;
pub fn sign(&self, message: String) -> FFIStringResult;
}

extern "Swift" {
type PrivateKeySignerFFI;
pub type PrivateKeySignerFFI;

#[swift_bridge(init)]
fn new(signer_id: String) -> PrivateKeySignerFFI;
pub fn new(signer_id: String) -> PrivateKeySignerFFI;

fn private_key(&self) -> FFIStringResult;
pub fn private_key(&self) -> FFIStringResult;
}
}
100 changes: 50 additions & 50 deletions platforms/swift/Tests/YttriumTests/AccountClientTests.swift
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import Foundation
import XCTest
@testable import YttriumCore
@testable import Yttrium
// import Foundation
// import XCTest
// @testable import YttriumCore
// @testable import Yttrium

final class AccountClientTests: XCTestCase {
// final class AccountClientTests: XCTestCase {

static let mnemonic = "test test test test test test test test test test test junk"
// static let mnemonic = "test test test test test test test test test test test junk"

/// Using `mnemonic` derived at `m/44'/60'/0'/0/0`
static let privateKeyHex = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
// /// Using `mnemonic` derived at `m/44'/60'/0'/0/0`
// static let privateKeyHex = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"

static let entryPoint = "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
// static let entryPoint = "0x0000000071727De22E5E9d8BAf0edAc6f37da032"

/// `Ethereum Sepolia` chain ID
static let chainId = 11155111
// /// `Ethereum Sepolia` chain ID
// static let chainId = 11155111

static let ownerAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
// static let ownerAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"

static let simpleAccountAddress = "0x75BD33d92EEAC5Fe41446fcF5953050d691E7fc9"
// static let simpleAccountAddress = "0x75BD33d92EEAC5Fe41446fcF5953050d691E7fc9"

func testSendTransaction() async throws {
let config = Config.local()
// func testSendTransaction() async throws {
// let config = Config.local()

let accountClient = AccountClient(
ownerAddress: Self.ownerAddress,
entryPoint: Self.entryPoint,
chainId: Self.chainId,
config: config,
signerType: .privateKey
)
accountClient.register(privateKey: Self.privateKeyHex)
// let accountClient = AccountClient(
// ownerAddress: Self.ownerAddress,
// entryPoint: Self.entryPoint,
// chainId: Self.chainId,
// config: config,
// signerType: .privateKey
// )
// accountClient.register(privateKey: Self.privateKeyHex)

let transaction = Transaction.mock()
// let transaction = Transaction.mock()

let user_operation_hash = try await accountClient.sendTransaction(transaction)
}
// let user_operation_hash = try await accountClient.sendTransaction(transaction)
// }

func testGetAddress() async throws {
let config = Config.local()
// func testGetAddress() async throws {
// let config = Config.local()

let accountClient = AccountClient(
ownerAddress: Self.ownerAddress,
entryPoint: Self.entryPoint,
chainId: Self.chainId,
config: config,
signerType: .privateKey
)
accountClient.register(privateKey: Self.privateKeyHex)
// let accountClient = AccountClient(
// ownerAddress: Self.ownerAddress,
// entryPoint: Self.entryPoint,
// chainId: Self.chainId,
// config: config,
// signerType: .privateKey
// )
// accountClient.register(privateKey: Self.privateKeyHex)

let expectedAddress = Self.simpleAccountAddress
// let expectedAddress = Self.simpleAccountAddress

let address = try await accountClient.getAddress()
// let address = try await accountClient.getAddress()

XCTAssertEqual(address, expectedAddress)
}
}
// XCTAssertEqual(address, expectedAddress)
// }
// }

extension Transaction {
// extension Transaction {

public static func mock() -> Self {
Self(
to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
value: "0",
data: "0x68656c6c6f"
)
}
}
// public static func mock() -> Self {
// Self(
// to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
// value: "0",
// data: "0x68656c6c6f"
// )
// }
// }

0 comments on commit f8263d4

Please sign in to comment.