diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..973fcba3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,38 @@ +--- +name: Pull Request +about: '' +title: 'feat: description of fix' +labels: '' +assignees: '' + +--- + + +# Description + +Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes # (issue) + +## Type of change + +- [ ] Chore (chore: description-of-task) +- [ ] Fix (fix: description-of-fix) +- [ ] Feature (feat: description-of-fix) +- [ ] Docs (docs: description-of-docs-added-or-modified) +- [ ] Test (test: description-of-tests-performed) +- [ ] Refactor (refactor: description-of-refactor) + +Please specify the type of change in your title following the above format + + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] Any dependent changes have been merged and published in downstream modules \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c2a102..81a19dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.1.0-alpha.4](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.1.0-alpha.3...v1.1.0-alpha.4) (2021-04-29) + + +### Features + +* Replaced type with enum for types with multiple values ([#157](https://github.com/thenewboston-developers/thenewboston-js/issues/157)) ([cab172b](https://github.com/thenewboston-developers/thenewboston-js/commit/cab172be7a8d87713fa88ac601e916f99715c71d)) + + +### Bug Fixes + +* `Account.isValidPair` throwing on invalid seeds ([#152](https://github.com/thenewboston-developers/thenewboston-js/issues/152)) ([1a18fad](https://github.com/thenewboston-developers/thenewboston-js/commit/1a18fad5e143658e66b2beb01829fbd1c99780d1)), closes [#151](https://github.com/thenewboston-developers/thenewboston-js/issues/151) + ## [1.1.0-alpha.3](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2021-04-12) diff --git a/jest.config.js b/jest.config.js index e354fdc9..ed4dde44 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,4 +5,6 @@ module.exports = { coverageProvider: "v8", // The test environment that will be used for testing testEnvironment: "node", + + transformIgnorePatterns: ["node_modules/nock/"], }; diff --git a/package-lock.json b/package-lock.json index eb6759bf..4c584d52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "thenewboston", - "version": "1.1.0-alpha.3", + "version": "1.1.0-alpha.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ed110c6b..ccd61e9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "thenewboston", - "version": "1.1.0-alpha.3", + "version": "1.1.0-alpha.4", "description": "JavaScript library for thenewboston.", "author": { "name": "thenewboston-developers", diff --git a/src/account.ts b/src/account.ts index a6df78e4..18faa9f8 100644 --- a/src/account.ts +++ b/src/account.ts @@ -52,7 +52,11 @@ export class Account { * @param accountNumber the given account number hex string */ static isValidPair(signingKey: string, accountNumber: string) { - return new Account(signingKey).accountNumberHex === accountNumber; + try { + return new Account(signingKey).accountNumberHex === accountNumber; + } catch (_) { + return false; + } } /** The 32 byte account number as a 32 byte hex string. */ diff --git a/src/confirmation-validator.ts b/src/confirmation-validator.ts index de321784..b6245a77 100644 --- a/src/confirmation-validator.ts +++ b/src/confirmation-validator.ts @@ -1,12 +1,20 @@ import { Validator } from "./validator"; import type { Account } from "./account"; -import type { ConfirmationValidatorConfigResponse, CleanResponse, CrawlResponse, CleanData, CrawlData } from "./models"; +import type { + BankConfirmationServices, + ConfirmationValidatorConfigResponse, + CleanResponse, + CrawlResponse, + CleanData, + CrawlData, + PaginationOptions, +} from "./models"; /** Used for connecting with and using confirmation validator server nodes. */ export class ConfirmationValidator extends Validator { /** Gets the current confirmation confirmation validator's listed services. */ - async getBankConfirmationServices() { - return await super.getData("/bank_confirmation_services"); + async getBankConfirmationServices(options: Partial = {}) { + return await super.getPaginatedData("/bank_confirmation_services", options); } /** Gets the current crawl status */ diff --git a/src/models/responses/bank/config.ts b/src/models/responses/bank/config.ts index 9ff4edb1..390be0ab 100644 --- a/src/models/responses/bank/config.ts +++ b/src/models/responses/bank/config.ts @@ -22,5 +22,5 @@ export interface BankConfigResponse { protocol: Protocol; version: Version; default_transaction_fee: number; - node_type: NodeType; + node_type: NodeType.bank; } diff --git a/src/models/responses/confirmation-validator/config.ts b/src/models/responses/confirmation-validator/config.ts index df00cdd8..9516dc74 100644 --- a/src/models/responses/confirmation-validator/config.ts +++ b/src/models/responses/confirmation-validator/config.ts @@ -26,5 +26,5 @@ export interface ConfirmationValidatorConfigResponse { root_account_file_hash: Hex; seed_block_identifier: Hex; daily_confirmation_rate: number; - node_type: NodeType; + node_type: NodeType.confirmationValidator; } diff --git a/src/models/responses/constants.ts b/src/models/responses/constants.ts index b6892535..675bbd7c 100644 --- a/src/models/responses/constants.ts +++ b/src/models/responses/constants.ts @@ -1,4 +1,8 @@ -export type NodeType = "BANK" | "CONFIRMATION_VALIDATOR" | "PRIMARY_VALIDATOR"; +export enum NodeType { + bank = "BANK", + confirmationValidator = "CONFIRMATION_VALIDATOR", + primaryValidator = "PRIMARY_VALIDATOR", +} export type Version = "v1.0"; export type Protocol = "http" | "https"; export type Port = number; diff --git a/src/models/responses/generic/clean.ts b/src/models/responses/generic/clean.ts index 937d8999..aa46ed27 100644 --- a/src/models/responses/generic/clean.ts +++ b/src/models/responses/generic/clean.ts @@ -1,9 +1,15 @@ import type { Origin, Port, Protocol } from "../constants"; +export enum CleanStatus { + cleaning = "cleaning", + notCleaning = "not_cleaning", + stopRequested = "stop_requested", +} + /** The response model for a crawl request. */ export interface CleanResponse { clean_last_completed: string; - clean_status: string; + clean_status: CleanStatus | null; ip_address: Origin; port: Port; protocol: Protocol; diff --git a/src/models/responses/generic/confirmation-block.ts b/src/models/responses/generic/confirmation-block.ts new file mode 100644 index 00000000..7cec6cc4 --- /dev/null +++ b/src/models/responses/generic/confirmation-block.ts @@ -0,0 +1,17 @@ +import { BlockMessage } from "../../block-message"; + +export interface UpdatedBalance { + account_number: string; + balance: number; + balance_lock?: string; +} + +export interface ConfirmationBlock { + message: { + block: BlockMessage; + block_identifier: string; + updated_balances: UpdatedBalance[]; + }; + node_identifier: string; + signature: string; +} diff --git a/src/models/responses/generic/crawl.ts b/src/models/responses/generic/crawl.ts index e0f17094..8ecdfe56 100644 --- a/src/models/responses/generic/crawl.ts +++ b/src/models/responses/generic/crawl.ts @@ -1,9 +1,15 @@ import type { Origin, Port, Protocol } from "../constants"; +export enum CrawlStatus { + crawling = "crawling", + notCrawling = "not_crawling", + stopRequested = "stop_requested", +} + /** The response model for a crawl request. */ export interface CrawlResponse { crawl_last_completed: string; - crawl_status: string; + crawl_status: CrawlStatus | null; ip_address: Origin; port: Port; protocol: Protocol; diff --git a/src/models/responses/generic/index.ts b/src/models/responses/generic/index.ts index 7ba1ad71..3bc1f313 100644 --- a/src/models/responses/generic/index.ts +++ b/src/models/responses/generic/index.ts @@ -2,3 +2,4 @@ export type { AccountBalanceLockResponse } from "./account-balance-lock"; export type { AccountBalanceResponse } from "./account-balance"; export type { CleanResponse } from "./clean"; export type { CrawlResponse } from "./crawl"; +export type { ConfirmationBlock, UpdatedBalance } from "./confirmation-block"; diff --git a/src/models/responses/pagination/entries/confirmation-services.ts b/src/models/responses/pagination/entries/confirmation-services.ts new file mode 100644 index 00000000..95a0be8d --- /dev/null +++ b/src/models/responses/pagination/entries/confirmation-services.ts @@ -0,0 +1,11 @@ +import { PaginatedEntry } from "../"; + +export interface ConfirmationServices extends PaginatedEntry { + end: string; + start: string; + bank: string; + validator: string; +} + +export type BankConfirmationServices = Omit; +export type ValidatorConfirmationServices = Omit; diff --git a/src/models/responses/pagination/entries/index.ts b/src/models/responses/pagination/entries/index.ts index 72de7570..fdf5f28f 100644 --- a/src/models/responses/pagination/entries/index.ts +++ b/src/models/responses/pagination/entries/index.ts @@ -3,3 +3,4 @@ export type { PaginatedBankEntry } from "./bank"; export type { PaginatedBlockEntry } from "./block"; export type { PaginatedValidatorEntry } from "./validator"; export type { PaginatedTransactionEntry } from "./transaction"; +export type { BankConfirmationServices, ValidatorConfirmationServices } from "./confirmation-services"; diff --git a/src/models/responses/primary-validator/config.ts b/src/models/responses/primary-validator/config.ts index 6226aea1..9f492459 100644 --- a/src/models/responses/primary-validator/config.ts +++ b/src/models/responses/primary-validator/config.ts @@ -1,4 +1,4 @@ -import type { Hex, Origin, Port, Protocol, Url, Trust, Version, NodeType } from "../constants"; +import type { Hex, Origin, Port, Protocol, Url, Version, NodeType } from "../constants"; export interface PrimaryValidatorConfigResponse { primary_validator: null; @@ -13,5 +13,5 @@ export interface PrimaryValidatorConfigResponse { root_account_file_hash: Hex; seed_block_identifier: Hex; daily_confirmation_rate: number; - node_type: NodeType; + node_type: NodeType.primaryValidator; } diff --git a/src/payment-handler.ts b/src/payment-handler.ts index bef6ef6c..74bcfa9c 100644 --- a/src/payment-handler.ts +++ b/src/payment-handler.ts @@ -50,7 +50,7 @@ export class PaymentHandler { async createTransaction(sender: Account, txs: Transaction[]) { txs = txs.map((tx) => { if (tx.memo) { - tx.memo?.trim(); + tx.memo = tx.memo.trim(); if (!/^[a-zA-Z0-9_ ]*$/.test(tx.memo)) throwError("Invalid memo", "Memo can only contain alphanumeric characters, spaces, and underscores"); if (tx.memo.length > 64) throwError("Invalid memo", "Memo cannot exceed 64 characters"); diff --git a/src/validator.ts b/src/validator.ts index c4bac38e..3e9c5b4d 100644 --- a/src/validator.ts +++ b/src/validator.ts @@ -7,6 +7,7 @@ import type { PaginatedValidatorEntry, PaginatedTransactionEntry, PaginationOptions, + ConfirmationBlock, } from "./models"; /** @@ -30,34 +31,34 @@ export abstract class Validator extends ServerNode { /** * Gets the account balance with the given account number (id). - * @param id the account number + * @param accountNumber the public key of the account */ - async getAccountBalance(id: string) { - return await super.getData(`/accounts/${id}/balance`); + async getAccountBalance(accountNumber: string) { + return await super.getData(`/accounts/${accountNumber}/balance`); } /** * Gets the balance lock of the given account. - * @param id the id of the account + * @param accountNumber the public key of the account */ - async getAccountBalanceLock(id: string) { - return await super.getData(`/accounts/${id}/balance_lock`); + async getAccountBalanceLock(accountNumber: string) { + return await super.getData(`/accounts/${accountNumber}/balance_lock`); } /** * Gets the details of given block identifier's queued transactions. - * @param id the block identifier + * @param blockId the block identifier */ - async getQueuedConfirmationBlock(id: string) { - return await super.getData(`/confirmation_blocks/${id}/queued`); + async getQueuedConfirmationBlock(blockId: string) { + return await super.getData(`/confirmation_blocks/${blockId}/queued`); } /** * Gets the details of given block identifier's valid transactions. - * @param id the block identifier + * @param blockId the block identifier */ - async getValidConfirmationBlock(id: string) { - return await super.getData(`/confirmation_blocks/${id}/valid`); + async getValidConfirmationBlock(blockId: string) { + return await super.getData(`/confirmation_blocks/${blockId}/valid`); } /** diff --git a/tests/account.test.js b/tests/account.test.js index f47249c8..85693011 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -1,4 +1,4 @@ -const { Account } = require("../"); +const { Account } = require("../dist"); describe("Account", () => { const defaultAccount = { @@ -46,6 +46,15 @@ describe("Account", () => { expect(Account.isValidPair(defaultAccount.accountNumber, defaultAccount.signingKey)).toBeFalsy(); }); + it("isValidPair doesn't throw errors", () => { + const results = [ + Account.isValidPair("asdf", "asdf"), + Account.isValidPair(defaultAccount.signingKey, "asdf"), + Account.isValidPair("asdf", defaultAccount.accountNumber), + ]; + expect(results.every((val) => typeof val === "boolean")).toBeTruthy(); + }); + it("createSignature(message)", () => { const account = createDefaultAccount(); assertAccountBasics(account); diff --git a/tests/bank.test.js b/tests/bank.test.js index 1605c4e7..482f17df 100644 --- a/tests/bank.test.js +++ b/tests/bank.test.js @@ -1,4 +1,4 @@ -const tnb = require("../"); +const tnb = require("../dist"); const nock = require("nock"); const data = require("./data/bank"); @@ -97,21 +97,22 @@ describe("Bank", () => { it("getTransactions()", async () => { const transactions = await bank.getTransactions(); expect(typeof transactions).toBe("object"); - expect(transactions.results[0]).toStrictEqual( { - "id": "443aabd9-d06b-4c4b-af3b-5a21cbee523d", - "block": { - "id": "04f407d2-35fa-4416-99f4-1ea39612a014", - "created_date": "2021-04-12T08:21:32.612926Z", - "modified_date": "2021-04-12T08:21:32.612953Z", - "balance_key": "d2af51bfc15be5af4c4120c488625b7b224f6acb84a4467a4dd8f1647a0ec8e8", - "sender": "22d0f0047b572a6acb6615f7aae646b0b96ddc58bfd54ed2775f885baeba3d6a", - "signature": "9e715ea8e5c173a87369215868c649fbe164444ea138d2fff4e4add80f4ccdb3a5ee6a529964b43a5b9fd611d504b58c52c380792ed359c036763942e003a002" - }, - "amount": 1, - "fee": "PRIMARY_VALIDATOR", - "memo": "", - "recipient": "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3" - }); + expect(transactions.results[0]).toStrictEqual({ + id: "443aabd9-d06b-4c4b-af3b-5a21cbee523d", + block: { + id: "04f407d2-35fa-4416-99f4-1ea39612a014", + created_date: "2021-04-12T08:21:32.612926Z", + modified_date: "2021-04-12T08:21:32.612953Z", + balance_key: "d2af51bfc15be5af4c4120c488625b7b224f6acb84a4467a4dd8f1647a0ec8e8", + sender: "22d0f0047b572a6acb6615f7aae646b0b96ddc58bfd54ed2775f885baeba3d6a", + signature: + "9e715ea8e5c173a87369215868c649fbe164444ea138d2fff4e4add80f4ccdb3a5ee6a529964b43a5b9fd611d504b58c52c380792ed359c036763942e003a002", + }, + amount: 1, + fee: "PRIMARY_VALIDATOR", + memo: "", + recipient: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + }); }); it("getBanks()", async () => { @@ -196,7 +197,7 @@ describe("Bank", () => { "fakeBalanceLock", [{ amount: 1, recipient: "fakeAccountNumber" }], new tnb.Account(), - 'Memo' + "Memo" ); expect(typeof res).toBe("object"); expect(res).toStrictEqual({ diff --git a/tests/confirmationValidator.test.js b/tests/confirmationValidator.test.js new file mode 100644 index 00000000..f93ec4ee --- /dev/null +++ b/tests/confirmationValidator.test.js @@ -0,0 +1,303 @@ +const nock = require("nock"); + +const cvData = require("./data/confirmationValidator"); +const { Account, ConfirmationValidator } = require("../dist"); + +describe("", () => { + const cv = new ConfirmationValidator("http://3.101.33.24", { defaultPagination: { limit: 20, offset: 0 } }); + const cvNID = "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729"; + + const accountNumber = "330cf5f7a06b7915adbc1a26228bf1fa6729aff9133259916c393383cf9f6d7d"; + const bankNID = "a0fa98ce5c4974b6fc2333e284133da5095adc49c143c3f2cdadfa502b13a8bd"; + const validatorNID = "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc"; + const confirmationBlockID = "f0b89767914480ebd12301e11580b08ca2a53cf3f14adf3d2afd7b3e5e7e6d74"; + + beforeAll(() => { + nock("http://3.101.33.24") + .get(`/accounts/${accountNumber}/balance`) + .reply(200, cvData.accountBalance) + .get(`/accounts/${accountNumber}/balance_lock`) + .reply(200, cvData.accountBalanceLock) + .get("/accounts") + .query({ limit: 20, offset: 0 }) + .reply(200, cvData.accounts) + .get(`/banks/${bankNID}`) + .reply(200, cvData.bank) + .get("/banks") + .query({ limit: 20, offset: 0 }) + .reply(200, cvData.banks) + .get("/clean") + .reply(200, cvData.clean.get) + .post("/clean") + .reply(200, cvData.clean.start) + .post("/clean") + .reply(200, cvData.clean.stop) + .get("/config") + .reply(200, cvData.config) + .get("/bank_confirmation_services") + .query({ limit: 20, offset: 0 }) + .reply(200, cvData.confirmationServices) + .get(`/confirmation_blocks/${confirmationBlockID}/valid`) + .reply(200, cvData.confirmationBlock.valid) + .get("/crawl") + .reply(200, cvData.crawl.get) + .post("/crawl") + .reply(200, cvData.crawl.start) + .post("/crawl") + .reply(200, cvData.crawl.stop) + .get(`/validators/${validatorNID}`) + .reply(200, cvData.validator) + .get("/validators") + .query({ limit: 20, offset: 0 }) + .reply(200, cvData.validators); + }); + + afterAll(() => nock.cleanAll()); + + it("getAccountBalance(accountNumber: string)", async () => { + const balance = await cv.getAccountBalance(accountNumber); + + expect(balance).toStrictEqual({ balance: 5004 }); + }); + + it("getAccountBalanceLock(accountNumber: string)", async () => { + const balanceLock = await cv.getAccountBalanceLock(accountNumber); + + expect(balanceLock).toStrictEqual({ + balance_lock: "330cf5f7a06b7915adbc1a26228bf1fa6729aff9133259916c393383cf9f6d7d", + }); + }); + + it("getAccounts(options: Partial = {})", async () => { + const accounts = await cv.getAccounts(); + + expect(accounts).toStrictEqual(cvData.accounts); + expect(accounts.results.length).toBeLessThanOrEqual(20); + }); + + it("getBank(nodeIdentifier: string)", async () => { + const specifiedBank = await cv.getBank(bankNID); + + expect(specifiedBank.node_identifier).toBe(bankNID); + expect(specifiedBank).toStrictEqual({ + account_number: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + ip_address: "54.177.121.3", + node_identifier: "a0fa98ce5c4974b6fc2333e284133da5095adc49c143c3f2cdadfa502b13a8bd", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: "2021-07-23T22:33:32.451310Z", + trust: "0.00", + }); + }); + + it("getBanks(options: Partial = {})", async () => { + const connectedBanks = await cv.getBanks(); + + expect(connectedBanks.results.length).toBeLessThanOrEqual(20); + expect(connectedBanks).toStrictEqual({ + count: 2, + next: null, + previous: null, + results: [ + { + account_number: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + ip_address: "54.177.121.3", + node_identifier: "a0fa98ce5c4974b6fc2333e284133da5095adc49c143c3f2cdadfa502b13a8bd", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: null, + trust: "0.00", + }, + { + account_number: "a7ef465b163bcafae5b2a29d879aa1c314761b3bcfe8fb255cf960ddf226b2c3", + ip_address: "13.244.248.94", + node_identifier: "ed0c31cc8b3e1cb5200bf2d9bad96434b4c65529503e2e2427efb3a453eebd5d", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: null, + trust: "0.00", + }, + ], + }); + }); + + it("getCleanStatus()", async () => { + const clean = await cv.getCleanStatus(); + + expect(clean.clean_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(["cleaning", "not_cleaning", null].includes(clean.clean_status)).toBeTruthy; + expect(clean.ip_address).toBe("3.101.33.24"); + expect(clean.port).toBe(80); + expect(clean.protocol).toBe("http"); + }); + + it("startClean()", async () => { + const account = new Account(validatorNID); + const clean = await cv.startClean(account); + + expect(clean.clean_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(clean.clean_status).toBe("cleaning"); + expect(clean.ip_address).toBe("3.101.33.24"); + expect(clean.port).toBe(80); + expect(clean.protocol).toBe("http"); + }); + + it("stopClean()", async () => { + const account = new Account(validatorNID); + const clean = await cv.stopClean(account); + + expect(clean.clean_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(["stop_requested", "not_cleaning", null].includes(clean.clean_status)).toBeTruthy; + expect(clean.ip_address).toBe("3.101.33.24"); + expect(clean.port).toBe(80); + expect(clean.protocol).toBe("http"); + }); + + it("getConfig()", async () => { + const config = await cv.getConfig(); + + expect(config.ip_address).toBe("3.101.33.24"); + expect(config.node_identifier).toBe(cvNID); + expect(config).toStrictEqual({ + primary_validator: { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + account_number: "d32e26852fa5882c3997e7d48e07accf4c185699d2e832898a63c93862a01a4a", + ip_address: "3.101.33.24", + node_identifier: "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://3.101.33.24:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + node_type: "CONFIRMATION_VALIDATOR", + }); + }); + + it("getBankConfirmationServices()", async () => { + const confirmationServices = await cv.getBankConfirmationServices(); + + expect(confirmationServices.results.length).toBeLessThanOrEqual(20); + expect(confirmationServices).toStrictEqual(cvData.confirmationServices); + }); + + it("getValidConfirmationBlock()", async () => { + const block = await cv.getValidConfirmationBlock(confirmationBlockID); + + expect(block.node_identifier).toBe(cvNID); + expect(block.message.block_identifier).toBe(confirmationBlockID); + expect(block).toStrictEqual(cvData.confirmationBlock.valid); + }); + + it("getCrawlStatus()", async () => { + const crawl = await cv.getCrawlStatus(); + + expect(crawl.crawl_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(["crawling", "not_crawling", null].includes(crawl.crawl_status)).toBeTruthy; + expect(crawl.ip_address).toBe("3.101.33.24"); + expect(crawl.port).toBe(80); + expect(crawl.protocol).toBe("http"); + }); + + it("startCrawl()", async () => { + const account = new Account(validatorNID); + const crawl = await cv.startCrawl(account); + + expect(crawl.crawl_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(crawl.crawl_status).toBe("crawling"); + expect(crawl.ip_address).toBe("3.101.33.24"); + expect(crawl.port).toBe(80); + expect(crawl.protocol).toBe("http"); + }); + + it("stopCrawl()", async () => { + const account = new Account(validatorNID); + const crawl = await cv.stopCrawl(account); + + expect(crawl.crawl_last_completed).toBe("2021-03-21 11:15:07.923380+00:00"); + expect(["stop_requested", "not_crawling", null].includes(crawl.crawl_status)).toBeTruthy; + expect(crawl.ip_address).toBe("3.101.33.24"); + expect(crawl.port).toBe(80); + expect(crawl.protocol).toBe("http"); + }); + + it("getValidator()", async () => { + const validatorConfig = await cv.getValidator(validatorNID); + + expect(validatorConfig.node_identifier).toBe(validatorNID); + expect(validatorConfig).toStrictEqual({ + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }); + }); + + it("getValidators()", async () => { + const validators = await cv.getValidators({ limit: 20, offset: 0 }); + + expect(validators).toStrictEqual({ + count: 2, + next: null, + previous: null, + results: [ + { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + { + account_number: "d32e26852fa5882c3997e7d48e07accf4c185699d2e832898a63c93862a01a4a", + ip_address: "3.101.33.24", + node_identifier: "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://3.101.33.24:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + ], + }); + }); +}); diff --git a/tests/data/confirmationValidator/accountBalance.js b/tests/data/confirmationValidator/accountBalance.js new file mode 100644 index 00000000..faed8fc4 --- /dev/null +++ b/tests/data/confirmationValidator/accountBalance.js @@ -0,0 +1 @@ +module.exports = { balance: 5004 }; diff --git a/tests/data/confirmationValidator/accountBalanceLock.js b/tests/data/confirmationValidator/accountBalanceLock.js new file mode 100644 index 00000000..a0c70c2a --- /dev/null +++ b/tests/data/confirmationValidator/accountBalanceLock.js @@ -0,0 +1,3 @@ +module.exports = { + balance_lock: "330cf5f7a06b7915adbc1a26228bf1fa6729aff9133259916c393383cf9f6d7d", +}; diff --git a/tests/data/confirmationValidator/accounts.js b/tests/data/confirmationValidator/accounts.js new file mode 100644 index 00000000..d8aa4886 --- /dev/null +++ b/tests/data/confirmationValidator/accounts.js @@ -0,0 +1,127 @@ +module.exports = { + count: 817, + next: "http://3.101.33.24/accounts?limit=20&offset=20", + previous: null, + results: [ + { + id: "fb55be41-a98c-4d6f-91db-3e4cf52d0843", + account_number: "3b993aec5e6bac032dbe3f106dd0a305fb8ed55b10369d9760b40c0818235be1", + balance: 4, + balance_lock: "f53e35181c80b1c9cd93b89cf470c2d2ccba079eed75e8114f00a5af8943603f", + }, + { + id: "6eb24626-96f1-410d-83b5-12d73583ad9f", + account_number: "9bfa37627e2dba0ae48165b219e76ceaba036b3db8e84108af73a1cce01fad35", + balance: 6, + balance_lock: "749f6faa4eeeda50f51334e903a1eaae084435d53d2a85fb0993a518fef27273", + }, + { + id: "20c05fd1-b73c-4ca4-ae99-91bf70c2eede", + account_number: "153f6b4f1fd60e004512213296f178195fa8192b0ff2d33e97987c6aac175811", + balance: 58807, + balance_lock: "153f6b4f1fd60e004512213296f178195fa8192b0ff2d33e97987c6aac175811", + }, + { + id: "95e33842-d5ad-4b95-b7de-5fa2718e4547", + account_number: "330cf5f7a06b7915adbc1a26228bf1fa6729aff9133259916c393383cf9f6d7d", + balance: 5004, + balance_lock: "330cf5f7a06b7915adbc1a26228bf1fa6729aff9133259916c393383cf9f6d7d", + }, + { + id: "a308d16d-7db8-4bec-b0c9-2060896d218d", + account_number: "27d91d9b42b3430a6dbf0ba9d220162a2b494fafc0b5534d14f7dfd2bb761a92", + balance: 2504, + balance_lock: "27d91d9b42b3430a6dbf0ba9d220162a2b494fafc0b5534d14f7dfd2bb761a92", + }, + { + id: "d2062672-fd5c-4fe3-9cc6-64fc0004f0e8", + account_number: "5415528f1f9ffc62962db65797604f93d2adb152aed57c782e0391ebc3caec76", + balance: 39204, + balance_lock: "5415528f1f9ffc62962db65797604f93d2adb152aed57c782e0391ebc3caec76", + }, + { + id: "d3a38aea-e0b0-4cf7-869b-d266ac2cebe8", + account_number: "b004c0c1aa2e6596d545f93e7d4d03c525b96c8bd69b79bdcb809e90dcb01b7a", + balance: 10009, + balance_lock: "b004c0c1aa2e6596d545f93e7d4d03c525b96c8bd69b79bdcb809e90dcb01b7a", + }, + { + id: "1c018fbf-8148-4755-b670-ef8ebd637503", + account_number: "dd0a2bfb303d051eb7e14554de3e517249a409b278afcbad30e961cec316a8ae", + balance: 5010, + balance_lock: "dd0a2bfb303d051eb7e14554de3e517249a409b278afcbad30e961cec316a8ae", + }, + { + id: "0fcba8da-a08e-412a-945e-b966fa8dcc4d", + account_number: "965ef39eda2db7e91d2c937abdf1c5f6b9c49d22954ed80ea9e743ca1531123e", + balance: 10, + balance_lock: "40840fea9c738693bedd0a76deb82a821f08116be31aa2202fbdc4998a2abe0a", + }, + { + id: "88c447b8-dd13-4ac4-b7de-e3179c99d3fa", + account_number: "e5c2ff3c4f6886fd7cd87002d83c6aabe48e585ce38026c0df6ea7c517e0f7a4", + balance: 1510, + balance_lock: "e5c2ff3c4f6886fd7cd87002d83c6aabe48e585ce38026c0df6ea7c517e0f7a4", + }, + { + id: "0ce45c95-9c90-49ab-ad8d-30a9d41b1499", + account_number: "fdae688d9e879ce89f164c6eb793d5a3c9e714bc6962a671275c0e2e1e6ea599", + balance: 196000, + balance_lock: "fdae688d9e879ce89f164c6eb793d5a3c9e714bc6962a671275c0e2e1e6ea599", + }, + { + id: "82f56541-c2a6-49ec-a3fc-155b69a20328", + account_number: "e68952859eaf8d68f9ebb6f23e944ac00380a8a93c82b5363cb845ffe055a195", + balance: 27510, + balance_lock: "e68952859eaf8d68f9ebb6f23e944ac00380a8a93c82b5363cb845ffe055a195", + }, + { + id: "7a2e8dcc-9b90-4879-b1dd-45ef97eaee69", + account_number: "75f6e7520352023f3014af04de7641ff808b4e5c20b3214436442d199b50c1dc", + balance: 25004, + balance_lock: "75f6e7520352023f3014af04de7641ff808b4e5c20b3214436442d199b50c1dc", + }, + { + id: "014c0057-4496-41e7-b555-9cc943c7a504", + account_number: "7972e740622fe935bd7ce8b1ad3f0a0034888adbebf6bcc9e60d9d640cfc84db", + balance: 10220, + balance_lock: "7972e740622fe935bd7ce8b1ad3f0a0034888adbebf6bcc9e60d9d640cfc84db", + }, + { + id: "6449720a-4095-47eb-ad46-03a0323d99ce", + account_number: "b6bb041711d29581a543571991a484fd9765f0b14e927fa19057aa182d0e8fab", + balance: 1004, + balance_lock: "b6bb041711d29581a543571991a484fd9765f0b14e927fa19057aa182d0e8fab", + }, + { + id: "0dc64754-e621-469f-a484-319612c0126f", + account_number: "d9b57a556016745c31f9fa299972807556e5327a2f7460e9bc33b8c90d984452", + balance: 5004, + balance_lock: "d9b57a556016745c31f9fa299972807556e5327a2f7460e9bc33b8c90d984452", + }, + { + id: "ea1e5272-aca0-49b1-a271-db78000b4adf", + account_number: "e4c4183ff27359d133c7ce8e8847e3fc9a67d9e0be2af3a92b5afc17815e4c2c", + balance: 1204, + balance_lock: "e4c4183ff27359d133c7ce8e8847e3fc9a67d9e0be2af3a92b5afc17815e4c2c", + }, + { + id: "d48feb03-c542-45ca-b0c1-3745a85b1b89", + account_number: "ff0be6e480f67e3130d32e9fd802f561d1bc4ba45c0b604640b0e7523f25e5ce", + balance: 804, + balance_lock: "ff0be6e480f67e3130d32e9fd802f561d1bc4ba45c0b604640b0e7523f25e5ce", + }, + { + id: "2aaea711-2b12-4dae-ab06-5a9e9791267f", + account_number: "0946e89dc9343691c63dc42f74f556bb4ea65170edbaee6831eb91e34d81b65d", + balance: 50005, + balance_lock: "0946e89dc9343691c63dc42f74f556bb4ea65170edbaee6831eb91e34d81b65d", + }, + { + id: "b3fdfe6d-97a6-409c-96d3-f7f7408b0eaa", + account_number: "165acdbb34976743c1ed6bd674e63631b861df4420555da8f8a60dc72aef4d2c", + balance: 1003, + balance_lock: "165acdbb34976743c1ed6bd674e63631b861df4420555da8f8a60dc72aef4d2c", + }, + ], +}; diff --git a/tests/data/confirmationValidator/bank.js b/tests/data/confirmationValidator/bank.js new file mode 100644 index 00000000..c349d01b --- /dev/null +++ b/tests/data/confirmationValidator/bank.js @@ -0,0 +1,11 @@ +module.exports = { + account_number: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + ip_address: "54.177.121.3", + node_identifier: "a0fa98ce5c4974b6fc2333e284133da5095adc49c143c3f2cdadfa502b13a8bd", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: "2021-07-23T22:33:32.451310Z", + trust: "0.00", +}; diff --git a/tests/data/confirmationValidator/banks.js b/tests/data/confirmationValidator/banks.js new file mode 100644 index 00000000..8e39289c --- /dev/null +++ b/tests/data/confirmationValidator/banks.js @@ -0,0 +1,29 @@ +module.exports = { + count: 2, + next: null, + previous: null, + results: [ + { + account_number: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + ip_address: "54.177.121.3", + node_identifier: "a0fa98ce5c4974b6fc2333e284133da5095adc49c143c3f2cdadfa502b13a8bd", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: null, + trust: "0.00", + }, + { + account_number: "a7ef465b163bcafae5b2a29d879aa1c314761b3bcfe8fb255cf960ddf226b2c3", + ip_address: "13.244.248.94", + node_identifier: "ed0c31cc8b3e1cb5200bf2d9bad96434b4c65529503e2e2427efb3a453eebd5d", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + confirmation_expiration: null, + trust: "0.00", + }, + ], +}; diff --git a/tests/data/confirmationValidator/clean.js b/tests/data/confirmationValidator/clean.js new file mode 100644 index 00000000..b2509040 --- /dev/null +++ b/tests/data/confirmationValidator/clean.js @@ -0,0 +1,23 @@ +module.exports = { + get: { + clean_last_completed: "2021-03-21 11:15:07.923380+00:00", + clean_status: "not_cleaning", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, + start: { + clean_last_completed: "2021-03-21 11:15:07.923380+00:00", + clean_status: "cleaning", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, + stop: { + clean_last_completed: "2021-03-21 11:15:07.923380+00:00", + clean_status: "stop_requested", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, +}; diff --git a/tests/data/confirmationValidator/config.js b/tests/data/confirmationValidator/config.js new file mode 100644 index 00000000..62de1320 --- /dev/null +++ b/tests/data/confirmationValidator/config.js @@ -0,0 +1,28 @@ +module.exports = { + primary_validator: { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + account_number: "d32e26852fa5882c3997e7d48e07accf4c185699d2e832898a63c93862a01a4a", + ip_address: "3.101.33.24", + node_identifier: "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://3.101.33.24:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + node_type: "CONFIRMATION_VALIDATOR", +}; diff --git a/tests/data/confirmationValidator/confirmationBlock.js b/tests/data/confirmationValidator/confirmationBlock.js new file mode 100644 index 00000000..cb934756 --- /dev/null +++ b/tests/data/confirmationValidator/confirmationBlock.js @@ -0,0 +1,54 @@ +module.exports = { + valid: { + message: { + block: { + account_number: "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f", + message: { + balance_key: "477476a4d1ed015bc8e4e4bc9e164048d7d13212568093969ebd37070ce97f6e", + txs: [ + { + amount: 1, + fee: "PRIMARY_VALIDATOR", + recipient: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + }, + { + amount: 1, + memo: "Yo", + recipient: "b6e21072b6ba2eae6f78bc3ade17f6a561fa4582d5494a5120617f2027d38797", + }, + { + amount: 1, + fee: "BANK", + recipient: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + }, + ], + }, + signature: + "6293452496c618d831b7ddcf5443b9f92fa06133a5c0c2fdade0dca438dbc2bcdc3112e05dee7c40c00064dc904f91a05b5034d11a49b2a4e49097b1d6c4060d", + }, + block_identifier: "f0b89767914480ebd12301e11580b08ca2a53cf3f14adf3d2afd7b3e5e7e6d74", + updated_balances: [ + { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + balance: 7, + }, + { + account_number: "a37e2836805975f334108b55523634c995bd2a4db610062f404510617e83126f", + balance: 408169, + balance_lock: "2d6eb919aa0b5476da5a0909d25c00298d276ba502e2f222064062bda034dfa1", + }, + { + account_number: "b6e21072b6ba2eae6f78bc3ade17f6a561fa4582d5494a5120617f2027d38797", + balance: 11837, + }, + { + account_number: "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6", + balance: 1, + }, + ], + }, + node_identifier: "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729", + signature: + "3141f41a558c06b35ac9605588c6dbe1e3c8cd8cde5fd8bf507df5fa0a202f88140043a924508c528c6d6015daebf4cb6088cca857c5582c69d25e3a65607b0a", + }, +}; diff --git a/tests/data/confirmationValidator/confirmationServices.js b/tests/data/confirmationValidator/confirmationServices.js new file mode 100644 index 00000000..181d8e18 --- /dev/null +++ b/tests/data/confirmationValidator/confirmationServices.js @@ -0,0 +1,31 @@ +module.exports = { + count: 3, + next: null, + previous: null, + results: [ + { + id: "2dfcef62-e8c8-4bfa-88ca-60413bc117bc", + created_date: "2021-04-11T22:33:32.454200Z", + modified_date: "2021-04-11T22:33:32.454252Z", + end: "2021-04-15T22:33:32.451310Z", + start: "2021-04-11T22:33:32.451310Z", + bank: "f041e603-ae46-4fa4-811e-2055034f467d", + }, + { + id: "94feef27-ab2e-4b24-8b2f-e385fdcb23b1", + created_date: "2021-04-12T00:33:52.946880Z", + modified_date: "2021-04-12T00:33:52.946907Z", + end: "2021-04-24T22:33:32.451310Z", + start: "2021-04-15T22:33:32.451310Z", + bank: "f041e603-ae46-4fa4-811e-2055034f467d", + }, + { + id: "85478b67-4ea7-4c35-bf6f-cd65c25ece86", + created_date: "2021-04-16T02:36:43.606329Z", + modified_date: "2021-04-16T02:36:43.606355Z", + end: "2021-07-23T22:33:32.451310Z", + start: "2021-04-24T22:33:32.451310Z", + bank: "f041e603-ae46-4fa4-811e-2055034f467d", + }, + ], +}; diff --git a/tests/data/confirmationValidator/crawl.js b/tests/data/confirmationValidator/crawl.js new file mode 100644 index 00000000..7429a0d2 --- /dev/null +++ b/tests/data/confirmationValidator/crawl.js @@ -0,0 +1,23 @@ +module.exports = { + get: { + crawl_last_completed: "2021-03-21 11:15:07.923380+00:00", + crawl_status: "not_crawling", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, + start: { + crawl_last_completed: "2021-03-21 11:15:07.923380+00:00", + crawl_status: "crawling", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, + stop: { + crawl_last_completed: "2021-03-21 11:15:07.923380+00:00", + crawl_status: "stop_requested", + ip_address: "3.101.33.24", + port: 80, + protocol: "http", + }, +}; diff --git a/tests/data/confirmationValidator/index.js b/tests/data/confirmationValidator/index.js new file mode 100644 index 00000000..b6ed56a9 --- /dev/null +++ b/tests/data/confirmationValidator/index.js @@ -0,0 +1,27 @@ +const accounts = require("./accounts"); +const accountBalance = require("./accountBalance"); +const accountBalanceLock = require("./accountBalanceLock.js"); +const bank = require("./bank"); +const banks = require("./banks"); +const clean = require("./clean"); +const config = require("./config"); +const confirmationBlock = require("./confirmationBlock"); +const confirmationServices = require("./confirmationServices"); +const crawl = require("./crawl"); +const validator = require("./validator"); +const validators = require("./validators"); + +module.exports = { + accounts, + accountBalance, + accountBalanceLock, + bank, + banks, + clean, + config, + confirmationBlock, + confirmationServices, + crawl, + validator, + validators, +}; diff --git a/tests/data/confirmationValidator/validator.js b/tests/data/confirmationValidator/validator.js new file mode 100644 index 00000000..48115217 --- /dev/null +++ b/tests/data/confirmationValidator/validator.js @@ -0,0 +1,14 @@ +module.exports = { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", +}; diff --git a/tests/data/confirmationValidator/validators.js b/tests/data/confirmationValidator/validators.js new file mode 100644 index 00000000..2adb8d31 --- /dev/null +++ b/tests/data/confirmationValidator/validators.js @@ -0,0 +1,35 @@ +module.exports = { + count: 2, + next: null, + previous: null, + results: [ + { + account_number: "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3", + ip_address: "54.219.183.128", + node_identifier: "9375feb25085c6f2a58640404e7c16582e210a6a12717c8d3d5307f750c861fc", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://54.219.183.128:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + { + account_number: "d32e26852fa5882c3997e7d48e07accf4c185699d2e832898a63c93862a01a4a", + ip_address: "3.101.33.24", + node_identifier: "f4e756be5067cc974b13f08ef3e47aef298cb767807d97e320c46f2a815d6729", + port: 80, + protocol: "http", + version: "v1.0", + default_transaction_fee: 1, + root_account_file: "http://3.101.33.24:80/media/root_account_file.json", + root_account_file_hash: "be00d11e661cbb9158e81a9a34a67738bd662ccced1ab5fc93ee775bc1841683", + seed_block_identifier: "", + daily_confirmation_rate: 1, + trust: "100.00", + }, + ], +}; diff --git a/tests/paymentHandler.test.js b/tests/paymentHandler.test.js index bf5353fb..16ed5101 100644 --- a/tests/paymentHandler.test.js +++ b/tests/paymentHandler.test.js @@ -1,4 +1,4 @@ -const tnb = require("../"); +const tnb = require("../dist"); describe("PaymentHandler", () => { const bank = new tnb.Bank("http://54.177.121.3"); @@ -6,13 +6,13 @@ describe("PaymentHandler", () => { it("constructor()", async () => { await paymentHandler.init(); - const pv = await bank.getBankPV() + const pv = await bank.getBankPV(); expect(paymentHandler.bank.url).toBe(bank.url); expect(paymentHandler.primaryValidator.url).toBe(pv.url); }); - it("sender: Account, txs: Transaction[]", async () => { - const pv = await bank.getBankPV() + it("createTransaction(sender: Account, txs: Transaction[])", async () => { + const pv = await bank.getBankPV(); paymentHandler.init(); const sender = new tnb.Account(); const recipient = new tnb.Account(); @@ -20,7 +20,7 @@ describe("PaymentHandler", () => { const txs = [ { amount: 100, - memo: 'hi', + memo: "hi", recipient: recipient.accountNumberHex, }, ]; @@ -28,7 +28,7 @@ describe("PaymentHandler", () => { const transaction = await paymentHandler.createTransaction(sender, txs); expect(transaction.sender).toBe(sender); expect(transaction.balanceLock).toBe((await pv.getAccountBalanceLock(sender.accountNumberHex)).balance_lock); - expect(transaction.transactions[0].amount).toBe(100) - expect(transaction.transactions[0].memo).toBe('hi') + expect(transaction.transactions[0].amount).toBe(100); + expect(transaction.transactions[0].memo).toBe("hi"); }); }); diff --git a/tests/primaryValidator.test.js b/tests/primaryValidator.test.js index 31c5b7e2..d058bfcf 100644 --- a/tests/primaryValidator.test.js +++ b/tests/primaryValidator.test.js @@ -1,4 +1,4 @@ -const tnb = require("../"); +const tnb = require("../dist"); const nock = require("nock"); const data = require("./data/primaryValidator");