Skip to content

Commit

Permalink
test(unit): ScheduleInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Ricky Saechao <[email protected]>
  • Loading branch information
RickyLB committed Sep 7, 2023
1 parent 01503ed commit 049162a
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
117 changes: 117 additions & 0 deletions Tests/HederaTests/ScheduleInfoTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* ‌
* 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 SnapshotTesting
import XCTest

@testable import Hedera

import struct HederaProtobufs.Proto_ScheduleInfo
import struct HederaProtobufs.Proto_CryptoDeleteTransactionBody
import struct HederaProtobufs.Proto_Timestamp

internal final class ScheduleInfoTests: XCTestCase {
internal let unusedPrivateKey: PrivateKey =
"302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"

private func makeDeleteInfo() throws -> ScheduleInfo {
let scheduleId = AnySchedulableTransaction.accountDelete(AccountDeleteTransaction.init().accountId(AccountId("6.6.6"))).toSchedulableTransactionData()

let info = try ScheduleInfo.init(protobuf: try .with { proto in
proto.scheduleID = try ScheduleId.fromString("1.2.3").toProtobuf()
proto.payerAccountID = try AccountId.fromString("3.4.5").toProtobuf()
proto.creatorAccountID = try AccountId.fromString("6.7.8").toProtobuf()
proto.scheduledTransactionID = .with { proto in
proto.accountID = .with{ proto in
proto.accountNum = 5006
}
proto.nonce = 0
proto.scheduled = false
}
proto.scheduledTransactionBody = .with {proto in
proto.data = scheduleId
proto.memo = ""
proto.transactionFee = 200000000
}
proto.signers = .with { proto in
proto.keys = [unusedPrivateKey.publicKey.toProtobuf()]
}
proto.waitForExpiry = true
proto.adminKey = unusedPrivateKey.publicKey.toProtobuf()
proto.memo = "flook"
proto.ledgerID = LedgerId.testnet.bytes
proto.deletionTime = Timestamp(seconds: 1_554_158_542, subSecondNanos: 0).toProtobuf()
})

return info
}

private func makeInfo() throws -> ScheduleInfo {
let scheduleId = AnySchedulableTransaction.accountDelete(AccountDeleteTransaction.init().accountId(AccountId("6.6.6"))).toSchedulableTransactionData()

let info = try ScheduleInfo.init(protobuf: try .with { proto in
proto.scheduleID = try ScheduleId.fromString("1.2.3").toProtobuf()
proto.payerAccountID = try AccountId.fromString("3.4.5").toProtobuf()
proto.creatorAccountID = try AccountId.fromString("6.7.8").toProtobuf()
proto.scheduledTransactionID = .with { proto in
proto.accountID = .with{ proto in
proto.accountNum = 5006
}
proto.nonce = 0
proto.scheduled = false
}
proto.scheduledTransactionBody = .with {proto in
proto.data = scheduleId
proto.memo = ""
proto.transactionFee = 200000000
}
proto.signers = .with { proto in
proto.keys = [unusedPrivateKey.publicKey.toProtobuf()]
}
proto.waitForExpiry = true
proto.adminKey = unusedPrivateKey.publicKey.toProtobuf()
proto.memo = "flook"
proto.ledgerID = LedgerId.testnet.bytes
proto.executionTime = Timestamp(seconds: 1_554_158_542, subSecondNanos: 0).toProtobuf()
})

return info
}

internal func testSerialize() throws {
let info = try makeInfo()

assertSnapshot(matching: info, as: .description)
}

internal func testSerializeDeleted() throws {
let info = try makeDeleteInfo()

assertSnapshot(matching: info, as: .description)
}



// internal func testFromProtobuf() throws {
// let info = try createInfo()

// assertSnapshot(matching: try ScheduleInfo.fromProtobuf(info), as: .description)
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ScheduleInfo(scheduleId: 1.2.3, creatorAccountId: 6.7.8, payerAccountId: Optional(3.4.5), signatories: Hedera.KeyList(keys: [Hedera.Key.single(302a300506032b6570032100e0c8ec2758a5879ffac226a13c0c516b799e72e35141a0dd828f94d37988a4b7)], threshold: nil), adminKey: Optional(Hedera.Key.single(302a300506032b6570032100e0c8ec2758a5879ffac226a13c0c516b799e72e35141a0dd828f94d37988a4b7)), scheduledTransactionId: [email protected], scheduledTransactionBody: HederaProtobufs.Proto_SchedulableTransactionBody:
transactionFee: 200000000
cryptoDelete {
deleteAccountID {
shardNum: 6
realmNum: 6
accountNum: 6
}
}
, waitForExpiry: true, memo: "flook", expirationTime: nil, executedAt: Optional(1554158542000000000), deletedAt: nil, ledgerId: testnet)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ScheduleInfo(scheduleId: 1.2.3, creatorAccountId: 6.7.8, payerAccountId: Optional(3.4.5), signatories: Hedera.KeyList(keys: [Hedera.Key.single(302a300506032b6570032100e0c8ec2758a5879ffac226a13c0c516b799e72e35141a0dd828f94d37988a4b7)], threshold: nil), adminKey: Optional(Hedera.Key.single(302a300506032b6570032100e0c8ec2758a5879ffac226a13c0c516b799e72e35141a0dd828f94d37988a4b7)), scheduledTransactionId: [email protected], scheduledTransactionBody: HederaProtobufs.Proto_SchedulableTransactionBody:
transactionFee: 200000000
cryptoDelete {
deleteAccountID {
shardNum: 6
realmNum: 6
accountNum: 6
}
}
, waitForExpiry: true, memo: "flook", expirationTime: nil, executedAt: nil, deletedAt: Optional(1554158542000000000), ledgerId: testnet)

0 comments on commit 049162a

Please sign in to comment.