From ad5ed54efc1f09b0ec2525fc0255ab39ab1df61d Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 12 Apr 2021 14:33:51 +0530 Subject: [PATCH 1/2] feat: Added support for memo (#140) * Add memo * Memo validation * Fix memo * update docs and tests * Add memo tests * Remove console.log --- docs/account-payment-handler.md | 5 +- docs/primary-validator.md | 1 + src/account-payment-handler.ts | 4 +- src/models/transaction.ts | 3 +- src/payment-handler.ts | 15 +- src/utils/transfer-details.ts | 5 +- tests/bank.test.js | 33 +- tests/data/bank/bank_transactions.js | 462 +++++++++------------------ tests/paymentHandler.test.js | 17 +- 9 files changed, 207 insertions(+), 338 deletions(-) diff --git a/docs/account-payment-handler.md b/docs/account-payment-handler.md index 7c798d7e..d0c1c006 100644 --- a/docs/account-payment-handler.md +++ b/docs/account-payment-handler.md @@ -29,7 +29,8 @@ await paymentHandler.init(); const recipientAccount = new Account("fakeSigningKey"); const amount = 1000; -await sendCoins(recipientAccount, 1000); +// You can use this method to send memos as well +await sendCoins(recipientAccount, amount, "memo"); ``` ## Send Bulk Payments @@ -58,6 +59,7 @@ await paymentHandler.init(); /* Note The sender cannot be listed as a recipient A recipient cannot be listed more than once + You must follow this order of the fields */ const txs = [ @@ -67,6 +69,7 @@ const txs = [ }, { amount: 100, + memo: "hi", recipient: "fakeAccountNumber2", }, { diff --git a/docs/primary-validator.md b/docs/primary-validator.md index 00fa16cc..e59885a1 100644 --- a/docs/primary-validator.md +++ b/docs/primary-validator.md @@ -19,6 +19,7 @@ const transactions = [ }, { amount: 1, + memo: "hi", recipient: "fakeAccountNumber", }, { diff --git a/src/account-payment-handler.ts b/src/account-payment-handler.ts index 99743ac9..6c10434d 100644 --- a/src/account-payment-handler.ts +++ b/src/account-payment-handler.ts @@ -16,8 +16,8 @@ export class AccountPaymentHandler { await this.client.init(); } - async sendCoins(recipient: Account | string, amount: number) { - await this.client.sendCoins(new TransferDetails(this.account, recipient, amount)); + async sendCoins(recipient: Account | string, amount: number, memo = "") { + await this.client.sendCoins(new TransferDetails(this.account, recipient, amount, memo)); } async sendBulkTransactions(transactions: Transaction[]) { diff --git a/src/models/transaction.ts b/src/models/transaction.ts index 764439a2..1564fc0e 100644 --- a/src/models/transaction.ts +++ b/src/models/transaction.ts @@ -1,6 +1,7 @@ /** The model for thenewboston transactions. */ export interface Transaction { amount: number; - recipient: string; fee?: string; + memo?: string; + recipient: string; } diff --git a/src/payment-handler.ts b/src/payment-handler.ts index 0eb0a697..bef6ef6c 100644 --- a/src/payment-handler.ts +++ b/src/payment-handler.ts @@ -48,6 +48,17 @@ export class PaymentHandler { * */ async createTransaction(sender: Account, txs: Transaction[]) { + txs = txs.map((tx) => { + if (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"); + } + if (tx.memo === "") delete tx.memo; + return tx; + }); + const { balance_lock: balanceLock } = await this.primaryValidator!.getAccountBalanceLock( sender.accountNumberHex ).catch((err) => @@ -81,9 +92,9 @@ export class PaymentHandler { * Sends a specific amount of coins to a given account from the sender. * @param transferDetails The object with transfer details like sender, recipient and amount */ - async sendCoins({ sender, recipient, amount }: TransferDetails) { + async sendCoins({ sender, recipient, amount, memo = "" }: TransferDetails) { const recipientAccount = typeof recipient === "string" ? recipient : recipient.accountNumberHex; - const transaction = await this.createTransaction(sender, [{ recipient: recipientAccount, amount }]); + const transaction = await this.createTransaction(sender, [{ amount, memo, recipient: recipientAccount }]); await this.broadcastTransaction(transaction); } diff --git a/src/utils/transfer-details.ts b/src/utils/transfer-details.ts index 77411084..643e5b97 100644 --- a/src/utils/transfer-details.ts +++ b/src/utils/transfer-details.ts @@ -1,13 +1,16 @@ import type { Account } from "../account"; +import { throwError } from "./throw-error"; export class TransferDetails { public sender: Account; public recipient: Account | string; public amount: number; + public memo: string; - constructor(sender: Account, recipient: Account | string, amount: number) { + constructor(sender: Account, recipient: Account | string, amount: number, memo: string) { this.sender = sender; this.recipient = recipient; this.amount = amount; + this.memo = memo; } } diff --git a/tests/bank.test.js b/tests/bank.test.js index 8533e283..1605c4e7 100644 --- a/tests/bank.test.js +++ b/tests/bank.test.js @@ -97,21 +97,21 @@ describe("Bank", () => { it("getTransactions()", async () => { const transactions = await bank.getTransactions(); expect(typeof transactions).toBe("object"); - expect(transactions.results[0]).toStrictEqual({ - id: "a486f2ca-2431-455a-bdb2-6dccbf7e1ace", - block: { - id: "30b5bafb-139c-43ad-a03f-8c04e77c35a2", - created_date: "2021-03-30T03:38:45.827858Z", - modified_date: "2021-03-30T03:38:45.827884Z", - balance_key: "43731d388391f5a8b046066a4a3cf6164b16192a99fcd00bdeb627a98d31016e", - sender: "7c2d3b7774b494a496c00d175bd68d04280acb3fd1bac5dc46cae2b67d7f5a4f", - signature: - "d8b6d6f56149519d26ebb901702c078a0b75b4f153a84655f1a1b161c52aff65086c3a0195e91ee8504790cbc699d7f8189c680aa89d609b5d12101d7190d407", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }); + 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 () => { @@ -195,7 +195,8 @@ describe("Bank", () => { const res = await bank.addBlocks( "fakeBalanceLock", [{ amount: 1, recipient: "fakeAccountNumber" }], - new tnb.Account() + new tnb.Account(), + 'Memo' ); expect(typeof res).toBe("object"); expect(res).toStrictEqual({ diff --git a/tests/data/bank/bank_transactions.js b/tests/data/bank/bank_transactions.js index 3b7ee5ae..c58cd8ae 100644 --- a/tests/data/bank/bank_transactions.js +++ b/tests/data/bank/bank_transactions.js @@ -1,307 +1,157 @@ module.exports = { - count: 2284, - next: "http://13.57.215.62/bank_transactions?limit=20&offset=20", - previous: null, - results: [ - { - id: "a486f2ca-2431-455a-bdb2-6dccbf7e1ace", - block: { - id: "30b5bafb-139c-43ad-a03f-8c04e77c35a2", - created_date: "2021-03-30T03:38:45.827858Z", - modified_date: "2021-03-30T03:38:45.827884Z", - balance_key: "43731d388391f5a8b046066a4a3cf6164b16192a99fcd00bdeb627a98d31016e", - sender: "7c2d3b7774b494a496c00d175bd68d04280acb3fd1bac5dc46cae2b67d7f5a4f", - signature: - "d8b6d6f56149519d26ebb901702c078a0b75b4f153a84655f1a1b161c52aff65086c3a0195e91ee8504790cbc699d7f8189c680aa89d609b5d12101d7190d407", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "c4177fbb-0325-41cc-aea9-b227d7661f4d", - block: { - id: "30b5bafb-139c-43ad-a03f-8c04e77c35a2", - created_date: "2021-03-30T03:38:45.827858Z", - modified_date: "2021-03-30T03:38:45.827884Z", - balance_key: "43731d388391f5a8b046066a4a3cf6164b16192a99fcd00bdeb627a98d31016e", - sender: "7c2d3b7774b494a496c00d175bd68d04280acb3fd1bac5dc46cae2b67d7f5a4f", - signature: - "d8b6d6f56149519d26ebb901702c078a0b75b4f153a84655f1a1b161c52aff65086c3a0195e91ee8504790cbc699d7f8189c680aa89d609b5d12101d7190d407", - }, - amount: 4000, - fee: "", - recipient: "c2315f0f5f21630941ab47770911aeea5b0e65c419e1d535075c255a69a9e7d0", - }, - { - id: "913457ab-8b39-4543-ba8b-fa1a31d4584e", - block: { - id: "30b5bafb-139c-43ad-a03f-8c04e77c35a2", - created_date: "2021-03-30T03:38:45.827858Z", - modified_date: "2021-03-30T03:38:45.827884Z", - balance_key: "43731d388391f5a8b046066a4a3cf6164b16192a99fcd00bdeb627a98d31016e", - sender: "7c2d3b7774b494a496c00d175bd68d04280acb3fd1bac5dc46cae2b67d7f5a4f", - signature: - "d8b6d6f56149519d26ebb901702c078a0b75b4f153a84655f1a1b161c52aff65086c3a0195e91ee8504790cbc699d7f8189c680aa89d609b5d12101d7190d407", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "e5415495-608c-4e0f-8da2-9992c39a3f3d", - block: { - id: "4817c2a9-fa24-4c63-9eae-1df5a44b4654", - created_date: "2021-03-29T19:49:22.526342Z", - modified_date: "2021-03-29T19:49:22.526367Z", - balance_key: "8b3004ad8637a8c42e66f92f68c576a704ce3eaa55fd0f22ae76fee5a1fe7c1a", - sender: "431f89d714dc2d748c899b14c725a52c2b5560c2b8e2bb2bb691f41a155c3a2e", - signature: - "f653376751d72bd1ea41c147a7a331d73b7d10d795661e2a93c08c2e022d58d04117fde1c0e1b22e3f462fed6c6172047e823328d692afb39d70fd4e3f3e990a", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "ecbf52cd-a192-4646-adaf-5f099deda7aa", - block: { - id: "4817c2a9-fa24-4c63-9eae-1df5a44b4654", - created_date: "2021-03-29T19:49:22.526342Z", - modified_date: "2021-03-29T19:49:22.526367Z", - balance_key: "8b3004ad8637a8c42e66f92f68c576a704ce3eaa55fd0f22ae76fee5a1fe7c1a", - sender: "431f89d714dc2d748c899b14c725a52c2b5560c2b8e2bb2bb691f41a155c3a2e", - signature: - "f653376751d72bd1ea41c147a7a331d73b7d10d795661e2a93c08c2e022d58d04117fde1c0e1b22e3f462fed6c6172047e823328d692afb39d70fd4e3f3e990a", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "f69c3f97-50d1-4a4b-9fb2-f47db63df8f2", - block: { - id: "4817c2a9-fa24-4c63-9eae-1df5a44b4654", - created_date: "2021-03-29T19:49:22.526342Z", - modified_date: "2021-03-29T19:49:22.526367Z", - balance_key: "8b3004ad8637a8c42e66f92f68c576a704ce3eaa55fd0f22ae76fee5a1fe7c1a", - sender: "431f89d714dc2d748c899b14c725a52c2b5560c2b8e2bb2bb691f41a155c3a2e", - signature: - "f653376751d72bd1ea41c147a7a331d73b7d10d795661e2a93c08c2e022d58d04117fde1c0e1b22e3f462fed6c6172047e823328d692afb39d70fd4e3f3e990a", - }, - amount: 3, - fee: "", - recipient: "f962cd319293a079ee1916d20174e698072ae52bcf620f9519469c6f7eef6b4c", - }, - { - id: "813bafa7-f376-449f-9aa9-f547265cd970", - block: { - id: "fa66fc20-5f27-46a7-98f2-e6c0fa70f399", - created_date: "2021-03-29T18:53:04.113649Z", - modified_date: "2021-03-29T18:53:04.113676Z", - balance_key: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - sender: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - signature: - "c8fbd20e8032b0c351189344450c31b370074cabd2cceabbb6d88e144279d8079f69b89f6b767848c905e92b0d6e90050237eb834f9d6c8eb893f7cf97d9f40b", - }, - amount: 10000, - fee: "", - recipient: "0d1ab8b726814b0ac7c8a91888aaed423d0d860a97fbe91c40720a0df2e07ba4", - }, - { - id: "a5fe1c38-5ffd-407a-916a-5ef661f0651a", - block: { - id: "fa66fc20-5f27-46a7-98f2-e6c0fa70f399", - created_date: "2021-03-29T18:53:04.113649Z", - modified_date: "2021-03-29T18:53:04.113676Z", - balance_key: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - sender: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - signature: - "c8fbd20e8032b0c351189344450c31b370074cabd2cceabbb6d88e144279d8079f69b89f6b767848c905e92b0d6e90050237eb834f9d6c8eb893f7cf97d9f40b", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "7e0db6eb-65c9-4a2e-9fc4-d860fc05ccdc", - block: { - id: "fa66fc20-5f27-46a7-98f2-e6c0fa70f399", - created_date: "2021-03-29T18:53:04.113649Z", - modified_date: "2021-03-29T18:53:04.113676Z", - balance_key: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - sender: "83b78435dbf090fc90e51d6de67e958fdd1a837c7a505ac45a1fde7462acfd3a", - signature: - "c8fbd20e8032b0c351189344450c31b370074cabd2cceabbb6d88e144279d8079f69b89f6b767848c905e92b0d6e90050237eb834f9d6c8eb893f7cf97d9f40b", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "78dd6280-c7f3-4ed5-acfa-5bbc70171f7c", - block: { - id: "fcbdabba-9175-468c-9d69-b5856b640dca", - created_date: "2021-03-29T18:02:34.334077Z", - modified_date: "2021-03-29T18:02:34.334104Z", - balance_key: "eb09608b152bbdd5df105f300d03f32bda673553eff122e9fc566d26010dde43", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "e5f4407ee48a82206b98377b54ff8a04ad1bba7b80852b31d8d18ba383d1527cd2e0ead712f4d21db8fdfe4f2dc978077388ec57aceec6f917ab04153fcde50c", - }, - amount: 50, - fee: "", - recipient: "776d8bf50b44f3a7ac1cd2b961dcd593f9dc383f97196ae3bbf0fae24b2691eb", - }, - { - id: "9da197f8-cf15-4d44-a5b7-8b2ee4f24fc0", - block: { - id: "fcbdabba-9175-468c-9d69-b5856b640dca", - created_date: "2021-03-29T18:02:34.334077Z", - modified_date: "2021-03-29T18:02:34.334104Z", - balance_key: "eb09608b152bbdd5df105f300d03f32bda673553eff122e9fc566d26010dde43", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "e5f4407ee48a82206b98377b54ff8a04ad1bba7b80852b31d8d18ba383d1527cd2e0ead712f4d21db8fdfe4f2dc978077388ec57aceec6f917ab04153fcde50c", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "d4a5004a-6534-45fb-b678-c1a86f9ce51f", - block: { - id: "fcbdabba-9175-468c-9d69-b5856b640dca", - created_date: "2021-03-29T18:02:34.334077Z", - modified_date: "2021-03-29T18:02:34.334104Z", - balance_key: "eb09608b152bbdd5df105f300d03f32bda673553eff122e9fc566d26010dde43", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "e5f4407ee48a82206b98377b54ff8a04ad1bba7b80852b31d8d18ba383d1527cd2e0ead712f4d21db8fdfe4f2dc978077388ec57aceec6f917ab04153fcde50c", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "e7cdc6ea-2ab7-4500-977a-9cdb0ebd41ae", - block: { - id: "ad7e26e4-c1d7-494d-9ccc-4646f31afef2", - created_date: "2021-03-29T18:01:34.130686Z", - modified_date: "2021-03-29T18:01:34.130713Z", - balance_key: "23c48c86c4467e925c95259d8b0d9ff5c499729ddbb80f1ea3f3dcf61c232630", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "b162b19501278b534df88e3d6c99b225e7392b7a8d60583aa7417bb356f1fd0e468bc42d5ff86ac58a90ff3f2bed3d0bb9c5f61e53644f46d39b35d411b4f20b", - }, - amount: 50, - fee: "", - recipient: "776d8bf50b44f3a7ac1cd2b961dcd593f9dc383f97196ae3bbf0fae24b2691eb", - }, - { - id: "f168f3b5-4b2f-4e9f-af0f-af11a9337fb1", - block: { - id: "ad7e26e4-c1d7-494d-9ccc-4646f31afef2", - created_date: "2021-03-29T18:01:34.130686Z", - modified_date: "2021-03-29T18:01:34.130713Z", - balance_key: "23c48c86c4467e925c95259d8b0d9ff5c499729ddbb80f1ea3f3dcf61c232630", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "b162b19501278b534df88e3d6c99b225e7392b7a8d60583aa7417bb356f1fd0e468bc42d5ff86ac58a90ff3f2bed3d0bb9c5f61e53644f46d39b35d411b4f20b", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "4045c6a1-f773-4a86-bf6b-38fa80c6607b", - block: { - id: "ad7e26e4-c1d7-494d-9ccc-4646f31afef2", - created_date: "2021-03-29T18:01:34.130686Z", - modified_date: "2021-03-29T18:01:34.130713Z", - balance_key: "23c48c86c4467e925c95259d8b0d9ff5c499729ddbb80f1ea3f3dcf61c232630", - sender: "7658a980ecc4458bad84be5bb239968cf7be96fa18a1197bef3d62f9b93e5410", - signature: - "b162b19501278b534df88e3d6c99b225e7392b7a8d60583aa7417bb356f1fd0e468bc42d5ff86ac58a90ff3f2bed3d0bb9c5f61e53644f46d39b35d411b4f20b", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "82c4a550-860b-4678-a16d-357778d8cac5", - block: { - id: "3bd3c9bd-4a4f-4b10-858e-6da36b5cb450", - created_date: "2021-03-29T16:03:47.764153Z", - modified_date: "2021-03-29T16:03:47.764178Z", - balance_key: "1431298509b238837af4931c1ff53d01aac7aa33e59fd28aa3fa926bbec3c45e", - sender: "d259f2500152bcd1c1e85b1afa06b4582a4bf5d3df48d07263f4364e37b1fdc9", - signature: - "48f7567f8664be8aa86966924e097c2128e81e1b71c668b8b6bbf2e594b15a8ce9182604a1ca3cf38b08ee6c4190051e6c25062b7fb1b0a99b864b4987b0510b", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "6ca9ffa7-83ef-4405-86d7-8cb126e4e54e", - block: { - id: "3bd3c9bd-4a4f-4b10-858e-6da36b5cb450", - created_date: "2021-03-29T16:03:47.764153Z", - modified_date: "2021-03-29T16:03:47.764178Z", - balance_key: "1431298509b238837af4931c1ff53d01aac7aa33e59fd28aa3fa926bbec3c45e", - sender: "d259f2500152bcd1c1e85b1afa06b4582a4bf5d3df48d07263f4364e37b1fdc9", - signature: - "48f7567f8664be8aa86966924e097c2128e81e1b71c668b8b6bbf2e594b15a8ce9182604a1ca3cf38b08ee6c4190051e6c25062b7fb1b0a99b864b4987b0510b", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - { - id: "aa4bcff9-e3aa-4bfc-8ac1-5fca73446180", - block: { - id: "3bd3c9bd-4a4f-4b10-858e-6da36b5cb450", - created_date: "2021-03-29T16:03:47.764153Z", - modified_date: "2021-03-29T16:03:47.764178Z", - balance_key: "1431298509b238837af4931c1ff53d01aac7aa33e59fd28aa3fa926bbec3c45e", - sender: "d259f2500152bcd1c1e85b1afa06b4582a4bf5d3df48d07263f4364e37b1fdc9", - signature: - "48f7567f8664be8aa86966924e097c2128e81e1b71c668b8b6bbf2e594b15a8ce9182604a1ca3cf38b08ee6c4190051e6c25062b7fb1b0a99b864b4987b0510b", - }, - amount: 240, - fee: "", - recipient: "f1decb80339a4bb6c089b77cbac553e23a6ca86b0cfc64adb8c8eb8f8b57d815", - }, - { - id: "431355a6-645d-422a-bdec-dc5fc2c2f3ae", - block: { - id: "d0dbcf10-090b-4009-a244-fe9962dfa960", - created_date: "2021-03-28T20:49:11.650401Z", - modified_date: "2021-03-28T20:49:11.650427Z", - balance_key: "0dabbdd4c4cc2fe3ad56abf6293ed9d10e1e80fe27d0fc0a89fa9b55c9b2bc83", - sender: "d87ea2aab7a3cd828e2b162f0933ea4c55c88ea25235d54ae30660649a52072e", - signature: - "ff434e550c4937e21e44e9542d271c6e3f8309e7d7083d69aabe853c33c73c98e6bad92448924c82407b410407b8fd3f827711041f8605ba9591bc6f9730010b", - }, - amount: 1, - fee: "BANK", - recipient: "9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5", - }, - { - id: "afb90fec-dff4-4bc2-ab3e-7a3fb5971437", - block: { - id: "d0dbcf10-090b-4009-a244-fe9962dfa960", - created_date: "2021-03-28T20:49:11.650401Z", - modified_date: "2021-03-28T20:49:11.650427Z", - balance_key: "0dabbdd4c4cc2fe3ad56abf6293ed9d10e1e80fe27d0fc0a89fa9b55c9b2bc83", - sender: "d87ea2aab7a3cd828e2b162f0933ea4c55c88ea25235d54ae30660649a52072e", - signature: - "ff434e550c4937e21e44e9542d271c6e3f8309e7d7083d69aabe853c33c73c98e6bad92448924c82407b410407b8fd3f827711041f8605ba9591bc6f9730010b", - }, - amount: 1, - fee: "PRIMARY_VALIDATOR", - recipient: "c7498d45482098a4c4e2b2fa405fdb00e5bc74bf4739c43417e7c50ff08c4109", - }, - ], -}; + "count": 2329, + "next": "http://54.177.121.3/bank_transactions?limit=10&offset=10", + "previous": null, + "results": [ + { + "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" + }, + { + "id": "c96faaf6-8fd0-4f8f-a78f-3a702dcd0bd2", + "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": "", + "memo": "escrow your tnbc tnbCrow", + "recipient": "a8bf1f82fbff541bf6dc010afe2cd46929249963a089a3d5875f4625e317d888" + }, + { + "id": "42b37cc8-c632-4bc2-9b57-3336e188f29f", + "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": "BANK", + "memo": "", + "recipient": "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6" + }, + { + "id": "632f32e0-ba29-41a6-ac37-ec626087e734", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "", + "memo": "Be the first to buy stake in Keysign", + "recipient": "0973547428d479a8c0114baf601d261c827ee6a0a8cba8d2dcbc6a1937b4e024" + }, + { + "id": "8b2c532e-0ca3-4625-b5a5-fd4de1eba35f", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "PRIMARY_VALIDATOR", + "memo": "", + "recipient": "4afb3eaad999e4c073be0fbde86b76f9370d53b398b9cab9d760825709a1d6b3" + }, + { + "id": "3c2f8128-8e09-46eb-8c05-1a25a9e2f951", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "", + "memo": "Be the first to buy stake in Keysign", + "recipient": "549f2df0cb2004477a1ad12bd9db3a5df26ad358c722b9151c19c0f5320bec40" + }, + { + "id": "8451dca8-8d26-49d1-91ae-f516df5e2473", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "", + "memo": "Be the first to buy stake in Keysign", + "recipient": "92fcbfba3512c73c254d05b3e83e938efebe18d65bf407a85d39e5f0f1691b10" + }, + { + "id": "8d9617ec-0e5f-4e96-8dc0-56995de7382e", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "", + "memo": "Be the first to buy stake in Keysign", + "recipient": "9a3718a273fda5bdce62cadc800ba002b6db9e9848286b1b4674a86b30519865" + }, + { + "id": "49b906f4-1e2f-4cb4-9d7b-da62f114e9ea", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "BANK", + "memo": "", + "recipient": "e3a94381f8db207ddad931391886d611d6f4c060d0db2b0e373738e2f4db96d6" + }, + { + "id": "f1166eee-e519-4cba-a257-b74cc08fda6e", + "block": { + "id": "ba329793-6279-4e66-b797-6ced19d2e00e", + "created_date": "2021-04-12T08:18:29.939654Z", + "modified_date": "2021-04-12T08:18:29.939682Z", + "balance_key": "8a1b579a06b32f65626b873991770dab99c3e1e90683ca1d9e3d9d64e1d76fc2", + "sender": "8928526805de48e4bf2ed2a9b4b839e6b2603018ecdfbf4cffdb2065e01a3ed1", + "signature": "14c6b669996054f0fb2dbea2be47179793f501b5ed708f20d8515d8831eda4d61299721ec8bb2a9c17a33ff45b3cf20b997277a519edc44ec1b8a973f3d9fd0b" + }, + "amount": 1, + "fee": "", + "memo": "Be the first to buy stake in Keysign", + "recipient": "f922b8ed4ab05f5c41a6bac10b1b41c4ce3074bb75bd5de61b06af24173e0970" + } + ] +} \ No newline at end of file diff --git a/tests/paymentHandler.test.js b/tests/paymentHandler.test.js index ba4a6392..bf5353fb 100644 --- a/tests/paymentHandler.test.js +++ b/tests/paymentHandler.test.js @@ -1,21 +1,18 @@ const tnb = require("../"); describe("PaymentHandler", () => { - const bank = new tnb.Bank("http://13.57.215.62"); - const pv = new tnb.PrimaryValidator("http://54.241.124.162/"); + const bank = new tnb.Bank("http://54.177.121.3"); const paymentHandler = new tnb.PaymentHandler({ bankUrl: bank.url }); - function assertPaymentHandlerBasics(paymentHandler) { - expect(paymentHandler.bank.url).toBe(bank.url); - expect(paymentHandler.primaryValidator.url).toBe(pv.url); - } - it("constructor()", async () => { await paymentHandler.init(); - assertPaymentHandlerBasics(paymentHandler); + 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() paymentHandler.init(); const sender = new tnb.Account(); const recipient = new tnb.Account(); @@ -23,6 +20,7 @@ describe("PaymentHandler", () => { const txs = [ { amount: 100, + memo: 'hi', recipient: recipient.accountNumberHex, }, ]; @@ -30,6 +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]).toStrictEqual(txs[0]); + expect(transaction.transactions[0].amount).toBe(100) + expect(transaction.transactions[0].memo).toBe('hi') }); }); From afae3c1b5cff0d8eac3dc03b2b79a0e53b52106b Mon Sep 17 00:00:00 2001 From: Zino Adidi Date: Mon, 12 Apr 2021 12:05:46 +0300 Subject: [PATCH 2/2] chore(release): 1.1.0-alpha.3 --- CHANGELOG.md | 7 +++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c57d37a..a0c2a102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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.3](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2021-04-12) + + +### Features + +* Added support for memo ([#140](https://github.com/thenewboston-developers/thenewboston-js/issues/140)) ([ad5ed54](https://github.com/thenewboston-developers/thenewboston-js/commit/ad5ed54efc1f09b0ec2525fc0255ab39ab1df61d)) + ## [1.1.0-alpha.2](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.1.0-alpha.1...v1.1.0-alpha.2) (2021-04-10) diff --git a/package-lock.json b/package-lock.json index 9ee6a7b4..eb6759bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "thenewboston", - "version": "1.1.0-alpha.2", + "version": "1.1.0-alpha.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4bd773c2..ed110c6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "thenewboston", - "version": "1.1.0-alpha.2", + "version": "1.1.0-alpha.3", "description": "JavaScript library for thenewboston.", "author": { "name": "thenewboston-developers",