Skip to content

Commit

Permalink
Merge pull request #106 from keefertaylor/annots
Browse files Browse the repository at this point in the history
Add Annotations model
  • Loading branch information
keefertaylor authored Jul 30, 2019
2 parents c6f3d42 + f88e79c commit c15dcb8
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ extension TezosNodeIntegrationTests {
public func testRunOperation_promises() {
let expectation = XCTestExpectation(description: "completion called")

let operation = OperationFactory.testOperationFactory.originationOperation(address: Wallet.testWallet.address)
let operation = OperationFactory.testOperationFactory.originationOperation(
address: Wallet.testWallet.address,
operationFees: nil
)
nodeClient.runOperation(operation, from: .testWallet) .done { result in
guard let contents = result["contents"] as? [[String: Any]],
let metadata = contents[0]["metadata"] as? [String: Any],
Expand Down Expand Up @@ -203,12 +206,14 @@ extension TezosNodeIntegrationTests {
OperationFactory.testOperationFactory.transactionOperation(
amount: Tez("1")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5"
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFees: nil
),
OperationFactory.testOperationFactory.transactionOperation(
amount: Tez("2")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5"
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFees: nil
)
]

Expand Down
13 changes: 9 additions & 4 deletions IntegrationTests/TezosKit/TezosNodeIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class TezosNodeIntegrationTests: XCTestCase {

/// Sending a bunch of requests quickly can cause race conditions in the Tezos network as counters and operations
/// propagate. Define a throttle period in seconds to wait between each test.
let intertestWaitTime: UInt32 = 0
let intertestWaitTime: UInt32 = 30
sleep(intertestWaitTime)

nodeClient = TezosNodeClient(remoteNodeURL: .nodeURL)
Expand Down Expand Up @@ -287,7 +287,10 @@ class TezosNodeIntegrationTests: XCTestCase {
public func testRunOperation() {
let expectation = XCTestExpectation(description: "completion called")

let operation = OperationFactory.testOperationFactory.originationOperation(address: Wallet.testWallet.address)
let operation = OperationFactory.testOperationFactory.originationOperation(
address: Wallet.testWallet.address,
operationFees: nil
)
self.nodeClient.runOperation(operation, from: .testWallet) { result in
switch result {
case .failure(let error):
Expand Down Expand Up @@ -316,12 +319,14 @@ class TezosNodeIntegrationTests: XCTestCase {
OperationFactory.testOperationFactory.transactionOperation(
amount: Tez("1")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5"
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFees: nil
),
OperationFactory.testOperationFactory.transactionOperation(
amount: Tez("2")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5"
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFees: nil
)
]

Expand Down
18 changes: 18 additions & 0 deletions Tests/TezosKit/MichelsonAnnotationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Keefer Taylor, 2019.

import TezosKit
import XCTest

final class MichelsonAnnotationTests: XCTestCase {
func testValidAnnotations() {
let annotationValue = "tezoskit"
let validAnnotations = [ "@\(annotationValue)", "%\(annotationValue)", ":\(annotationValue)"]
for annotation in validAnnotations {
XCTAssertNotNil(MichelsonAnnotation(annotation: annotation))
}
}

func testInvalidAnnotation() {
XCTAssertNil(MichelsonAnnotation(annotation: "&nonsense"))
}
}
2 changes: 0 additions & 2 deletions Tests/TezosKit/OperationFactoryTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class OperationFactoryTest: XCTestCase {
func testOriginationOperationWithDefaultFees() {
let originationOperation = operationFactory.originationOperation(
address: "tz1abc",
contractCode: nil,
operationFees: nil
)

Expand Down Expand Up @@ -92,7 +91,6 @@ class OperationFactoryTest: XCTestCase {
func testOriginationOperationWithCustomFees() {
let originationOperation = operationFactory.originationOperation(
address: "tz1abc",
contractCode: nil,
operationFees: .testFees
)

Expand Down
8 changes: 8 additions & 0 deletions TezosKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
77FE788422EEA29300B85B9D /* TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FE788322EEA29300B85B9D /* TestHelpers.swift */; };
77FE788622EEE3C800B85B9D /* GetContractStorageRPC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FE788522EEE3C800B85B9D /* GetContractStorageRPC.swift */; };
77FE788822EEE42500B85B9D /* GetContractStorageRPCTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FE788722EEE42500B85B9D /* GetContractStorageRPCTest.swift */; };
77FE788A22EFF92E00B85B9D /* MichelsonAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FE788922EFF92E00B85B9D /* MichelsonAnnotation.swift */; };
77FE788C22EFFA7100B85B9D /* MichelsonAnnotationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FE788B22EFFA7100B85B9D /* MichelsonAnnotationTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -410,6 +412,8 @@
77FE788322EEA29300B85B9D /* TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelpers.swift; sourceTree = "<group>"; };
77FE788522EEE3C800B85B9D /* GetContractStorageRPC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetContractStorageRPC.swift; sourceTree = "<group>"; };
77FE788722EEE42500B85B9D /* GetContractStorageRPCTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetContractStorageRPCTest.swift; sourceTree = "<group>"; };
77FE788922EFF92E00B85B9D /* MichelsonAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MichelsonAnnotation.swift; sourceTree = "<group>"; };
77FE788B22EFFA7100B85B9D /* MichelsonAnnotationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MichelsonAnnotationTests.swift; sourceTree = "<group>"; };
C2BFF006F7695B932864C46D /* Pods_TezosKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TezosKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F4F69CEC90588DB51FE973FC /* Pods_TezosKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TezosKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -461,6 +465,7 @@
isa = PBXGroup;
children = (
7730B1D822E95B4500148990 /* MichelsonParameter.swift */,
77FE788922EFF92E00B85B9D /* MichelsonAnnotation.swift */,
77FE787F22EE907900B85B9D /* MichelsonComparable.swift */,
77FE787722EC336700B85B9D /* NoneMichelsonParameter.swift */,
77FE786922EC320900B85B9D /* BoolMichelsonParameter.swift */,
Expand Down Expand Up @@ -731,6 +736,7 @@
isa = PBXGroup;
children = (
77633D522247EFE20011106A /* TezosNodeClientTests.swift */,
77FE788B22EFFA7100B85B9D /* MichelsonAnnotationTests.swift */,
77FE788722EEE42500B85B9D /* GetContractStorageRPCTest.swift */,
77FE788122EE913300B85B9D /* GetBigMapValueRPCTest.swift */,
77FE786322EBE53200B85B9D /* MichelsonTests.swift */,
Expand Down Expand Up @@ -1096,6 +1102,7 @@
77CE387C21FC7ED8006ADABA /* TezosNodeClient.swift in Sources */,
77CE385E21FC7ED8006ADABA /* Wallet.swift in Sources */,
77CE384D21FC7ED8006ADABA /* TransactionOperation.swift in Sources */,
77FE788A22EFF92E00B85B9D /* MichelsonAnnotation.swift in Sources */,
77CE386621FC7ED8006ADABA /* GetProposalsListRPC.swift in Sources */,
7719265A22D92F5E00E63DE4 /* PreapplicationService.swift in Sources */,
77CE387D21FC7ED8006ADABA /* TezosKitError.swift in Sources */,
Expand Down Expand Up @@ -1141,6 +1148,7 @@
77B69EBF224E92C900DB4319 /* ConseilClientTests.swift in Sources */,
77CE36E321F7F49F006ADABA /* GetChainHeadHashRPCTest.swift in Sources */,
77CE36FA21F7F49F006ADABA /* TezosKitErrorCodesTest.swift in Sources */,
77FE788C22EFFA7100B85B9D /* MichelsonAnnotationTests.swift in Sources */,
77CE370321F7F49F006ADABA /* GetProposalUnderEvaluationRPCTest.swift in Sources */,
77FE788222EE913300B85B9D /* GetBigMapValueRPCTest.swift in Sources */,
77CE36FE21F7F49F006ADABA /* GetBallotsRPCTest.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "772F48A42224894E00DF0F9D"
BuildableName = "IntegrationTests.xctest"
BlueprintName = "IntegrationTests"
ReferencedContainer = "container:TezosKit.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "77CE359E21F7DC76006ADABA"
BuildableName = "TezosKitTests.xctest"
BlueprintName = "TezosKitTests"
ReferencedContainer = "container:TezosKit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</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">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
18 changes: 18 additions & 0 deletions TezosKit/Michelson/MichelsonAnnotation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Keefer Taylor, 2019.

import Foundation

/// A Michelson annotation.
public class MichelsonAnnotation {
public let value: String

/// Initialize a new annotation.
///
/// - Note: Michelson annotations must start with ':', '%', or '@'.
public init?(annotation: String) {
guard annotation.starts(with: ":") || annotation.starts(with: "%") || annotation.starts(with: "@") else {
return nil
}
self.value = annotation
}
}
1 change: 1 addition & 0 deletions TezosKit/Michelson/MichelsonParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Foundation

/// String constants used in Micheline param JSON encoding.
internal enum MichelineConstants {
public static let annotations = "annots"
public static let args = "args"
public static let primitive = "prim"
public static let bytes = "bytes"
Expand Down

0 comments on commit c15dcb8

Please sign in to comment.