-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTokenMintTransactionTests.swift
101 lines (76 loc) · 3.02 KB
/
TokenMintTransactionTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// SPDX-License-Identifier: Apache-2.0
import HieroProtobufs
import SnapshotTesting
import XCTest
@testable import Hiero
internal final class TokenMintTransactionTests: XCTestCase {
private static let testTokenId: TokenId = "4.2.0"
private static let testAmount: UInt64 = 10
private static let testMetadata = [Data([1, 2, 3, 4, 5])]
private static func makeTransaction() throws -> TokenMintTransaction {
try TokenMintTransaction()
.nodeAccountIds(Resources.nodeAccountIds)
.transactionId(Resources.txId)
.sign(Resources.privateKey)
.tokenId(testTokenId)
.amount(testAmount)
.freeze()
}
private static func makeMetadataTransaction() throws -> TokenMintTransaction {
try TokenMintTransaction()
.nodeAccountIds(Resources.nodeAccountIds)
.transactionId(Resources.txId)
.sign(Resources.privateKey)
.tokenId(testTokenId)
.metadata(testMetadata)
.freeze()
}
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 testSerializeMetadata() throws {
let tx = try Self.makeMetadataTransaction().makeProtoBody()
assertSnapshot(matching: tx, as: .description)
}
internal func testToFromBytesMetadata() throws {
let tx = try Self.makeMetadataTransaction()
let tx2 = try Transaction.fromBytes(tx.toBytes())
XCTAssertEqual(try tx.makeProtoBody(), try tx2.makeProtoBody())
}
internal func testFromProtoBody() throws {
let protoData = Proto_TokenMintTransactionBody.with { proto in
proto.token = Self.testTokenId.toProtobuf()
proto.amount = Self.testAmount
proto.metadata = Self.testMetadata
}
let protoBody = Proto_TransactionBody.with { proto in
proto.tokenMint = protoData
proto.transactionID = Resources.txId.toProtobuf()
}
let tx = try TokenMintTransaction(protobuf: protoBody, protoData)
XCTAssertEqual(tx.tokenId, Self.testTokenId)
XCTAssertEqual(tx.amount, Self.testAmount)
XCTAssertEqual(tx.metadata, Self.testMetadata)
}
internal func testGetSetTokenId() {
let tx = TokenMintTransaction()
tx.tokenId(Self.testTokenId)
XCTAssertEqual(tx.tokenId, Self.testTokenId)
}
internal func testGetSetAmount() {
let tx = TokenMintTransaction()
tx.amount(Self.testAmount)
XCTAssertEqual(tx.amount, Self.testAmount)
}
internal func testGetSetMetadata() {
let tx = TokenMintTransaction()
tx.metadata(Self.testMetadata)
XCTAssertEqual(tx.metadata, Self.testMetadata)
}
}