|
1 | | -import { Container, Utils as KernelUtils } from "@arkecosystem/core-kernel"; |
2 | | -import { NetworkStateStatus } from "@arkecosystem/core-p2p/src/enums"; |
3 | | -import { NetworkState } from "@arkecosystem/core-p2p/src/network-state"; |
4 | | -import { Peer } from "@arkecosystem/core-p2p/src/peer"; |
5 | | -import { PeerVerificationResult } from "@arkecosystem/core-p2p/src/peer-verifier"; |
6 | | -import { Blocks, Crypto, Utils } from "@arkecosystem/crypto"; |
| 1 | +import { Container, Utils as KernelUtils } from "@packages/core-kernel"; |
| 2 | +import { NetworkStateStatus } from "@packages/core-p2p/src/enums"; |
| 3 | +import { NetworkState } from "@packages/core-p2p/src/network-state"; |
| 4 | +import { Peer } from "@packages/core-p2p/src/peer"; |
| 5 | +import { PeerVerificationResult } from "@packages/core-p2p/src/peer-verifier"; |
| 6 | +import { Blocks, Crypto, Utils } from "@packages/crypto"; |
7 | 7 |
|
8 | 8 | describe("NetworkState", () => { |
| 9 | + // @ts-ignore |
9 | 10 | const lastBlock = { |
10 | 11 | data: { |
11 | 12 | id: "17882607875259085966", |
@@ -152,6 +153,54 @@ describe("NetworkState", () => { |
152 | 153 | }); |
153 | 154 | }); |
154 | 155 |
|
| 156 | + describe("getNodeHeight", () => { |
| 157 | + it("should return node height", () => { |
| 158 | + const data = { |
| 159 | + status: NetworkStateStatus.Test, |
| 160 | + nodeHeight: 31, |
| 161 | + lastBlockId: "10024d739768a68b43a6e4124718129e1fe07b0461630b3f275b7640d298c3b7", |
| 162 | + quorumDetails: { |
| 163 | + peersQuorum: 31, |
| 164 | + peersNoQuorum: 7, |
| 165 | + peersOverHeight: 0, |
| 166 | + peersOverHeightBlockHeaders: {}, |
| 167 | + peersForked: 0, |
| 168 | + peersDifferentSlot: 0, |
| 169 | + peersForgingNotAllowed: 1, |
| 170 | + }, |
| 171 | + }; |
| 172 | + |
| 173 | + const networkState = NetworkState.parse(data); |
| 174 | + |
| 175 | + expect(networkState.getNodeHeight()).toBe(31); |
| 176 | + }); |
| 177 | + }); |
| 178 | + |
| 179 | + describe("getLastBlockId", () => { |
| 180 | + it("should return lats block id", () => { |
| 181 | + const data = { |
| 182 | + status: NetworkStateStatus.Test, |
| 183 | + nodeHeight: 31, |
| 184 | + lastBlockId: "10024d739768a68b43a6e4124718129e1fe07b0461630b3f275b7640d298c3b7", |
| 185 | + quorumDetails: { |
| 186 | + peersQuorum: 31, |
| 187 | + peersNoQuorum: 7, |
| 188 | + peersOverHeight: 0, |
| 189 | + peersOverHeightBlockHeaders: {}, |
| 190 | + peersForked: 0, |
| 191 | + peersDifferentSlot: 0, |
| 192 | + peersForgingNotAllowed: 1, |
| 193 | + }, |
| 194 | + }; |
| 195 | + |
| 196 | + const networkState = NetworkState.parse(data); |
| 197 | + |
| 198 | + expect(networkState.getLastBlockId()).toBe( |
| 199 | + "10024d739768a68b43a6e4124718129e1fe07b0461630b3f275b7640d298c3b7", |
| 200 | + ); |
| 201 | + }); |
| 202 | + }); |
| 203 | + |
155 | 204 | describe("getQuorum", () => { |
156 | 205 | it("should return 1 when NetworkStateStatus.Test", () => { |
157 | 206 | const data = { |
|
0 commit comments