Skip to content

Commit

Permalink
Renamed packages, Unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
metallicalfa2 committed Apr 30, 2020
1 parent ff6d22e commit 07bfc00
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 81 deletions.
Binary file not shown.
88 changes: 88 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/FetchNodeDetails.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FetchNodeDetails"
BuildableName = "FetchNodeDetails"
BlueprintName = "FetchNodeDetails"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FetchNodeDetailsTests"
BuildableName = "FetchNodeDetailsTests"
BlueprintName = "FetchNodeDetailsTests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "fetch_node_detailsTestsSync">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync/testBigIntCapabilities()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync/testgetCurrentEpoch()">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FetchNodeDetails"
BuildableName = "FetchNodeDetails"
BlueprintName = "FetchNodeDetails"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "fetch_node_detailsTests">
</Test>
<Test
Identifier = "fetch_node_detailsTests/testBigIntCapabilities()">
</Test>
Expand All @@ -96,11 +99,23 @@
<Test
Identifier = "fetch_node_detailsTests/testGetNodeEndpoints()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsAsync">
</Test>
<Test
Identifier = "fetch_node_detailsTestsAsync/test_async_getCurrentEpoch()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync">
Identifier = "fetch_node_detailsTestsAsync/test_getNodeDetailsPromise()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync/testBigIntCapabilities()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync/testGetNodeDetails()">
</Test>
<Test
Identifier = "fetch_node_detailsTestsSync/testgetCurrentEpoch()">
</Test>
</SkippedTests>
</TestableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>fetch-node-details.xcscheme_^#shared#^_</key>
<key>FetchNodeDetails.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>fetch-node-details.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
Expand Down
18 changes: 6 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
import PackageDescription

let package = Package(
name: "fetch-node-details",
name: "FetchNodeDetails",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "fetch-node-details",
targets: ["fetch-node-details"]),
name: "FetchNodeDetails",
targets: ["FetchNodeDetails"]),
],
dependencies: [
// .package(url: "https://github.com/attaswift/BigInt.git", from: "5.0.0"),
// .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.8.4"),
// .package(url: "https://github.com/daltoniam/Starscream.git", from: "3.1.0"),
// .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.0.0")
.package(url: "https://github.com/rathishubham7/web3swift", from:"2.2.2")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
// .target(name: "secp256k1"),
// .target(name: "web3swift", dependencies: ["BigInt", "secp256k1", "PromiseKit", "Starscream", "CryptoSwift"]),
.target(
name: "fetch-node-details", dependencies: ["web3swift"]),
name: "FetchNodeDetails", dependencies: ["web3swift"]),
.testTarget(
name: "fetch-node-detailsTests",
dependencies: ["fetch-node-details"]),
name: "FetchNodeDetailsTests",
dependencies: ["FetchNodeDetails"]),
]
)
Binary file modified Sources/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ extension FetchNodeDetails {
transactionOptions: options)!

let txPromise = tx.callPromise()
let rp = Promise<Int>.pending()
let (tempPromise, seal) = Promise<Int>.pending()

txPromise.done{ data in
let epoch = data.first?.value
guard let newEpoch = epoch else { throw "some error"}
print(newEpoch)
rp.resolver.fulfill(Int("\(newEpoch)")!)
seal.fulfill(Int("\(newEpoch)")!)
}

return rp.promise
return tempPromise
}

