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] P256 Signing Via Cryptokit #162

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,30 @@ extension TezosNodeIntegrationTests {

wait(for: [expectation], timeout: .expectationTimeout)
}

public func testRunOperation_promises() {
let expectation = XCTestExpectation(description: "completion called")

let operation = nodeClient.operationFactory.delegateOperation(
source: Wallet.testWallet.address,
to: .testnetBaker,
operationFeePolicy: .default,
signatureProvider: Wallet.testWallet
)!
self.nodeClient.runOperation(operation, from: .testWallet).done { simulationResult in
guard case .success(let consumedGas, let consumedStorage) = simulationResult else {
XCTFail()
return
}
XCTAssertEqual(consumedGas, 10_000)
XCTAssertEqual(consumedStorage, 0)
expectation.fulfill()
} .catch { _ in
XCTFail()
}

wait(for: [expectation], timeout: .expectationTimeout)
}
//
// public func testRunOperation_promises() {
// let expectation = XCTestExpectation(description: "completion called")
//
// let operation = nodeClient.operationFactory.delegateOperation(
// source: Wallet.testWallet.address,
// to: .testnetBaker,
// operationFeePolicy: .default,
// signatureProvider: Wallet.testWallet
// )!
// self.nodeClient.runOperation(operation, from: .testWallet).done { simulationResult in
// guard case .success(let consumedGas, let consumedStorage) = simulationResult else {
// XCTFail()
// return
// }
// XCTAssertEqual(consumedGas, 10_000)
// XCTAssertEqual(consumedStorage, 0)
// expectation.fulfill()
// } .catch { _ in
// XCTFail()
// }
//
// wait(for: [expectation], timeout: .expectationTimeout)
// }

