Skip to content

Commit

Permalink
Merge pull request #45 from portto/feat/addPlatformParam
Browse files Browse the repository at this point in the history
add: platform parameter
  • Loading branch information
POLAX7 authored Jan 11, 2023
2 parents 1aa3fd8 + 2370883 commit e34ca3f
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 21 deletions.
6 changes: 4 additions & 2 deletions Example/Tests/Methods/SendTransactionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import XCTest
import BigInt

class SendTransactionTests: XCTestCase {


let platform = "sdk_ios"
var mockUIApplication: MockUIApplication!

override func setUp() {
Expand Down Expand Up @@ -52,7 +53,8 @@ class SendTransactionTests: XCTestCase {
URLQueryItem(name: .from, value: from),
URLQueryItem(name: .to, value: to),
URLQueryItem(name: .value, value: "0x7b"),
URLQueryItem(name: .data, value: "0x" + dataString)
URLQueryItem(name: .data, value: "0x" + dataString),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down
22 changes: 15 additions & 7 deletions Example/Tests/URLEncode/EVMBaseMethodURLEncodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import BigInt
// swiftlint:disable type_body_length
class EVMBaseMethodURLEncodeTests: XCTestCase {

let platform = "sdk_ios"
func testURLComponent() throws {
// Given:
let item = URLQueryItem(name: .accountProof, value: "123 456 % 1")
Expand All @@ -38,7 +39,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .appId, value: appId),
URLQueryItem(name: .requestId, value: requestId.uuidString),
URLQueryItem(name: .blockchain, value: Blockchain.ethereum.rawValue),
URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue)
URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -74,7 +76,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue),
URLQueryItem(name: .signType, value: EVMBaseSignType.sign.rawValue),
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .message, value: message)
URLQueryItem(name: .message, value: message),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -110,7 +113,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue),
URLQueryItem(name: .signType, value: EVMBaseSignType.personalSign.rawValue),
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .message, value: message)
URLQueryItem(name: .message, value: message),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -211,7 +215,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue),
URLQueryItem(name: .signType, value: EVMBaseSignType.typedSignV3.rawValue),
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .message, value: message)
URLQueryItem(name: .message, value: message),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -331,7 +336,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: EVMBaseMethodType.signMessage.rawValue),
URLQueryItem(name: .signType, value: EVMBaseSignType.typedSignV4.rawValue),
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .message, value: message)
URLQueryItem(name: .message, value: message),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -370,7 +376,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .to, value: to),
URLQueryItem(name: .value, value: "0x0"),
URLQueryItem(name: .data, value: "0x" + dataString)
URLQueryItem(name: .data, value: "0x" + dataString),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -409,7 +416,8 @@ class EVMBaseMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .from, value: ethereumAddress),
URLQueryItem(name: .to, value: to),
URLQueryItem(name: .value, value: "0x100"),
URLQueryItem(name: .data, value: "0x" + dataString)
URLQueryItem(name: .data, value: "0x" + dataString),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down
8 changes: 7 additions & 1 deletion Example/Tests/URLEncode/FlowMethodURLEncodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import FlowSDK
@testable import BloctoSDK

final class FlowMethodURLEncodeTests: XCTestCase {


let platform = "sdk_ios"
func testFlowRequestAccount() throws {
// Given:
let requestId = UUID()
Expand All @@ -27,6 +28,7 @@ final class FlowMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .requestId, value: requestId.uuidString),
URLQueryItem(name: .blockchain, value: Blockchain.flow.rawValue),
URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand All @@ -53,6 +55,7 @@ final class FlowMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .requestId, value: requestId.uuidString),
URLQueryItem(name: .blockchain, value: Blockchain.flow.rawValue),
URLQueryItem(name: .method, value: FlowMethodType.authenticate.rawValue),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -84,6 +87,7 @@ final class FlowMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: FlowMethodType.authenticate.rawValue),
URLQueryItem(name: .flowAppId, value: appId),
URLQueryItem(name: .flowNonce, value: nonce),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -120,6 +124,7 @@ final class FlowMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: FlowMethodType.userSignature.rawValue),
URLQueryItem(name: .from, value: address),
URLQueryItem(name: .message, value: message),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -173,6 +178,7 @@ final class FlowMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: FlowMethodType.sendTransaction.rawValue),
URLQueryItem(name: .from, value: addressString),
URLQueryItem(name: .flowTransaction, value: transactionDataHex),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down
10 changes: 7 additions & 3 deletions Example/Tests/URLEncode/SolanaMethodURLEncodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import XCTest

