Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
chore!: replace ropsten environment for sandbox
Browse files Browse the repository at this point in the history
Ropsten has been deprecated and won't work anymore. Sandbox is the
preferred testing environment.
  • Loading branch information
CassiusPacheco committed Oct 20, 2022
1 parent 468e1e2 commit 5fcc365
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The Core SDK must be initialised before any of its classes are used. Upon initia
For example, you initialise the SDK and retrieve a URL to buy crypto through Moonpay:

```swift
ImmutableX.initialize(base: .ropsten)
ImmutableX.initialize(base: .sandbox)

let url = try await ImmutableX.shared.buyCryptoURL(signer: signer)
```
Expand Down
13 changes: 8 additions & 5 deletions Sources/ImmutableXCore/Config/ImmutableXBase.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/// An enum for defining the environment the SDK will communicate with
public enum ImmutableXBase {
/// Ethereum network
case production
case ropsten

/// The default test network (currently Goerli)
case sandbox

internal var publicApiUrl: String {
switch self {
case .production:
return "https://api.x.immutable.com"
case .ropsten:
return "https://api.ropsten.x.immutable.com"
case .sandbox:
return "https://api.sandbox.x.immutable.com"
}
}

internal var moonpayApiKey: String {
switch self {
case .production:
return "pk_live_lgGxv3WyWjnWff44ch4gmolN0953"
case .ropsten:
case .sandbox:
return "pk_test_nGdsu1IBkjiFzmEvN8ddf4gM9GNy5Sgz"
}
}
Expand All @@ -25,7 +28,7 @@ public enum ImmutableXBase {
switch self {
case .production:
return "https://buy.moonpay.io"
case .ropsten:
case .sandbox:
return "https://buy-staging.moonpay.io"
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ImmutableXCore/ImmutableX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct ImmutableX {
/// is accessed.
public internal(set) static var shared: ImmutableX!

/// The environment the SDK will communicate with. Defaults to `.ropsten`.
/// The environment the SDK will communicate with. Defaults to `.sandbox`.
public let base: ImmutableXBase

/// Defines the level of logging for ImmutableX network calls. Defaults to `.none`.
Expand Down Expand Up @@ -37,7 +37,7 @@ public struct ImmutableX {
private let buyCryptoWorkflow: BuyCryptoWorkflow.Type

/// Internal init method that includes dependencies. For the public facing API use ``initialize(base:logLevel:)`` instead.
internal init(base: ImmutableXBase = .ropsten, logLevel: ImmutableXHTTPLoggingLevel = .none, buyWorkflow: BuyWorkflow.Type = BuyWorkflow.self, sellWorkflow: SellWorkflow.Type = SellWorkflow.self, cancelOrderWorkflow: CancelOrderWorkflow.Type = CancelOrderWorkflow.self, transferWorkflow: TransferWorkflow.Type = TransferWorkflow.self, registerWorkflow: RegisterWorkflow.Type = RegisterWorkflow.self, buyCryptoWorkflow: BuyCryptoWorkflow.Type = BuyCryptoWorkflow.self) {
internal init(base: ImmutableXBase = .sandbox, logLevel: ImmutableXHTTPLoggingLevel = .none, buyWorkflow: BuyWorkflow.Type = BuyWorkflow.self, sellWorkflow: SellWorkflow.Type = SellWorkflow.self, cancelOrderWorkflow: CancelOrderWorkflow.Type = CancelOrderWorkflow.self, transferWorkflow: TransferWorkflow.Type = TransferWorkflow.self, registerWorkflow: RegisterWorkflow.Type = RegisterWorkflow.self, buyCryptoWorkflow: BuyCryptoWorkflow.Type = BuyCryptoWorkflow.self) {
self.base = base
self.logLevel = logLevel
self.buyWorkflow = buyWorkflow
Expand All @@ -49,7 +49,7 @@ public struct ImmutableX {
}

/// Initializes the SDK with the given ``base`` and ``logLevel`` by assigning a shared instance accessible via `ImmutableX.shared`.
public static func initialize(base: ImmutableXBase = .ropsten, logLevel: ImmutableXHTTPLoggingLevel = .none) {
public static func initialize(base: ImmutableXBase = .sandbox, logLevel: ImmutableXHTTPLoggingLevel = .none) {
ImmutableX.shared = ImmutableX(base: base, logLevel: logLevel)
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/ImmutableXCoreTests/Config/ImmutableXBaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import XCTest
final class ImmutableXBaseTests: XCTestCase {
func testPublicApiUrl() async throws {
XCTAssertEqual(ImmutableXBase.production.publicApiUrl, "https://api.x.immutable.com")
XCTAssertEqual(ImmutableXBase.ropsten.publicApiUrl, "https://api.ropsten.x.immutable.com")
XCTAssertEqual(ImmutableXBase.sandbox.publicApiUrl, "https://api.sandbox.x.immutable.com")
}

func testMoonpayApiKey() async throws {
XCTAssertEqual(ImmutableXBase.production.moonpayApiKey, "pk_live_lgGxv3WyWjnWff44ch4gmolN0953")
XCTAssertEqual(ImmutableXBase.ropsten.moonpayApiKey, "pk_test_nGdsu1IBkjiFzmEvN8ddf4gM9GNy5Sgz")
XCTAssertEqual(ImmutableXBase.sandbox.moonpayApiKey, "pk_test_nGdsu1IBkjiFzmEvN8ddf4gM9GNy5Sgz")
}

func testBuyCryptoUrl() async throws {
XCTAssertEqual(ImmutableXBase.production.buyCryptoUrl, "https://buy.moonpay.io")
XCTAssertEqual(ImmutableXBase.ropsten.buyCryptoUrl, "https://buy-staging.moonpay.io")
XCTAssertEqual(ImmutableXBase.sandbox.buyCryptoUrl, "https://buy-staging.moonpay.io")
}
}
4 changes: 2 additions & 2 deletions Tests/ImmutableXCoreTests/ImmutableXTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ final class ImmutableXTests: XCTestCase {
}

func testInitialize() {
ImmutableX.initialize(base: .ropsten, logLevel: .calls(including: [.requestBody]))
XCTAssertEqual(ImmutableX.shared.base, .ropsten)
ImmutableX.initialize(base: .sandbox, logLevel: .calls(including: [.requestBody]))
XCTAssertEqual(ImmutableX.shared.base, .sandbox)

if case .calls(including: [.requestBody]) = ImmutableX.shared.logLevel {
// success
Expand Down
2 changes: 1 addition & 1 deletion Tests/ImmutableXCoreTests/Mocks/Stubs/Models.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
@testable import ImmutableXCore

let coreStub1 = ImmutableX(base: .ropsten, buyWorkflow: BuyWorkflowMock.self, sellWorkflow: SellWorkflowMock.self, cancelOrderWorkflow: CancelOrderWorkflowMock.self, transferWorkflow: TransferWorkflowMock.self, registerWorkflow: RegisterWorkflowMock.self)
let coreStub1 = ImmutableX(base: .sandbox, buyWorkflow: BuyWorkflowMock.self, sellWorkflow: SellWorkflowMock.self, cancelOrderWorkflow: CancelOrderWorkflowMock.self, transferWorkflow: TransferWorkflowMock.self, registerWorkflow: RegisterWorkflowMock.self)

let tokenETHStub1 = Token(
data: TokenData(
Expand Down
10 changes: 5 additions & 5 deletions Tests/ImmutableXCoreTests/Workflows/BuyCryptoWorkflowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class BuyCryptoWorkflowTests: XCTestCase {
let response = try await BuyCryptoWorkflow.buyCryptoURL(
colorCodeHex: "#000000",
signer: SignerMock(),
base: .ropsten,
base: .sandbox,
moonpayAPI: moonpayAPI,
exchangesAPI: exchangesAPI,
usersAPI: usersAPI
Expand All @@ -54,7 +54,7 @@ final class BuyCryptoWorkflowTests: XCTestCase {
_ = try await BuyCryptoWorkflow.buyCryptoURL(
colorCodeHex: "#000000",
signer: SignerMock(),
base: .ropsten,
base: .sandbox,
moonpayAPI: self.moonpayAPI,
exchangesAPI: self.exchangesAPI,
usersAPI: self.usersAPI
Expand All @@ -71,7 +71,7 @@ final class BuyCryptoWorkflowTests: XCTestCase {
_ = try await BuyCryptoWorkflow.buyCryptoURL(
colorCodeHex: "#000000",
signer: SignerMock(),
base: .ropsten,
base: .sandbox,
moonpayAPI: self.moonpayAPI,
exchangesAPI: self.exchangesAPI,
usersAPI: self.usersAPI
Expand All @@ -88,7 +88,7 @@ final class BuyCryptoWorkflowTests: XCTestCase {
_ = try await BuyCryptoWorkflow.buyCryptoURL(
colorCodeHex: "#000000",
signer: SignerMock(),
base: .ropsten,
base: .sandbox,
moonpayAPI: self.moonpayAPI,
exchangesAPI: self.exchangesAPI,
usersAPI: self.usersAPI
Expand All @@ -105,7 +105,7 @@ final class BuyCryptoWorkflowTests: XCTestCase {
_ = try await BuyCryptoWorkflow.buyCryptoURL(
colorCodeHex: "#000000",
signer: SignerMock(),
base: .ropsten,
base: .sandbox,
moonpayAPI: self.moonpayAPI,
exchangesAPI: self.exchangesAPI,
usersAPI: self.usersAPI
Expand Down
4 changes: 2 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"version": "0.1"
},
"host": "api.ropsten.x.immutable.com",
"host": "api.sandbox.x.immutable.com",
"basePath": "/",
"paths": {
"/v1/assets": {
Expand Down Expand Up @@ -5369,4 +5369,4 @@
"x-go-gen-location": "models"
}
}
}
}

0 comments on commit 5fcc365

Please sign in to comment.