-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
2,800 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import Hedera | ||
import XCTest | ||
|
||
internal struct Account { | ||
internal let id: AccountId | ||
internal let key: PrivateKey | ||
|
||
internal static func create(_ testEnv: NonfreeTestEnvironment, balance: Hbar = 0) async throws -> Self { | ||
let key = PrivateKey.generateEd25519() | ||
|
||
try await testEnv.ratelimits.accountCreate() | ||
|
||
let receipt = try await AccountCreateTransaction(key: .single(key.publicKey), initialBalance: balance) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client) | ||
|
||
let id = try XCTUnwrap(receipt.accountId) | ||
|
||
return Self(id: id, key: key) | ||
} | ||
|
||
internal func delete(_ testEnv: NonfreeTestEnvironment) async throws { | ||
_ = try await AccountDeleteTransaction() | ||
.accountId(id) | ||
.transferAccountId(testEnv.operator.accountId) | ||
.sign(key) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Tests/HederaE2ETests/Account/AccountAllowanceApprove.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import Hedera | ||
import XCTest | ||
|
||
internal final class AccountAllowanceApprove: XCTestCase { | ||
internal func createAccount(_ testEnv: NonfreeTestEnvironment, balance: Hbar) async throws -> Account { | ||
let account = try await Account.create(testEnv, balance: balance) | ||
|
||
addTeardownBlock { | ||
try await account.delete(testEnv) | ||
} | ||
|
||
return account | ||
} | ||
|
||
internal func testSpend() async throws { | ||
let testEnv = try TestEnvironment.nonFree | ||
async let (alice, bob) = (createAccount(testEnv, balance: 10), createAccount(testEnv, balance: 10)) | ||
|
||
_ = try await AccountAllowanceApproveTransaction() | ||
.approveHbarAllowance(bob.id, alice.id, 10) | ||
.freezeWith(testEnv.client) | ||
.sign(bob.key) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client) | ||
|
||
let transferRecord = try await TransferTransaction() | ||
.hbarTransfer(testEnv.operator.accountId, 5) | ||
.approvedHbarTransfer(bob.id, -5) | ||
.transactionId(TransactionId.generateFrom(alice.id)) | ||
.freezeWith(testEnv.client) | ||
.sign(alice.key) | ||
.execute(testEnv.client) | ||
.getRecord(testEnv.client) | ||
|
||
let transfer = try XCTUnwrap(transferRecord.transfers.first { $0.accountId == testEnv.operator.accountId }) | ||
XCTAssertEqual(transfer.amount, 5) | ||
} | ||
} |
Oops, something went wrong.