-
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.
test(unit): AccountDeleteTransaction
Signed-off-by: Ricky Saechao <[email protected]>
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* | ||
* 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 HederaProtobufs | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal class AccountDeleteTransactionTests: XCTestCase { | ||
private static let testTransferAccountId = AccountId("0.0.5007") | ||
private static let testAccountId = Resources.accountId | ||
private static let testMaxTransactionFee = Hbar.fromTinybars(100_000) | ||
|
||
private static func makeTransaction() throws -> AccountDeleteTransaction { | ||
try AccountDeleteTransaction() | ||
.nodeAccountIds(Resources.nodeAccountIds) | ||
.transactionId(Resources.txId) | ||
.transferAccountId(testTransferAccountId) | ||
.accountId(testAccountId) | ||
.maxTransactionFee(testMaxTransactionFee) | ||
.freeze() | ||
.sign(Resources.privateKey) | ||
} | ||
|
||
internal func testSerialize() throws { | ||
let tx = try Self.makeTransaction().makeProtoBody() | ||
|
||
assertSnapshot(matching: tx, as: .description) | ||
} | ||
|
||
internal func testToFromBytes() throws { | ||
let tx = try Self.makeTransaction() | ||
let tx2 = try Transaction.fromBytes(tx.toBytes()) | ||
|
||
XCTAssertEqual(try tx.makeProtoBody(), try tx2.makeProtoBody()) | ||
} | ||
|
||
internal func testFromProtoBody() throws { | ||
let protoData = Proto_CryptoDeleteTransactionBody.with { proto in | ||
proto.deleteAccountID = Self.testAccountId.toProtobuf() | ||
proto.transferAccountID = Self.testTransferAccountId.toProtobuf() | ||
} | ||
|
||
let protoBody = Proto_TransactionBody.with { proto in | ||
proto.cryptoDelete = protoData | ||
proto.transactionID = Resources.txId.toProtobuf() | ||
} | ||
|
||
let tx = try AccountDeleteTransaction(protobuf: protoBody, protoData) | ||
|
||
XCTAssertEqual(tx.accountId, Self.testAccountId) | ||
XCTAssertEqual(tx.transferAccountId, Self.testTransferAccountId) | ||
} | ||
|
||
internal func testGetSetAccountId() throws { | ||
let tx = AccountDeleteTransaction() | ||
tx.accountId(Self.testAccountId) | ||
|
||
XCTAssertEqual(tx.accountId, Self.testAccountId) | ||
} | ||
|
||
internal func testGetSetTransferAccountId() throws { | ||
let tx = AccountDeleteTransaction() | ||
tx.transferAccountId(Self.testTransferAccountId) | ||
|
||
XCTAssertEqual(tx.transferAccountId, Self.testTransferAccountId) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Tests/HederaTests/__Snapshots__/AccountDeleteTransactionTests/testSerialize.1.txt
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,24 @@ | ||
HederaProtobufs.Proto_TransactionBody: | ||
transactionID { | ||
transactionValidStart { | ||
seconds: 1554158542 | ||
} | ||
accountID { | ||
accountNum: 5006 | ||
} | ||
} | ||
nodeAccountID { | ||
accountNum: 5005 | ||
} | ||
transactionFee: 100000 | ||
transactionValidDuration { | ||
seconds: 120 | ||
} | ||
cryptoDelete { | ||
transferAccountID { | ||
accountNum: 5007 | ||
} | ||
deleteAccountID { | ||
accountNum: 5009 | ||
} | ||
} |