/// Preapplication should failure because of insufficient balance.
public func testPreapplyFailure_promises() {
Expand All @@ -193,38 +193,38 @@ extension TezosNodeIntegrationTests {

wait(for: [expectation], timeout: .expectationTimeout)
}

public func testMultipleOperations_promises() {
let expectation = XCTestExpectation(description: "promise fulfilled")

let ops: [TezosKit.Operation] = [
nodeClient.operationFactory.transactionOperation(
amount: Tez("1")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFeePolicy: .estimate,
signatureProvider: Wallet.testWallet
)!,
nodeClient.operationFactory.transactionOperation(
amount: Tez("2")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFeePolicy: .estimate,
signatureProvider: Wallet.testWallet
)!
]

nodeClient.forgeSignPreapplyAndInject(
operations: ops,
source: Wallet.testWallet.address,
signatureProvider: Wallet.testWallet
) .done { _ in
expectation.fulfill()
} .catch { error in
XCTFail("\(error)")
}
wait(for: [expectation], timeout: .expectationTimeout)
}
//
// public func testMultipleOperations_promises() {
// let expectation = XCTestExpectation(description: "promise fulfilled")
//
// let ops: [TezosKit.Operation] = [
// nodeClient.operationFactory.transactionOperation(
// amount: Tez("1")!,
// source: Wallet.testWallet.address,
// destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
// operationFeePolicy: .estimate,
// signatureProvider: Wallet.testWallet
// )!,
// nodeClient.operationFactory.transactionOperation(
// amount: Tez("2")!,
// source: Wallet.testWallet.address,
// destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
// operationFeePolicy: .estimate,
// signatureProvider: Wallet.testWallet
// )!
// ]
//
// nodeClient.forgeSignPreapplyAndInject(
// operations: ops,
// source: Wallet.testWallet.address,
// signatureProvider: Wallet.testWallet
// ) .done { _ in
// expectation.fulfill()
// } .catch { error in
// XCTFail("\(error)")
// }
// wait(for: [expectation], timeout: .expectationTimeout)
// }

func testSmartContractInvocation_promises() {
let expectation = XCTestExpectation(description: "completion called")
Expand Down
153 changes: 89 additions & 64 deletions Tests/IntegrationTests/TezosKit/TezosNodeIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 = 120
let intertestWaitTime: UInt32 = 0 // 120
sleep(intertestWaitTime)

nodeClient = TezosNodeClient(remoteNodeURL: .nodeURL)
Expand Down Expand Up @@ -243,69 +243,69 @@ class TezosNodeIntegrationTests: XCTestCase {

wait(for: [expectation], timeout: .expectationTimeout)
}

public func testRunOperation() {
let expectation = XCTestExpectation(description: "completion called")

let operation = nodeClient.operationFactory.delegateOperation(
source: Wallet.testWallet.address,
to: .testnetBaker,
operationFeePolicy: .default,
signatureProvider: Wallet.testWallet
)!
self.nodeClient.runOperation(operation, from: .testWallet) { result in
switch result {
case .failure(let error):
print(error)
XCTFail()
case .success(let simulationResult):
guard case .success(let consumedGas, let consumedStorage) = simulationResult else {
XCTFail()
return
}
XCTAssertEqual(consumedGas, 10_000)
XCTAssertEqual(consumedStorage, 0)
expectation.fulfill()
}
}

wait(for: [expectation], timeout: .expectationTimeout)
}

public func testMultipleOperations() {
let expectation = XCTestExpectation(description: "completion called")

let ops: [TezosKit.Operation] = [
nodeClient.operationFactory.transactionOperation(
amount: Tez("1")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFeePolicy: .estimate,
signatureProvider: Wallet.testWallet
)!,
nodeClient.operationFactory.transactionOperation(
amount: Tez("2")!,
source: Wallet.testWallet.address,
destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
operationFeePolicy: .estimate,
signatureProvider: Wallet.testWallet
)!
]

nodeClient.forgeSignPreapplyAndInject(
ops,
source: Wallet.testWallet.address,
signatureProvider: Wallet.testWallet
) { result in
switch result {
case .failure:
XCTFail()
case .success:
expectation.fulfill()
}
}
wait(for: [expectation], timeout: .expectationTimeout)
}
//
// public func testRunOperation() {
// let expectation = XCTestExpectation(description: "completion called")
//
// let operation = nodeClient.operationFactory.delegateOperation(
// source: Wallet.testWallet.address,
// to: .testnetBaker,
// operationFeePolicy: .default,
// signatureProvider: Wallet.testWallet
// )!
// self.nodeClient.runOperation(operation, from: .testWallet) { result in
// switch result {
// case .failure(let error):
// print(error)
// XCTFail()
// case .success(let simulationResult):
// guard case .success(let consumedGas, let consumedStorage) = simulationResult else {
// XCTFail()
// return
// }
// XCTAssertEqual(consumedGas, 10_000)
// XCTAssertEqual(consumedStorage, 0)
// expectation.fulfill()
// }
// }
//
// wait(for: [expectation], timeout: .expectationTimeout)
// }
//
// public func testMultipleOperations() {
// let expectation = XCTestExpectation(description: "completion called")
//
// let ops: [TezosKit.Operation] = [
// nodeClient.operationFactory.transactionOperation(
// amount: Tez("1")!,
// source: Wallet.testWallet.address,
// destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
// operationFeePolicy: .estimate,
// signatureProvider: Wallet.testWallet
// )!,
// nodeClient.operationFactory.transactionOperation(
// amount: Tez("2")!,
// source: Wallet.testWallet.address,
// destination: "tz3WXYtyDUNL91qfiCJtVUX746QpNv5i5ve5",
// operationFeePolicy: .estimate,
// signatureProvider: Wallet.testWallet
// )!
// ]
//
// nodeClient.forgeSignPreapplyAndInject(
// ops,
// source: Wallet.testWallet.address,
// signatureProvider: Wallet.testWallet
// ) { result in
// switch result {
// case .failure:
// XCTFail()
// case .success:
// expectation.fulfill()
// }
// }
// wait(for: [expectation], timeout: .expectationTimeout)
// }

func testSmartContractInvocation() {
let expectation = XCTestExpectation(description: "completion called")
Expand Down Expand Up @@ -631,6 +631,31 @@ class TezosNodeIntegrationTests: XCTestCase {
wait(for: [expectation], timeout: .expectationTimeout)
}

public func testSend_tz3() {
let expectation = XCTestExpectation(description: "completion called")

let tz2Wallet = Wallet(secretKey: "p2sk3F598zRWQkdhYsuxHd1KgytsqvN9Gvn7RLqE24CMghJjDqFo54", signingCurve: .p256)!

self.nodeClient.send(
amount: Tez(1.0),
to: "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW",
from: tz2Wallet.address,
signatureProvider: tz2Wallet,
operationFeePolicy: .estimate
) { result in
switch result {
case .failure(let error):
print(error)
XCTFail()
case .success(let hash):
print(hash)
expectation.fulfill()
}
}

wait(for: [expectation], timeout: .expectationTimeout)
}

public func testGetBigMapValueByID() {
let expectation = XCTestExpectation(description: "Got big map value")

Expand Down
Loading