Skip to content

Commit

Permalink
test(unit): StakingInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Ricky Saechao <[email protected]>
  • Loading branch information
RickyLB committed Sep 13, 2023
1 parent 6b0b985 commit 40542a6
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 3 deletions.
3 changes: 0 additions & 3 deletions Tests/HederaTests/ProxyStakerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import XCTest
@testable import Hedera

internal final class ProxyStakerTests: XCTestCase {
private static let testMemo = "test Memo"
private static let testContents: Data = "[swift::unit::fileUpdate::1]".data(using: .utf8)!

private static let proxyStaker: Proto_ProxyStaker = .with { proto in
proto.accountID = Resources.accountId.toProtobuf()
proto.amount = 10
Expand Down
76 changes: 76 additions & 0 deletions Tests/HederaTests/StakingInfoTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* ‌
* 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 final class StakingInfoTests: XCTestCase {

private static let stakingInfoAccount: Proto_StakingInfo = .with { proto in
proto.declineReward = true
proto.stakePeriodStart = Resources.validStart.toProtobuf()
proto.pendingReward = 5
proto.stakedToMe = 10
proto.stakedAccountID = Resources.accountId.toProtobuf()
}

private static let stakingInfoNode: Proto_StakingInfo = .with { proto in
proto.declineReward = true
proto.stakePeriodStart = Resources.validStart.toProtobuf()
proto.pendingReward = 5
proto.stakedToMe = 10
proto.stakedNodeID = 3
}

internal func testFromProtobufAccount() throws {
assertSnapshot(matching: try StakingInfo.fromProtobuf(Self.stakingInfoAccount), as: .description)
}

internal func testToProtobufAccount() throws {
assertSnapshot(matching: try StakingInfo.fromProtobuf(Self.stakingInfoAccount).toProtobuf(), as: .description)
}

internal func testFromProtobufNode() throws {
assertSnapshot(matching: try StakingInfo.fromProtobuf(Self.stakingInfoNode), as: .description)
}

internal func testToProtobufNode() throws {
assertSnapshot(matching: try StakingInfo.fromProtobuf(Self.stakingInfoNode).toProtobuf(), as: .description)
}

internal func testFromBytesAccount() throws {
assertSnapshot(matching: try StakingInfo.fromBytes(Self.stakingInfoAccount.serializedData()), as: .description)
}

internal func testToBytesAccount() throws {
assertSnapshot(matching: try StakingInfo.fromBytes(Self.stakingInfoAccount.serializedData()).toBytes().toHexString(), as: .description)
}

internal func testFromBytesNode() throws {
assertSnapshot(matching: try StakingInfo.fromBytes(Self.stakingInfoNode.serializedData()), as: .description)
}

internal func testToBytesNode() throws {
assertSnapshot(matching: try StakingInfo.fromBytes(Self.stakingInfoNode.serializedData()).toBytes().toHexString(), as: .description)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StakingInfo(declineStakingReward: true, stakePeriodStart: Optional(1554158542000000000), pendingReward: 5 tℏ, stakedToMe: 10 tℏ, stakedAccountId: Optional(0.0.5009), stakedNodeId: nil)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StakingInfo(declineStakingReward: true, stakePeriodStart: Optional(1554158542000000000), pendingReward: 5 tℏ, stakedToMe: 10 tℏ, stakedAccountId: nil, stakedNodeId: Optional(3))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StakingInfo(declineStakingReward: true, stakePeriodStart: Optional(1554158542000000000), pendingReward: 5 tℏ, stakedToMe: 10 tℏ, stakedAccountId: Optional(0.0.5009), stakedNodeId: nil)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
StakingInfo(declineStakingReward: true, stakePeriodStart: Optional(1554158542000000000), pendingReward: 5 tℏ, stakedToMe: 10 tℏ, stakedAccountId: nil, stakedNodeId: Optional(3))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0801120608cea78ae5051805200a2a03189127
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0801120608cea78ae5051805200a3003
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
HederaProtobufs.Proto_StakingInfo:
decline_reward: true
stake_period_start {
seconds: 1554158542
}
pending_reward: 5
staked_to_me: 10
staked_account_id {
accountNum: 5009
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HederaProtobufs.Proto_StakingInfo:
decline_reward: true
stake_period_start {
seconds: 1554158542
}
pending_reward: 5
staked_to_me: 10
staked_node_id: 3

0 comments on commit 40542a6

Please sign in to comment.