public func getEpochInfoPromise(epoch : Int) throws -> Promise<EpochInfo>{
Expand All @@ -53,10 +52,7 @@ extension FetchNodeDetails {
parameters: parameters,
extraData: extraData,
transactionOptions: options)!
//
// let result = tx.callPromise()
// let (promise, resolver) = Promise<EpochInfo>.pending()


let returnPromise = Promise<EpochInfo>{ seal in
let txPromise = tx.callPromise()
txPromise.done{ response in
Expand Down Expand Up @@ -86,7 +82,7 @@ extension FetchNodeDetails {
return returnPromise
}

public func getNodeEndpointPromise(nodeEthAddress: String) throws -> Promise<NodeInfo> {
public func getNodeEndpointPromise(nodeEthAddress: String) -> Promise<NodeInfo> {
let contractMethod = "getNodeDetails"
let parameters: [AnyObject] = [nodeEthAddress as AnyObject] // Parameters for contract method
let extraData: Data = Data() // Extra data for contract method
Expand All @@ -108,11 +104,15 @@ extension FetchNodeDetails {
// Unwraping Any? -> Any
guard let declaredIp = response["declaredIp"] else { throw "Casting for declaredIp from Any? to Any failed" }
guard let position = response["position"] else { throw "Casting for position from Any? to Any failed" }
guard let pubKx = response["pubKx"] else { throw "Casting for pubKx from Any? to Any failed" }
guard let pubKy = response["pubKy"] else { throw "Casting for pubKy from Any? to Any failed" }
guard var pubKx = response["pubKx"] else { throw "Casting for pubKx from Any? to Any failed" }
guard var pubKy = response["pubKy"] else { throw "Casting for pubKy from Any? to Any failed" }
guard let tmP2PListenAddress = response["tmP2PListenAddress"] else { throw "Casting for tmP2PListenAddress from Any? to Any failed" }
guard let p2pListenAddress = response["p2pListenAddress"] else { throw "Casting for p2pListenAddress from Any? to Any failed" }

//Change to hex
pubKx = String(BigInt("\(pubKx)", radix:10)!, radix:16, uppercase: true)
pubKy = String(BigInt("\(pubKy)", radix:10)!, radix:16, uppercase: true)

let object = NodeInfo(_declaredIp: "\(declaredIp)", _position: "\(position)", _pubKx: "\(pubKx)", _pubKy: "\(pubKy)", _tmP2PListenAddress: "\(tmP2PListenAddress)", _p2pListenAddress: "\(p2pListenAddress)")
seal.fulfill(object)
}.catch{err in seal.reject(err)}
Expand All @@ -121,52 +121,42 @@ extension FetchNodeDetails {
}

public func getNodeDetailsPromise() throws -> Promise<Bool>{
//if(self.nodeDetails.getUpdated()) { return self.nodeDetails }
//let (promise, resolver) = Promise<Int>.pending()
print("ASDF")
var currentEpoch: Int = -1;

let returnPromise = Promise<Bool> { seal in
let currentEpochPromise = try self.getCurrentEpochPromise();
currentEpochPromise.then{ response -> Promise<EpochInfo> in
print("currentEpoch is", response)
currentEpoch = response
return try self.getEpochInfoPromise(epoch: response)
}.then{epochInfo -> Guarantee<[Result<NodeInfo>]> in
let nodelist = epochInfo.getNodeList();
print("nodeList is", nodelist)
var torusIndexes:[BigInt] = Array()
var nodeEndPoints:[NodeInfo] = Array()
var getNodeInfoPromisesArray:[Promise<NodeInfo>] = Array()
for i in 0..<nodelist.count{
torusIndexes.append(BigInt(i+1))
//print(BigInt(i+1))
getNodeInfoPromisesArray.append(try self.getNodeEndpointPromise(nodeEthAddress: nodelist[i]))
}
return when(resolved: getNodeInfoPromisesArray)
}.done{ results in
//print(results)
var updatedEndpoints: Array<String> = Array()
var updatedNodePub:Array<TorusNodePub> = Array()

for result in results{
switch result {
case .fulfilled(let value):
// print(value)
let endPointElement:NodeInfo = value;
let endpoint = "https://" + endPointElement.getDeclaredIp().split(separator: ":")[0] + "/jrpc";
updatedEndpoints.append(endpoint)

let hexPubX = String(BigInt(endPointElement.getPubKx(), radix:10)!, radix:16, uppercase: true)
let hexPubY = String(BigInt(endPointElement.getPubKy(), radix:10)!, radix:16, uppercase: true)
let hexPubX = endPointElement.getPubKx()
let hexPubY = endPointElement.getPubKy()
updatedNodePub.append(TorusNodePub(_X: hexPubX, _Y: hexPubY))
default:
seal.reject("error with node info")
}

}
print(updatedNodePub, updatedEndpoints)


self.nodeDetails.setNodeListAddress(nodeListAddress: self.proxyAddress.address);
self.nodeDetails.setCurrentEpoch(currentEpoch: String(currentEpoch));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
// Created by Shubham on 13/3/20.
//


/// todo
/// Fix getpubkeyX and getpubkeyY

import Foundation
import web3swift
import BigInt

public class FetchNodeDetails {

var web3 : web3
var network : EthereumNetwork = EthereumNetwork.MAINNET;
var network : EthereumNetwork = EthereumNetwork.ROPSTEN;
var proxyAddress : EthereumAddress = EthereumAddress("0x638646503746d5456209e33a2ff5e3226d698bea")!
var walletAddress : EthereumAddress = EthereumAddress("0x5F7A02a42bF621da3211aCE9c120a47AA5229fBA")!
let yourContractABI: String = contractABIString
Expand Down Expand Up @@ -103,17 +107,19 @@ public class FetchNodeDetails {
//print(tx)

let result = try! tx.call()
//print(result.keys)
//print(result.values)

// Unwraping Any? -> Any
guard let declaredIp = result["declaredIp"] else { throw "Casting for declaredIp from Any? to Any failed" }
guard let position = result["position"] else { throw "Casting for position from Any? to Any failed" }
guard let pubKx = result["pubKx"] else { throw "Casting for pubKx from Any? to Any failed" }
guard let pubKy = result["pubKy"] else { throw "Casting for pubKy from Any? to Any failed" }
guard var pubKx = result["pubKx"] else { throw "Casting for pubKx from Any? to Any failed" }
guard var pubKy = result["pubKy"] else { throw "Casting for pubKy from Any? to Any failed" }
guard let tmP2PListenAddress = result["tmP2PListenAddress"] else { throw "Casting for tmP2PListenAddress from Any? to Any failed" }
guard let p2pListenAddress = result["p2pListenAddress"] else { throw "Casting for p2pListenAddress from Any? to Any failed" }


//Change to hex
pubKx = String(BigInt("\(pubKx)", radix:10)!, radix:16, uppercase: true)
pubKy = String(BigInt("\(pubKy)", radix:10)!, radix:16, uppercase: true)

let object = NodeInfo(_declaredIp: "\(declaredIp)", _position: "\(position)", _pubKx: "\(pubKx)", _pubKy: "\(pubKy)", _tmP2PListenAddress: "\(tmP2PListenAddress)", _p2pListenAddress: "\(p2pListenAddress)")
return object
}
Expand All @@ -132,7 +138,6 @@ public class FetchNodeDetails {
torusIndexes.append(BigInt(i+1))
nodeEndPoints.append(try! getNodeEndpoint(nodeEthAddress: nodelist[i]))
}
// print(torusIndexes, nodeEndPoints)

var updatedEndpoints: Array<String> = Array()
var updatedNodePub:Array<TorusNodePub> = Array()
Expand All @@ -142,14 +147,11 @@ public class FetchNodeDetails {
let endpoint = "https://" + endPointElement.getDeclaredIp().split(separator: ":")[0] + "/jrpc";
updatedEndpoints.append(endpoint)

let hexPubX = String(BigInt(endPointElement.getPubKx(), radix:10)!, radix:16, uppercase: true)
let hexPubY = String(BigInt(endPointElement.getPubKy(), radix:10)!, radix:16, uppercase: true)
let hexPubX = endPointElement.getPubKx()
let hexPubY = endPointElement.getPubKy()
updatedNodePub.append(TorusNodePub(_X: hexPubX, _Y: hexPubY))
//print(hexPubX,hexPubY)
}

// print(updatedNodePub, updatedEndpoints)

self.nodeDetails.setNodeListAddress(nodeListAddress: self.proxyAddress.address);
self.nodeDetails.setCurrentEpoch(currentEpoch: String(currentEpoch));
self.nodeDetails.setTorusNodeEndpoints(torusNodeEndpoints: updatedEndpoints);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 07bfc00

Please sign in to comment.