Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] #5

Open
wants to merge 7 commits into
base: refactor/swift-concurency
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: On pull request

on:
pull_request:
branches:
- 'main'
- 'refactor/swift-concurency'

jobs:
unit-test:
runs-on: macos-12
steps:
- uses: actions/checkout@v3
- name: Run tests
run: swift test --filter "OrcaSwapSwift" --enable-code-coverage
- name: Processing converage data
run: |
xcrun llvm-cov export -format="lcov" .build/debug/OrcaSwapSwift.xctest/Contents/MacOS/OrcaSwapSwift -instr-profile .build/debug/codecov/default.profdata > info.lcov
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
files: ./info.lcov # optional
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
4 changes: 2 additions & 2 deletions OrcaSwapSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'OrcaSwapSwift'
s.version = '2.0.0'
s.version = '2.1.1'
s.summary = 'A client for OrcaSwap written in Swift.'
s.description = <<-DESC
TODO: Add long description of the pod here.
Expand All @@ -25,5 +25,5 @@ TODO: Add long description of the pod here.

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'SolanaSwift', '~> 2.0.0'
s.dependency 'SolanaSwift', '~> 2.1.1'
end
10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"package": "SolanaSwift",
"repositoryURL": "https://github.com/p2p-org/solana-swift.git",
"state": {
"branch": "refactor/pwn-3297",
"revision": "2c3fc55c5c4efd68da680de10e1504140c2e54e7",
"version": null
"branch": null,
"revision": "7b1ef1cdb1a595d0dafc39bcb4c5603b7f56dd52",
"version": "2.1.1"
}
},
{
"package": "Task_retrying",
"repositoryURL": "https://github.com/bigearsenal/task-retrying-swift.git",
"state": {
"branch": null,
"revision": "c93fef795874cf31b7b0f8f6e9c23f4f15188dec",
"version": "1.0.2"
"revision": "645eaaf207a6f39ab4b469558d916ae23df199b5",
"version": "1.0.3"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
targets: ["OrcaSwapSwift"]),
],
dependencies: [
.package(url: "https://github.com/p2p-org/solana-swift.git", branch: "refactor/pwn-3297")
.package(url: "https://github.com/p2p-org/solana-swift.git", from: "2.1.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
3 changes: 3 additions & 0 deletions Sources/OrcaSwapSwift/OrcaSwap/OrcaSwap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ public class OrcaSwap: OrcaSwapType {

// retrieve all routes
var poolsPairs = [PoolsPair]()
try Task.checkCancellation()
try await withThrowingTaskGroup(of: [Pool]?.self) {group in
for route in currentRoutes where route.count <= 2 {
group.addTask { [weak self] in
guard let self = self else {return nil}
try Task.checkCancellation()
return try await self.getPools(
forRoute: route,
fromTokenName: fromTokenName,
Expand All @@ -121,6 +123,7 @@ public class OrcaSwap: OrcaSwapType {
}

for try await pools in group {
try Task.checkCancellation()
guard let pools = pools else {continue}
poolsPairs.append(pools)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/IntegrationTests/SwapIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private extension OrcaSwapSwift.Pool {
private struct MockAccountStorage: SolanaAccountStorage {
let _account: Account
var account: Account? {
get throws {
get {
_account
}
}
Expand Down
19 changes: 11 additions & 8 deletions Tests/UnitTests/OrcaSwap/OrcaSwapPreparationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ class OrcaSwapPreparationTests: XCTestCase {
apiClient: APIClient(configsProvider: MockConfigsProvider()),
solanaClient: solanaAPIClient,
blockchainClient: blockchainClient,
accountStorage: MockAccountStorage()
accountStorage: MockAccountStorage(
_account: try await Account(
phrase: "miracle pizza supply useful steak border same again youth silver access hundred"
.components(separatedBy: " "),
network: .mainnetBeta,
derivablePath: .init(type: .deprecated, walletIndex: 0)
)
)
)
try await orcaSwap.load()
}
Expand Down Expand Up @@ -237,14 +244,10 @@ private class MockSolanaAPIClient: JSONRPCAPIClient {
}

private struct MockAccountStorage: SolanaAccountStorage {
let _account: Account
var account: Account? {
get throws {
try? .init(
phrase: "miracle pizza supply useful steak border same again youth silver access hundred"
.components(separatedBy: " "),
network: .mainnetBeta,
derivablePath: .init(type: .deprecated, walletIndex: 0)
)
get {
_account
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/OrcaSwap/SwapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private extension OrcaSwapSwift.Pool {
private struct MockAccountStorage: SolanaAccountStorage {
let _account: Account
var account: Account? {
get throws {
get {
_account
}
}
Expand Down