class SolanaMethodURLEncodeTests: XCTestCase {

let platform = "sdk_ios"
func testSolanaRequestAccount() throws {
// Given:
let requestId = UUID()
Expand All @@ -23,7 +24,8 @@ class SolanaMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .appId, value: appId),
URLQueryItem(name: .requestId, value: requestId.uuidString),
URLQueryItem(name: .blockchain, value: Blockchain.solana.rawValue),
URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue)
URLQueryItem(name: .method, value: MethodName.requestAccount.rawValue),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -61,7 +63,8 @@ class SolanaMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .method, value: SolanaMethodType.signAndSendTransaction.rawValue),
URLQueryItem(name: .from, value: solanaAddress),
URLQueryItem(name: .isInvokeWrapped, value: "true"),
URLQueryItem(name: .message, value: messageHex)
URLQueryItem(name: .message, value: messageHex),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down Expand Up @@ -117,7 +120,8 @@ class SolanaMethodURLEncodeTests: XCTestCase {
URLQueryItem(name: .message, value: messageHex),
URLQueryItem(name: "\(QueryName.appendTx.rawValue)[\(appendTxKey1)]", value: appendTxValue1),
URLQueryItem(name: "\(QueryName.appendTx.rawValue)[\(appendTxKey2)]", value: appendTxValue2),
URLQueryItem(name: "\(QueryName.publicKeySignaturePairs.rawValue)[\(publicKey)]", value: signature)
URLQueryItem(name: "\(QueryName.publicKeySignaturePairs.rawValue)[\(publicKey)]", value: signature),
URLQueryItem(name: .platform, value: platform)
]

// When:
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Methods/RequestAccountMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct RequestAccountMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems = URLEncoding.queryItems(
var queryItems = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
2 changes: 2 additions & 0 deletions Sources/Core/Models/QueryName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public enum QueryName: String {

// error
case error

case platform
}
6 changes: 5 additions & 1 deletion Sources/Core/Utilities/URLEncoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import Foundation

public enum URLEncoding {

static func queryItems(
static func queryGeneralItems(
appId: String,
requestId: String,
blockchain: Blockchain
) -> [QueryItem] {

let platform: String = "sdk_ios"

let queryItems = [
QueryItem(name: .appId, value: appId),
QueryItem(name: .requestId, value: requestId),
QueryItem(name: .blockchain, value: blockchain.rawValue),
QueryItem(name: .platform, value: platform)
]
return queryItems
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct SendEVMBasedTransactionMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems = URLEncoding.queryItems(
var queryItems = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
2 changes: 1 addition & 1 deletion Sources/EVMBase/Methods/SignEVMBaseMessageMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public struct SignEVMBaseMessageMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems = URLEncoding.queryItems(
var queryItems = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
2 changes: 1 addition & 1 deletion Sources/Flow/Methods/AuthenticateMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct AuthenticateMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems = URLEncoding.queryItems(
var queryItems = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
2 changes: 1 addition & 1 deletion Sources/Flow/Methods/SendFlowTransactionMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct SendFlowTransactionMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) else {
return nil
}
var queryItems: [QueryItem] = URLEncoding.queryItems(
var queryItems: [QueryItem] = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
2 changes: 1 addition & 1 deletion Sources/Flow/Methods/SignFlowMessageMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public struct SignFlowMessageMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems = URLEncoding.queryItems(
var queryItems = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct SignAndSendSolanaTransactionMethod: CallbackMethod {
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
return nil
}
var queryItems: [QueryItem] = URLEncoding.queryItems(
var queryItems: [QueryItem] = URLEncoding.queryGeneralItems(
appId: appId,
requestId: id.uuidString,
blockchain: blockchain
Expand Down

0 comments on commit e34ca3f

Please sign in to comment.