From db478303f23dbdf9c18d32429ec879e4438ca1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 25 Mar 2025 13:24:41 -0300 Subject: [PATCH 01/31] chore: upgrade wallet-lib to v2.1.1 --- package.json | 2 +- packages/common/package.json | 2 +- packages/daemon/package.json | 2 +- packages/wallet-service/package.json | 2 +- yarn.lock | 46 ++++++++++++++++------------ 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 3891eae1..c78f513d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@aws-sdk/client-apigatewaymanagementapi": "3.540.0", "@aws-sdk/client-lambda": "3.540.0", "@aws-sdk/client-sqs": "3.540.0", - "@hathor/wallet-lib": "1.14.1", + "@hathor/wallet-lib": "2.1.1", "@wallet-service/common": "1.5.0", "bip32": "^4.0.0", "bitcoinjs-lib": "^6.1.5", diff --git a/packages/common/package.json b/packages/common/package.json index 10f44304..a20412fe 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -8,7 +8,7 @@ "test": "jest --runInBand --collectCoverage --detectOpenHandles --forceExit" }, "peerDependencies": { - "@hathor/wallet-lib": "1.14.1" + "@hathor/wallet-lib": "2.1.1" }, "dependencies": { "@aws-sdk/client-lambda": "3.540.0", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index fcbaca36..778441dd 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -46,7 +46,7 @@ "typescript": "4.9.5" }, "peerDependencies": { - "@hathor/wallet-lib": "1.14.1", + "@hathor/wallet-lib": "2.1.1", "@wallet-service/common": "1.5.0" }, "dependencies": { diff --git a/packages/wallet-service/package.json b/packages/wallet-service/package.json index e8cadf78..bd757b78 100644 --- a/packages/wallet-service/package.json +++ b/packages/wallet-service/package.json @@ -40,7 +40,7 @@ "winston": "3.13.0" }, "peerDependencies": { - "@hathor/wallet-lib": "1.14.1", + "@hathor/wallet-lib": "2.1.1", "@wallet-service/common": "1.5.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index ca032f7d..6baf4423 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2160,23 +2160,24 @@ __metadata: languageName: node linkType: hard -"@hathor/wallet-lib@npm:1.14.1": - version: 1.14.1 - resolution: "@hathor/wallet-lib@npm:1.14.1" +"@hathor/wallet-lib@npm:2.1.1": + version: 2.1.1 + resolution: "@hathor/wallet-lib@npm:2.1.1" dependencies: abstract-level: "npm:1.0.4" - axios: "npm:1.7.2" + axios: "npm:1.7.7" bitcore-lib: "npm:8.25.10" bitcore-mnemonic: "npm:8.25.10" buffer: "npm:6.0.3" crypto-js: "npm:4.2.0" isomorphic-ws: "npm:5.0.0" level: "npm:8.0.1" + level-transcoder: "npm:1.0.1" lodash: "npm:4.17.21" - long: "npm:5.2.3" queue-microtask: "npm:1.2.3" ws: "npm:8.17.1" - checksum: 10/e95fafa78a0a4a24cb4b6ee49c8abfb4754d347c159078e78486f57720499a58619339652c041313025d10b440b6069aee8676857890de7c0ef69c9c3870296a + zod: "npm:3.23.8" + checksum: 10/692e740b80be632b6a9eb9b302dffa3b04cb295ceebdc9f10d1bf3a7cd654f2837818a2ebbcb8110de6827706939d454a212f74ca0460557b4d382d2cd611e7a languageName: node linkType: hard @@ -5781,14 +5782,14 @@ __metadata: languageName: node linkType: hard -"axios@npm:1.7.2": - version: 1.7.2 - resolution: "axios@npm:1.7.2" +"axios@npm:1.7.7": + version: 1.7.7 + resolution: "axios@npm:1.7.7" dependencies: follow-redirects: "npm:^1.15.6" form-data: "npm:^4.0.0" proxy-from-env: "npm:^1.1.0" - checksum: 10/6ae80dda9736bb4762ce717f1a26ff997d94672d3a5799ad9941c24d4fb019c1dff45be8272f08d1975d7950bac281f3ba24aff5ecd49ef5a04d872ec428782f + checksum: 10/7f875ea13b9298cd7b40fd09985209f7a38d38321f1118c701520939de2f113c4ba137832fe8e3f811f99a38e12c8225481011023209a77b0c0641270e20cde1 languageName: node linkType: hard @@ -9726,7 +9727,7 @@ __metadata: "@aws-sdk/client-apigatewaymanagementapi": "npm:3.540.0" "@aws-sdk/client-lambda": "npm:3.540.0" "@aws-sdk/client-sqs": "npm:3.540.0" - "@hathor/wallet-lib": "npm:1.14.1" + "@hathor/wallet-lib": "npm:2.1.1" "@types/jest": "npm:29.5.13" "@typescript-eslint/eslint-plugin": "npm:^7.4.0" "@typescript-eslint/parser": "npm:^7.4.0" @@ -11498,7 +11499,7 @@ __metadata: languageName: node linkType: hard -"level-transcoder@npm:^1.0.1": +"level-transcoder@npm:1.0.1, level-transcoder@npm:^1.0.1": version: 1.0.1 resolution: "level-transcoder@npm:1.0.1" dependencies: @@ -11810,13 +11811,6 @@ __metadata: languageName: node linkType: hard -"long@npm:5.2.3, long@npm:^5.0.0, long@npm:^5.2.1": - version: 5.2.3 - resolution: "long@npm:5.2.3" - checksum: 10/9167ec6947a825b827c30da169a7384eec6c0c9ec2f0b9c74da2e93d81159bbe39fb09c3f13dae9721d4b807ccfa09797a7dd1012f5d478e3e33ca3c78b608e6 - languageName: node - linkType: hard - "long@npm:^4.0.0": version: 4.0.0 resolution: "long@npm:4.0.0" @@ -11824,6 +11818,13 @@ __metadata: languageName: node linkType: hard +"long@npm:^5.0.0, long@npm:^5.2.1": + version: 5.2.3 + resolution: "long@npm:5.2.3" + checksum: 10/9167ec6947a825b827c30da169a7384eec6c0c9ec2f0b9c74da2e93d81159bbe39fb09c3f13dae9721d4b807ccfa09797a7dd1012f5d478e3e33ca3c78b608e6 + languageName: node + linkType: hard + "lowercase-keys@npm:^2.0.0": version: 2.0.0 resolution: "lowercase-keys@npm:2.0.0" @@ -16827,3 +16828,10 @@ __metadata: checksum: 10/33bd5ee7017656c2ad728b5d4ba510e15bd65ce1ec180c5bbdc7a5f063256353ec482e6a2bc74de7515219d8494147924b9aae16e63fdaaf37cdf7d1ee8df125 languageName: node linkType: hard + +"zod@npm:3.23.8": + version: 3.23.8 + resolution: "zod@npm:3.23.8" + checksum: 10/846fd73e1af0def79c19d510ea9e4a795544a67d5b34b7e1c4d0425bf6bfd1c719446d94cdfa1721c1987d891321d61f779e8236fde517dc0e524aa851a6eff1 + languageName: node + linkType: hard From 925d52645b5b6bdefb57ca442e710f1107dafeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 25 Mar 2025 13:32:24 -0300 Subject: [PATCH 02/31] chore: upgrade yarn lock --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 6baf4423..12065a25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5014,7 +5014,7 @@ __metadata: typescript: "npm:5.4.3" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 1.14.1 + "@hathor/wallet-lib": 2.1.1 languageName: unknown linkType: soft @@ -15227,7 +15227,7 @@ __metadata: ws: "npm:8.13.0" xstate: "npm:4.38.2" peerDependencies: - "@hathor/wallet-lib": 1.14.1 + "@hathor/wallet-lib": 2.1.1 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft @@ -16303,7 +16303,7 @@ __metadata: webpack-node-externals: "npm:3.0.0" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 1.14.1 + "@hathor/wallet-lib": 2.1.1 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft From ccd1daf3ca3078556348a35d7e8be400824dcaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Thu, 27 Mar 2025 00:59:02 -0300 Subject: [PATCH 03/31] feat: turn authorities into bigint to compare with lib consts --- packages/common/src/types.ts | 7 ++++--- packages/wallet-service/src/types.ts | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 99d7571e..96e8a557 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -50,7 +50,7 @@ export interface TxInput { // eslint-disable-next-line camelcase tx_id: string; index: number; - value: number; + value: bigint; // eslint-disable-next-line camelcase token_data: number; script: string; @@ -59,7 +59,7 @@ export interface TxInput { } export interface TxOutput { - value: number; + value: bigint; script: string; token: string; decoded: DecodedOutput; @@ -190,7 +190,8 @@ export class Authorities { } toJSON(): Record { - const authorities = this.toInteger(); + // TOKEN_MINT_MASK and TOKEN_MELT_MASK are bigint (since they come from the output amount) + const authorities = BigInt(this.toInteger()); return { mint: (authorities & constants.TOKEN_MINT_MASK) > 0, // eslint-disable-line no-bitwise melt: (authorities & constants.TOKEN_MELT_MASK) > 0, // eslint-disable-line no-bitwise diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index e2c8d811..890fff83 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -306,7 +306,8 @@ export class Authorities { } toJSON(): Record { - const authorities = this.toInteger(); + // TOKEN_MINT_MASK and TOKEN_MELT_MASK are bigint (since they come from the output amount) + const authorities = BigInt(this.toInteger()); return { mint: (authorities & hathorLib.constants.TOKEN_MINT_MASK) > 0, // eslint-disable-line no-bitwise melt: (authorities & hathorLib.constants.TOKEN_MELT_MASK) > 0, // eslint-disable-line no-bitwise From 6c2eabe3a316615c44a72faa0ee6046de27e2a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Thu, 27 Mar 2025 00:59:32 -0300 Subject: [PATCH 04/31] feat: use node22 --- .codebuild/buildspec.yml | 2 +- flake.lock | 36 +++++++++++++++++++----------------- flake.nix | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.codebuild/buildspec.yml b/.codebuild/buildspec.yml index 1d167ee6..dc03251d 100644 --- a/.codebuild/buildspec.yml +++ b/.codebuild/buildspec.yml @@ -173,7 +173,7 @@ phases: #If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions. #If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails. runtime-versions: - nodejs: 20 + nodejs: 22 # name: version commands: - npm install -g yarn diff --git a/flake.lock b/flake.lock index 2a01bd58..7c1d546f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,15 +2,14 @@ "nodes": { "devshell": { "inputs": { - "nixpkgs": "nixpkgs", - "systems": "systems" + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1695973661, - "narHash": "sha256-BP2H4c42GThPIhERtTpV1yCtwQHYHEKdRu7pjrmQAwo=", + "lastModified": 1741473158, + "narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=", "owner": "numtide", "repo": "devshell", - "rev": "cd4e2fda3150dd2f689caeac07b7f47df5197c31", + "rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0", "type": "github" }, "original": { @@ -20,12 +19,15 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1649676176, - "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -36,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1677383253, - "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=", + "lastModified": 1722073938, + "narHash": "sha256-OpX0StkL8vpXyWOGUD6G+MA26wAXK6SpT94kLJXo6B4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9952d6bc395f5841262b006fbace8dd7e143b634", + "rev": "e36e9f57337d0ff0cf77aceb58af4c805472bfae", "type": "github" }, "original": { @@ -52,11 +54,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1708247094, - "narHash": "sha256-H2VS7VwesetGDtIaaz4AMsRkPoSLEVzL/Ika8gnbUnE=", + "lastModified": 1742923925, + "narHash": "sha256-biPjLws6FiBVUUDHEMFq5pUQL84Wf7PntPYdo3oKkFw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "045b51a3ae66f673ed44b5bbd1f4a341d96703bf", + "rev": "25d1b84f5c90632a623c48d83a2faf156451e6b1", "type": "github" }, "original": { @@ -89,11 +91,11 @@ }, "unstableNixPkgs": { "locked": { - "lastModified": 1708118438, - "narHash": "sha256-kk9/0nuVgA220FcqH/D2xaN6uGyHp/zoxPNUmPCMmEE=", + "lastModified": 1742889210, + "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5863c27340ba4de8f83e7e3c023b9599c3cb3c80", + "rev": "698214a32beb4f4c8e3942372c694f40848b360d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8dc4438b..fa40a73e 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ inherit (packages) node-packages; in { - nodejs = final.nodejs_20; + nodejs = final.nodejs_22; nodePackages = prev.nodePackages; yarn = (import unstableNixPkgs { system = final.system; }).yarn-berry; }; @@ -34,7 +34,7 @@ pkgs.devshell.mkShell { packages = with pkgs; [ nixpkgs-fmt - nodejs_20 + nodejs_22 yarn docker-compose ]; From 4916bd3492d44ae8fab71bc69c4d8013c93ac642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Fri, 28 Mar 2025 13:57:07 -0300 Subject: [PATCH 05/31] feat: change bigint support config on mysql client --- db/config.js | 3 +++ .../__tests__/integration/scripts/sequelize-db-config.js | 1 + packages/wallet-service/src/utils.ts | 3 +++ 3 files changed, 7 insertions(+) diff --git a/db/config.js b/db/config.js index 7d201df9..b3ed932c 100644 --- a/db/config.js +++ b/db/config.js @@ -9,6 +9,7 @@ module.exports = { port: process.env.DB_PORT || 3306, dialect: 'mysql', dialectOptions: { + supportBigNumbers: true, bigNumberStrings: true, }, }, @@ -20,6 +21,7 @@ module.exports = { port: process.env.CI_DB_PORT || 3306, dialect: 'mysql', dialectOptions: { + supportBigNumbers: true, bigNumberStrings: true, }, }, @@ -31,6 +33,7 @@ module.exports = { port: process.env.DB_PORT, dialect: 'mysql', dialectOptions: { + supportBigNumbers: true, bigNumberStrings: true, }, }, diff --git a/packages/daemon/__tests__/integration/scripts/sequelize-db-config.js b/packages/daemon/__tests__/integration/scripts/sequelize-db-config.js index ee52475a..b2ff043a 100644 --- a/packages/daemon/__tests__/integration/scripts/sequelize-db-config.js +++ b/packages/daemon/__tests__/integration/scripts/sequelize-db-config.js @@ -7,6 +7,7 @@ module.exports = { port: 3380, dialect: 'mysql', dialectOptions: { + supportBigNumbers: true, bigNumberStrings: true, }, }, diff --git a/packages/wallet-service/src/utils.ts b/packages/wallet-service/src/utils.ts index 06809ab1..b8815521 100644 --- a/packages/wallet-service/src/utils.ts +++ b/packages/wallet-service/src/utils.ts @@ -86,6 +86,9 @@ export const getDbConnection = (): ServerlessMysql => ( // TODO if not on local env, get IAM token // https://aws.amazon.com/blogs/database/iam-role-based-authentication-to-amazon-aurora-from-serverless-applications/ password: config.dbPass, + // BIGINT columns should be returned as strings to keep precision on the JS unsafe range. + supportBigNumbers: true, + bigNumberStrings: true, }, }) ); From d684a44c6065400b665c5cf9a5d840ce5076e3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Mon, 31 Mar 2025 13:45:07 -0300 Subject: [PATCH 06/31] feat: add database support for bigint with type changes and error fixes --- package.json | 2 +- packages/common/src/types.ts | 52 ++++---- packages/daemon/__tests__/db/index.test.ts | 116 +++++++++--------- packages/daemon/__tests__/utils.ts | 12 +- packages/daemon/src/db/index.ts | 25 ++-- packages/daemon/src/types/event.ts | 2 +- packages/daemon/src/types/transaction.ts | 2 +- packages/daemon/src/types/wallet.ts | 8 +- packages/daemon/src/utils/cache.ts | 2 +- packages/daemon/src/utils/wallet.ts | 7 +- packages/wallet-service/src/api/tokens.ts | 4 +- packages/wallet-service/src/api/txOutputs.ts | 14 ++- packages/wallet-service/src/commons.ts | 2 +- packages/wallet-service/src/db/index.ts | 41 ++++--- packages/wallet-service/src/db/utils.ts | 5 +- packages/wallet-service/src/fullnode.ts | 1 - packages/wallet-service/src/types.ts | 42 +++---- packages/wallet-service/tests/commons.test.ts | 46 +++---- packages/wallet-service/tests/db.test.ts | 32 ++--- .../wallet-service/tests/integration.test.ts | 1 - packages/wallet-service/tests/types.ts | 4 +- packages/wallet-service/tests/utils.ts | 14 +-- packages/wallet-service/tsconfig.json | 4 +- 23 files changed, 228 insertions(+), 210 deletions(-) diff --git a/package.json b/package.json index c78f513d..1a884c6d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "packages/wallet-service" ], "engines": { - "node": ">=18" + "node": ">=22" }, "nohoist": [ "**" diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 96e8a557..c1f3b7a8 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -88,12 +88,12 @@ export class Authorities { array: number[]; - constructor(authorities?: number | number[]) { + constructor(authorities?: bigint | number | number[]) { let tmp: number[] = []; if (authorities instanceof Array) { tmp = authorities; } else if (authorities != null) { - tmp = Authorities.intToArray(authorities); + tmp = Authorities.intToArray(Number(authorities)); } this.array = new Array(Authorities.LENGTH - tmp.length).fill(0).concat(tmp); @@ -200,19 +200,26 @@ export class Authorities { } export class Balance { - totalAmountSent: number; + totalAmountSent: bigint; - lockedAmount: number; + lockedAmount: bigint; - unlockedAmount: number; + unlockedAmount: bigint; lockedAuthorities: Authorities; unlockedAuthorities: Authorities; - lockExpires: number | null | undefined; + lockExpires: number | null; - constructor(totalAmountSent = 0, unlockedAmount = 0, lockedAmount = 0, lockExpires = null, unlockedAuthorities = null, lockedAuthorities = null) { + constructor( + totalAmountSent = 0n, + unlockedAmount = 0n, + lockedAmount = 0n, + lockExpires: number|null = null, + unlockedAuthorities: Authorities|null = null, + lockedAuthorities: Authorities|null = null + ) { this.totalAmountSent = totalAmountSent; this.unlockedAmount = unlockedAmount; this.lockedAmount = lockedAmount; @@ -226,7 +233,7 @@ export class Balance { * * @returns The total balance */ - total(): number { + total(): bigint { return this.unlockedAmount + this.lockedAmount; } @@ -249,7 +256,6 @@ export class Balance { this.totalAmountSent, this.unlockedAmount, this.lockedAmount, - // @ts-ignore this.lockExpires, this.unlockedAuthorities.clone(), this.lockedAuthorities.clone(), @@ -273,7 +279,6 @@ export class Balance { } else if (b2.lockExpires === null) { lockExpires = b1.lockExpires; } else { - // @ts-ignore lockExpires = Math.min(b1.lockExpires, b2.lockExpires); } return new Balance( @@ -297,7 +302,7 @@ export class TokenBalanceMap { get(tokenId: string): Balance { // if the token is not present, return 0 instead of undefined - return this.map[tokenId] || new Balance(0, 0, 0); + return this.map[tokenId] || new Balance(0n, 0n, 0n); } set(tokenId: string, balance: Balance): void { @@ -336,17 +341,16 @@ export class TokenBalanceMap { * @param tokenBalanceMap - The js object to convert to a TokenBalanceMap * @returns - The new TokenBalanceMap object */ - static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { + static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { const obj = new TokenBalanceMap(); for (const [tokenId, balance] of Object.entries(tokenBalanceMap)) { obj.set(tokenId, new Balance( - balance.totalSent as number, - balance.unlocked as number, - balance.locked as number, - // @ts-ignore - balance.lockExpires || null, - balance.unlockedAuthorities, - balance.lockedAuthorities, + balance.totalSent as bigint, + balance.unlocked as bigint, + balance.locked as bigint, + balance.lockExpires as number || null, + balance.unlockedAuthorities as Authorities, + balance.lockedAuthorities as Authorities, )); } return obj; @@ -396,7 +400,7 @@ export class TokenBalanceMap { // @ts-ignore obj.set(token, new Balance(0, 0, 0, null, new Authorities(output.value), 0)); } else { - obj.set(token, new Balance(value, value, 0, null)); + obj.set(token, new Balance(value, value, 0n, null)); } return obj; @@ -421,9 +425,9 @@ export class TokenBalanceMap { obj.set( token, new Balance( - 0, - 0, - 0, + 0n, + 0n, + 0n, null, // @ts-ignore authorities.toNegative(), @@ -431,7 +435,7 @@ export class TokenBalanceMap { ), ); } else { - obj.set(token, new Balance(0, -input.value, 0, null)); + obj.set(token, new Balance(0n, -input.value, 0n, null)); } return obj; } diff --git a/packages/daemon/__tests__/db/index.test.ts b/packages/daemon/__tests__/db/index.test.ts index d61fc123..a8bab3a2 100644 --- a/packages/daemon/__tests__/db/index.test.ts +++ b/packages/daemon/__tests__/db/index.test.ts @@ -138,12 +138,12 @@ describe('tx output methods', () => { const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', tokenId: 'token1', locked: false }, - { value: 15, address: 'address1', tokenId: 'token1', locked: false }, - { value: 25, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, - { value: 35, address: 'address2', tokenId: 'token1', locked: false }, + { value: 5n, address: 'address1', tokenId: 'token1', locked: false }, + { value: 15n, address: 'address1', tokenId: 'token1', locked: false }, + { value: 25n, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, + { value: 35n, address: 'address2', tokenId: 'token1', locked: false }, // authority utxo - { value: 0b11, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, + { value: 0b11n, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, ]; // empty list should be fine @@ -166,8 +166,8 @@ describe('tx output methods', () => { const { token, decoded } = output; let authorities = 0; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + authorities = Number(value); + value = 0n; } await expect( checkUtxoTable(mysql, utxos.length, txId, output.index, token, decoded?.address, value, authorities, decoded?.timelock, null, output.locked), @@ -239,8 +239,8 @@ describe('tx output methods', () => { const { token, decoded } = output; let authorities = 0; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + authorities = Number(value); + value = 0n; } await expect( checkUtxoTable(mysql, utxos.length, txId, index, token, decoded?.address, value, authorities, decoded?.timelock, null, output.locked), @@ -259,7 +259,7 @@ describe('tx output methods', () => { timelock: null, }, script: '', - value: 25, + value: 25n, authorities: 0, timelock: 500, heightlock: null, @@ -300,11 +300,11 @@ describe('tx output methods', () => { const txId = 'txId'; const utxos: DbTxOutput[] = [ - { txId, index: 0, tokenId: 'token1', address: 'address1', value: 5, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, - { txId, index: 1, tokenId: 'token1', address: 'address1', value: 15, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null}, - { txId, index: 2, tokenId: 'token1', address: 'address1', value: 25, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, - { txId, index: 3, tokenId: 'token1', address: 'address1', value: 1, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, - { txId, index: 4, tokenId: 'token1', address: 'address1', value: 3, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, + { txId, index: 0, tokenId: 'token1', address: 'address1', value: 5n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, + { txId, index: 1, tokenId: 'token1', address: 'address1', value: 15n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null}, + { txId, index: 2, tokenId: 'token1', address: 'address1', value: 25n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, + { txId, index: 3, tokenId: 'token1', address: 'address1', value: 1n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, + { txId, index: 4, tokenId: 'token1', address: 'address1', value: 3n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, ]; // add to utxo table @@ -332,8 +332,8 @@ describe('tx output methods', () => { await addOrUpdateTx(mysql, txId, 0, 1, 1, 65); const utxos: DbTxOutput[] = [ - { txId, index: 0, tokenId: 'token1', address: 'address1', value: 5, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, - { txId, index: 1, tokenId: 'token1', address: 'address1', value: 15, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null}, + { txId, index: 0, tokenId: 'token1', address: 'address1', value: 5n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null }, + { txId, index: 1, tokenId: 'token1', address: 'address1', value: 15n, authorities: 0, timelock: 0, heightlock: null, locked: false, spentBy: null, txProposalIndex: null, txProposalId: null}, ]; // add to utxo table @@ -359,17 +359,17 @@ describe('tx output methods', () => { const txId2 = 'txId2'; const utxos = [ // no locks - { value: 5, address: 'address1', token: 'token1', locked: false }, + { value: 5n, address: 'address1', token: 'token1', locked: false }, // only timelock - { value: 25, address: 'address2', token: 'token2', timelock: 50, locked: false }, + { value: 25n, address: 'address2', token: 'token2', timelock: 50, locked: false }, ]; const utxos2 = [ // only heightlock - { value: 35, address: 'address2', token: 'token1', timelock: null, locked: true }, + { value: 35n, address: 'address2', token: 'token1', timelock: null, locked: true }, // timelock and heightlock - { value: 45, address: 'address2', token: 'token1', timelock: 100, locked: true }, - { value: 55, address: 'address2', token: 'token1', timelock: 1000, locked: true }, + { value: 45n, address: 'address2', token: 'token1', timelock: 100, locked: true }, + { value: 55n, address: 'address2', token: 'token1', timelock: 1000, locked: true }, ]; // add to utxo table @@ -406,12 +406,12 @@ describe('tx output methods', () => { const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', tokenId: 'token1', locked: true }, - { value: 15, address: 'address1', tokenId: 'token1', locked: true }, - { value: 25, address: 'address2', tokenId: 'token2', timelock: 100, locked: true }, - { value: 35, address: 'address2', tokenId: 'token1', timelock: 200, locked: true }, + { value: 5n, address: 'address1', tokenId: 'token1', locked: true }, + { value: 15n, address: 'address1', tokenId: 'token1', locked: true }, + { value: 25n, address: 'address2', tokenId: 'token2', timelock: 100, locked: true }, + { value: 35n, address: 'address2', tokenId: 'token1', timelock: 200, locked: true }, // authority utxo - { value: 0b11, address: 'address1', tokenId: 'token1', timelock: 300, locked: true, tokenData: 129 }, + { value: 0b11n, address: 'address1', tokenId: 'token1', timelock: 300, locked: true, tokenData: 129 }, ]; // empty list should be fine @@ -449,9 +449,9 @@ describe('tx output methods', () => { expect.hasAssertions(); const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', token: 'token1', locked: false }, - { value: 25, address: 'address2', token: 'token2', timelock: 500, locked: true }, - { value: 35, address: 'address2', token: 'token1', locked: false }, + { value: 5n, address: 'address1', token: 'token1', locked: false }, + { value: 25n, address: 'address2', token: 'token2', timelock: 500, locked: true }, + { value: 35n, address: 'address2', token: 'token1', locked: false }, ]; // add to utxo table @@ -486,20 +486,20 @@ describe('address and wallet related tests', () => { const timestamp1 = 10; const addrMap1 = { address1: TokenBalanceMap.fromStringMap({ - token1: { unlocked: 10, locked: 0 }, - token2: { unlocked: 7, locked: 0 }, - token3: { unlocked: 2, locked: 0, unlockedAuthorities: new Authorities(0b01) }, + token1: { unlocked: 10n, locked: 0n }, + token2: { unlocked: 7n, locked: 0n }, + token3: { unlocked: 2n, locked: 0n, unlockedAuthorities: new Authorities(0b01) }, }), - address2: TokenBalanceMap.fromStringMap({ token1: { unlocked: 8, locked: 0, unlockedAuthorities: new Authorities(0b01) } }), + address2: TokenBalanceMap.fromStringMap({ token1: { unlocked: 8n, locked: 0n, unlockedAuthorities: new Authorities(0b01) } }), }; await updateAddressTablesWithTx(mysql, txId1, timestamp1, addrMap1); await expect(checkAddressTable(mysql, 2, address1, null, null, 2)).resolves.toBe(true); await expect(checkAddressTable(mysql, 2, address2, null, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token1, 10, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token2, 7, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token3, 2, 0, null, 1, 0b01, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address2, token1, 8, 0, null, 1, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token1, 10n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token2, 7n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token3, 2n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address2, token1, 8n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token1, 10, timestamp1)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token2, 7, timestamp1)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token3, 2, timestamp1)).resolves.toBe(true); @@ -509,21 +509,21 @@ describe('address and wallet related tests', () => { const txId2 = 'txId2'; const timestamp2 = 15; const addrMap2 = { - address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: -5, locked: 0 }, - token3: { unlocked: 6, locked: 0, unlockedAuthorities: new Authorities([-1]) } }), - address2: TokenBalanceMap.fromStringMap({ token1: { unlocked: 8, locked: 0, unlockedAuthorities: new Authorities(0b10) }, - token2: { unlocked: 3, locked: 0 } }), + address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: -5n, locked: 0n }, + token3: { unlocked: 6n, locked: 0n, unlockedAuthorities: new Authorities([-1]) } }), + address2: TokenBalanceMap.fromStringMap({ token1: { unlocked: 8n, locked: 0n, unlockedAuthorities: new Authorities(0b10) }, + token2: { unlocked: 3n, locked: 0n } }), }; await updateAddressTablesWithTx(mysql, txId2, timestamp2, addrMap2); await expect(checkAddressTable(mysql, 2, address1, null, null, 3)).resolves.toBe(true); await expect(checkAddressTable(mysql, 2, address2, null, null, 2)).resolves.toBe(true); // final balance for each (address,token) - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 0, null, 2)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token2', 7, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token3', 8, 0, null, 2, 0, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address2, 'token1', 16, 0, null, 2, 0b11, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address2, 'token2', 3, 0, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 0n, null, 2)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token2', 7n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token3', 8n, 0n, null, 2, 0, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address2, 'token1', 16n, 0n, null, 2, 0b11, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address2, 'token2', 3n, 0n, null, 1)).resolves.toBe(true); // tx history await expect(checkAddressTxHistoryTable(mysql, 8, address1, txId2, token1, -5, timestamp2)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 8, address1, txId2, token3, 6, timestamp2)).resolves.toBe(true); @@ -540,10 +540,10 @@ describe('address and wallet related tests', () => { const timestamp3 = 20; const lockExpires = 5000; const addrMap3 = { - address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 3, lockExpires } }), + address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0n, locked: 3n, lockExpires } }), }; await updateAddressTablesWithTx(mysql, txId3, timestamp3, addrMap3); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 3, lockExpires, 3)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 3n, lockExpires, 3)).resolves.toBe(true); // another tx, with higher timelock const txId4 = 'txId4'; @@ -552,7 +552,7 @@ describe('address and wallet related tests', () => { address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 2, lockExpires: lockExpires + 1 } }), }; await updateAddressTablesWithTx(mysql, txId4, timestamp4, addrMap4); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 5, lockExpires, 4)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 5n, lockExpires, 4)).resolves.toBe(true); // another tx, with lower timelock const txId5 = 'txId5'; @@ -561,7 +561,7 @@ describe('address and wallet related tests', () => { address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 2, lockExpires: lockExpires - 1 } }), }; await updateAddressTablesWithTx(mysql, txId5, timestamp5, addrMap5); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 7, lockExpires - 1, 5)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 7n, lockExpires - 1, 5)).resolves.toBe(true); // We shouldn't throw if the addressBalanceMap is empty: await expect(updateAddressTablesWithTx(mysql, txId5, timestamp5, {})).resolves.not.toThrow(); @@ -584,9 +584,9 @@ describe('address and wallet related tests', () => { const addr1Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 10, locked: 0, unlockedAuthorities: new Authorities(0b01) } }); const addr2Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 5, locked: 0 } }); await updateAddressLockedBalance(mysql, { [addr1]: addr1Map, [addr2]: addr2Map }); - await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60, 10, null, 3, 0b01, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 3, addr2, tokenId, 5, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 3, addr1, otherToken, 5, 5, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60n, 10n, null, 3, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr2, tokenId, 5n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, otherToken, 5n, 5n, null, 1)).resolves.toBe(true); // now pretend there's another locked authority, so final balance of locked authorities should be updated accordingly await addToUtxoTable(mysql, [{ @@ -594,7 +594,7 @@ describe('address and wallet related tests', () => { index: 0, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b01, timelock: 10000, heightlock: null, @@ -603,7 +603,7 @@ describe('address and wallet related tests', () => { }]); const newMap = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 0, locked: 0, unlockedAuthorities: new Authorities(0b10) } }); await updateAddressLockedBalance(mysql, { [addr1]: newMap }); - await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60, 10, null, 3, 0b11, 0b01)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60n, 10n, null, 3, 0b11, 0b01)).resolves.toBe(true); }); test('updateWalletLockedBalance', async () => { @@ -1225,8 +1225,8 @@ describe('voidTransaction', () => { await voidTransaction(mysql, txId, addressBalance); - await expect(checkAddressBalanceTable(mysql, 2, addr1, token2, 1, 0, null, 3)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 2, addr1, token1, 1, 0, null, 4)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 2, addr1, token2, 1n, 0n, null, 3)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 2, addr1, token1, 1n, 0n, null, 4)).resolves.toBe(true); // Address tx history entry should have been deleted for both tokens: await expect(checkAddressTxHistoryTable(mysql, 0, addr1, txId, token1, -1, 0)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 0, addr1, txId, token2, -1, 0)).resolves.toBe(true); diff --git a/packages/daemon/__tests__/utils.ts b/packages/daemon/__tests__/utils.ts index e70ed8ca..0b5fbf91 100644 --- a/packages/daemon/__tests__/utils.ts +++ b/packages/daemon/__tests__/utils.ts @@ -52,7 +52,7 @@ export const ADDRESSES = [ export const createOutput = ( index: number, - value: number, + value: bigint, address: string, token = '00', timelock: number | null = null, @@ -77,7 +77,7 @@ export const createOutput = ( ); export const createEventTxInput = ( - value: number, + value: bigint, address: string, txId: string, index: number, @@ -102,7 +102,7 @@ export const createEventTxInput = ( ); export const createInput = ( - value: number, + value: bigint, address: string, txId: string, index: number, @@ -132,7 +132,7 @@ export const checkUtxoTable = async ( index?: number, tokenId?: string, address?: string, - value?: number, + value?: bigint, authorities?: number, timelock?: number | null, heightlock?: number | null, @@ -363,8 +363,8 @@ export const checkAddressBalanceTable = async ( totalResults: number, address: string, tokenId: string, - unlocked: number, - locked: number, + unlocked: bigint, + locked: bigint, lockExpires: number | null, transactions: number, unlockedAuthorities = 0, diff --git a/packages/daemon/src/db/index.ts b/packages/daemon/src/db/index.ts index 7ea1ab56..ba491a6a 100644 --- a/packages/daemon/src/db/index.ts +++ b/packages/daemon/src/db/index.ts @@ -3,14 +3,13 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */ -import mysql, { Connection as MysqlConnection, OkPacket, Pool, ResultSetHeader } from 'mysql2/promise'; +*/ +import mysql, { Connection as MysqlConnection, Pool, ResultSetHeader } from 'mysql2/promise'; import { DbTxOutput, StringMap, Wallet, EventTxInput, - GenerateAddresses, AddressIndexMap, LastSyncedEvent, AddressBalance, @@ -126,8 +125,8 @@ export const addUtxos = async ( let value = output.value; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + authorities = Number(value); + value = 0n; } return [ @@ -220,7 +219,7 @@ export const getTxOutputsFromTx = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -262,7 +261,7 @@ export const getTxOutputs = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -345,7 +344,7 @@ export const getTxOutputsAtHeight = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -659,7 +658,7 @@ export const getUtxosLockedAtHeight = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -957,7 +956,7 @@ export const mapDbResultToDbTxOutput = (result: TxOutputRow): DbTxOutput => ({ index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -1024,7 +1023,7 @@ export const getLockedUtxoFromInputs = async (mysql: MysqlConnection, inputs: Ev index: utxo.index as number, tokenId: utxo.token_id as string, address: utxo.address as string, - value: utxo.value as number, + value: BigInt(utxo.value), authorities: utxo.authorities as number, timelock: utxo.timelock as number, heightlock: utxo.heightlock as number, @@ -1234,7 +1233,7 @@ export const getTxOutputsBySpent = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, @@ -1429,7 +1428,7 @@ export const getTxOutputsHeightUnlockedAtHeight = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, diff --git a/packages/daemon/src/types/event.ts b/packages/daemon/src/types/event.ts index a4bcb2a8..bb7be334 100644 --- a/packages/daemon/src/types/event.ts +++ b/packages/daemon/src/types/event.ts @@ -120,7 +120,7 @@ export interface EventTxInput { } export interface EventTxOutput { - value: number; + value: bigint; token_data: number; script: string; locked?: boolean; diff --git a/packages/daemon/src/types/transaction.ts b/packages/daemon/src/types/transaction.ts index a933b6ec..9032da1d 100644 --- a/packages/daemon/src/types/transaction.ts +++ b/packages/daemon/src/types/transaction.ts @@ -10,7 +10,7 @@ export interface DbTxOutput { index: number; tokenId: string; address: string; - value: number; + value: bigint; authorities: number; timelock: number | null; heightlock: number | null; diff --git a/packages/daemon/src/types/wallet.ts b/packages/daemon/src/types/wallet.ts index 15159a8e..2921b06b 100644 --- a/packages/daemon/src/types/wallet.ts +++ b/packages/daemon/src/types/wallet.ts @@ -27,13 +27,13 @@ export interface Wallet { export type TokenBalanceValue = { tokenId: string, tokenSymbol: string, - totalAmountSent: number; - lockedAmount: number; - unlockedAmount: number; + totalAmountSent: bigint; + lockedAmount: bigint; + unlockedAmount: bigint; lockedAuthorities: Record; unlockedAuthorities: Record; lockExpires: number | null; - total: number; + total: bigint; } export interface WalletBalanceValue { diff --git a/packages/daemon/src/utils/cache.ts b/packages/daemon/src/utils/cache.ts index 8c813f5f..007a0f56 100644 --- a/packages/daemon/src/utils/cache.ts +++ b/packages/daemon/src/utils/cache.ts @@ -43,7 +43,7 @@ export class LRU { } first(): string { - return this.cache.keys().next().value; + return this.cache.keys().next()?.value ?? ''; } clear(): void { diff --git a/packages/daemon/src/utils/wallet.ts b/packages/daemon/src/utils/wallet.ts index ec906770..fb49b8b5 100644 --- a/packages/daemon/src/utils/wallet.ts +++ b/packages/daemon/src/utils/wallet.ts @@ -178,7 +178,7 @@ export const unlockUtxos = async (mysql: MysqlConnection, utxos: DbTxOutput[], u }; return { - value: utxo.authorities > 0 ? utxo.authorities : utxo.value, + value: utxo.authorities > 0 ? BigInt(utxo.authorities) : utxo.value, token: utxo.tokenId, decoded, locked: false, @@ -474,7 +474,10 @@ export class FromTokenBalanceMapToBalanceValueList { } export const sortBalanceValueByAbsTotal = (balanceA: TokenBalanceValue, balanceB: TokenBalanceValue): number => { - if (Math.abs(balanceA.total) - Math.abs(balanceB.total) >= 0) return -1; + function abs(num: bigint) { + return num >= 0n ? num : -num; + } + if (abs(balanceA.total) - abs(balanceB.total) >= 0n) return -1; return 0; }; diff --git a/packages/wallet-service/src/api/tokens.ts b/packages/wallet-service/src/api/tokens.ts index 3bd891aa..80d4d82d 100644 --- a/packages/wallet-service/src/api/tokens.ts +++ b/packages/wallet-service/src/api/tokens.ts @@ -92,8 +92,8 @@ export const getTokenDetails = middy(walletIdProxyHandler(async (walletId, event ] = await Promise.all([ getTotalSupply(mysql, tokenId), getTotalTransactions(mysql, tokenId), - getAuthorityUtxo(mysql, tokenId, constants.TOKEN_MELT_MASK), - getAuthorityUtxo(mysql, tokenId, constants.TOKEN_MINT_MASK), + getAuthorityUtxo(mysql, tokenId, Number(constants.TOKEN_MELT_MASK)), + getAuthorityUtxo(mysql, tokenId, Number(constants.TOKEN_MINT_MASK)), ]); return { diff --git a/packages/wallet-service/src/api/txOutputs.ts b/packages/wallet-service/src/api/txOutputs.ts index 50af388e..19418725 100644 --- a/packages/wallet-service/src/api/txOutputs.ts +++ b/packages/wallet-service/src/api/txOutputs.ts @@ -22,6 +22,14 @@ import cors from '@middy/http-cors'; const mysql = getDbConnection(); +const positiveBigInt = Joi.custom(value => { + const newVal = BigInt(value); + if (newVal > 0n) { + return newVal; + } + throw new Error('value must be positive'); +}); + const bodySchema = Joi.object({ id: Joi.string().optional(), addresses: Joi.array() @@ -31,8 +39,10 @@ const bodySchema = Joi.object({ tokenId: Joi.string().default('00'), authority: Joi.number().default(0).integer().positive(), ignoreLocked: Joi.boolean().optional(), - biggerThan: Joi.number().integer().positive().default(-1), - smallerThan: Joi.number().integer().positive().default(constants.MAX_OUTPUT_VALUE + 1), + // @ts-ignore : bigint is not considered a basic type for a default value. + biggerThan: positiveBigInt.default(0n), + // @ts-ignore + smallerThan: positiveBigInt.default(constants.MAX_OUTPUT_VALUE + 1n), maxOutputs: Joi.number().integer().positive().default(constants.MAX_OUTPUTS), skipSpent: Joi.boolean().optional().default(true), txId: Joi.string().optional(), diff --git a/packages/wallet-service/src/commons.ts b/packages/wallet-service/src/commons.ts index 341de854..4e54117c 100644 --- a/packages/wallet-service/src/commons.ts +++ b/packages/wallet-service/src/commons.ts @@ -87,7 +87,7 @@ export const unlockUtxos = async (mysql: ServerlessMysql, utxos: DbTxOutput[], u }; return { - value: utxo.authorities > 0 ? utxo.authorities : utxo.value, + value: utxo.authorities > 0 ? BigInt(utxo.authorities) : utxo.value, token: utxo.tokenId, decoded, locked: false, diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 5ba752ca..353fb2aa 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -183,7 +183,7 @@ export const generateAddresses = async (mysql: ServerlessMysql, xpubkey: string, existingAddresses[address] = index; // if address is used, check if its index is higher than the current highest used index - if (entry.transactions > 0 && index > lastUsedAddressIndex) { + if (entry.transactions as number > 0 && index > lastUsedAddressIndex) { lastUsedAddressIndex = index; } @@ -683,8 +683,9 @@ export const addUtxos = async ( let value = output.value; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + // value should be within [0, 255] for authorities to be valid. + authorities = Number(value); + value = 0n; } return [ @@ -948,11 +949,11 @@ export const getWalletSortedValueUtxos = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value as string), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - locked: result.locked > 0, + locked: result.locked as number > 0, }; utxos.push(utxo); } @@ -1013,11 +1014,11 @@ export const getLockedUtxoFromInputs = async (mysql: ServerlessMysql, inputs: Tx index: utxo.index as number, tokenId: utxo.token_id as string, address: utxo.address as string, - value: utxo.value as number, + value: BigInt(utxo.value as string), authorities: utxo.authorities as number, timelock: utxo.timelock as number, heightlock: utxo.heightlock as number, - locked: (utxo.locked > 0), + locked: (utxo.locked as number > 0), })); } @@ -1382,9 +1383,9 @@ INNER JOIN token ON w.token_id = token.id const results: DbSelectResult = await mysql.query(query, params); for (const result of results) { - const totalAmount = result.total_received as number; - const unlockedBalance = result.unlocked_balance as number; - const lockedBalance = result.locked_balance as number; + const totalAmount = BigInt(result.total_received as string); + const unlockedBalance = BigInt(result.unlocked_balance as string); + const lockedBalance = BigInt(result.locked_balance as string); const unlockedAuthorities = new Authorities(result.unlocked_authorities as number); const lockedAuthorities = new Authorities(result.locked_authorities as number); const timelockExpires = result.timelock_expires as number; @@ -1516,11 +1517,11 @@ export const getUtxosLockedAtHeight = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value as string), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - locked: result.locked > 0, + locked: result.locked as number > 0, }; utxos.push(utxo); } @@ -1570,11 +1571,11 @@ export const getWalletUnlockedUtxos = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value as string), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - locked: result.locked > 0, + locked: result.locked as number > 0, }; utxos.push(utxo); } @@ -1940,11 +1941,11 @@ export const getTxOutputs = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value as string), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - locked: result.locked > 0, + locked: result.locked as number > 0, txProposalId: result.tx_proposal as string, txProposalIndex: result.tx_proposal_index as number, spentBy: result.spent_by ? result.spent_by as string : null, @@ -2008,11 +2009,11 @@ export const getTxOutputsBySpent = async ( index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value as string), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - locked: result.locked > 0, + locked: result.locked as number > 0, txProposalId: result.tx_proposal as string, txProposalIndex: result.tx_proposal_index as number, spentBy: result.spent_by ? result.spent_by as string : null, @@ -2395,7 +2396,7 @@ export const filterTxOutputs = async ( ignoreLocked: false, skipSpent: true, biggerThan: -1, - smallerThan: constants.MAX_OUTPUT_VALUE + 1, + smallerThan: constants.MAX_OUTPUT_VALUE + 1n, ...filters, }; @@ -2452,7 +2453,7 @@ export const mapDbResultToDbTxOutput = (result: any): DbTxOutput => ({ index: result.index as number, tokenId: result.token_id as string, address: result.address as string, - value: result.value as number, + value: BigInt(result.value), authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, diff --git a/packages/wallet-service/src/db/utils.ts b/packages/wallet-service/src/db/utils.ts index df7f3442..fae728d5 100644 --- a/packages/wallet-service/src/db/utils.ts +++ b/packages/wallet-service/src/db/utils.ts @@ -152,7 +152,10 @@ export class FromTokenBalanceMapToBalanceValueList { } export const sortBalanceValueByAbsTotal = (balanceA: TokenBalanceValue, balanceB: TokenBalanceValue): number => { - if (Math.abs(balanceA.total) - Math.abs(balanceB.total) >= 0) return -1; + function abs(num: bigint) { + return num >= 0n ? num : -num; + } + if (abs(balanceA.total) - abs(balanceB.total) >= 0n) return -1; return 0; }; diff --git a/packages/wallet-service/src/fullnode.ts b/packages/wallet-service/src/fullnode.ts index 3e024ed2..a812e1d7 100644 --- a/packages/wallet-service/src/fullnode.ts +++ b/packages/wallet-service/src/fullnode.ts @@ -6,7 +6,6 @@ */ import axios from 'axios'; -import Joi from 'joi'; import config from '@src/config'; import { FullNodeApiVersionResponse } from '@src/types'; import { FullnodeVersionSchema } from '@src/schemas'; diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index 890fff83..4e46dba9 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -204,12 +204,12 @@ export class Authorities { array: number[]; - constructor(authorities?: number | number[]) { + constructor(authorities?: bigint | number | number[]) { let tmp = []; if (authorities instanceof Array) { tmp = authorities; } else if (authorities != null) { - tmp = Authorities.intToArray(authorities); + tmp = Authorities.intToArray(Number(authorities)); } this.array = new Array(Authorities.LENGTH - tmp.length).fill(0).concat(tmp); @@ -316,11 +316,11 @@ export class Authorities { } export class Balance { - totalAmountSent: number; + totalAmountSent: bigint; - lockedAmount: number; + lockedAmount: bigint; - unlockedAmount: number; + unlockedAmount: bigint; lockedAuthorities: Authorities; @@ -328,7 +328,7 @@ export class Balance { lockExpires: number | null; - constructor(totalAmountSent = 0, unlockedAmount = 0, lockedAmount = 0, lockExpires = null, unlockedAuthorities = null, lockedAuthorities = null) { + constructor(totalAmountSent = 0n, unlockedAmount = 0n, lockedAmount = 0n, lockExpires = null, unlockedAuthorities = null, lockedAuthorities = null) { this.totalAmountSent = totalAmountSent; this.unlockedAmount = unlockedAmount; this.lockedAmount = lockedAmount; @@ -342,7 +342,7 @@ export class Balance { * * @returns The total balance */ - total(): number { + total(): bigint { return this.unlockedAmount + this.lockedAmount; } @@ -404,13 +404,13 @@ export class Balance { export type TokenBalanceValue = { tokenId: string, tokenSymbol: string, - totalAmountSent: number; - lockedAmount: number; - unlockedAmount: number; + totalAmountSent: bigint; + lockedAmount: bigint; + unlockedAmount: bigint; lockedAuthorities: Record; unlockedAuthorities: Record; lockExpires: number | null; - total: number; + total: bigint; } export class WalletTokenBalance { @@ -460,7 +460,7 @@ export class TokenBalanceMap { get(tokenId: string): Balance { // if the token is not present, return 0 instead of undefined - return this.map[tokenId] || new Balance(0, 0, 0); + return this.map[tokenId] || new Balance(0n, 0n, 0n); } set(tokenId: string, balance: Balance): void { @@ -499,10 +499,10 @@ export class TokenBalanceMap { * @param tokenBalanceMap - The js object to convert to a TokenBalanceMap * @returns - The new TokenBalanceMap object */ - static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { + static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { const obj = new TokenBalanceMap(); for (const [tokenId, balance] of Object.entries(tokenBalanceMap)) { - obj.set(tokenId, new Balance(balance.totalSent as number, balance.unlocked as number, balance.locked as number, balance.lockExpires || null, + obj.set(tokenId, new Balance(balance.totalSent as bigint, balance.unlocked as bigint, balance.locked as bigint, balance.lockExpires || null, balance.unlockedAuthorities, balance.lockedAuthorities)); } return obj; @@ -540,14 +540,14 @@ export class TokenBalanceMap { if (output.locked) { if (isAuthority(output.token_data)) { - obj.set(token, new Balance(0, 0, 0, output.decoded.timelock, 0, new Authorities(output.value))); + obj.set(token, new Balance(0n, 0n, 0n, output.decoded.timelock, 0, new Authorities(output.value))); } else { - obj.set(token, new Balance(value, 0, value, output.decoded.timelock, 0, 0)); + obj.set(token, new Balance(value, 0n, value, output.decoded.timelock, 0, 0)); } } else if (isAuthority(output.token_data)) { - obj.set(token, new Balance(0, 0, 0, null, new Authorities(output.value), 0)); + obj.set(token, new Balance(0n, 0n, 0n, null, new Authorities(output.value), 0)); } else { - obj.set(token, new Balance(value, value, 0, null)); + obj.set(token, new Balance(value, value, 0n, null)); } return obj; @@ -569,9 +569,9 @@ export class TokenBalanceMap { if (isAuthority(input.token_data)) { // for inputs, the authorities will have a value of -1 when set const authorities = new Authorities(input.value); - obj.set(token, new Balance(0, 0, 0, null, authorities.toNegative(), new Authorities(0))); + obj.set(token, new Balance(0n, 0n, 0n, null, authorities.toNegative(), new Authorities(0))); } else { - obj.set(token, new Balance(0, -input.value, 0, null)); + obj.set(token, new Balance(0n, -input.value, 0n, null)); } return obj; } @@ -651,7 +651,7 @@ export interface DbTxOutput { index: number; tokenId: string; address: string; - value: number; + value: bigint; authorities: number; timelock: number | null; heightlock: number | null; diff --git a/packages/wallet-service/tests/commons.test.ts b/packages/wallet-service/tests/commons.test.ts index 9e551a59..90d1942d 100644 --- a/packages/wallet-service/tests/commons.test.ts +++ b/packages/wallet-service/tests/commons.test.ts @@ -211,7 +211,7 @@ test('getWalletBalanceMap', () => { test('unlockUtxos', async () => { expect.hasAssertions(); - const reward = 6400; + const reward = 6400n; const txId1 = 'txId1'; const txId2 = 'txId2'; const txId3 = 'txId3'; @@ -252,7 +252,7 @@ test('unlockUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 2500, + value: 2500n, authorities: 0, timelock: now, heightlock: null, @@ -263,7 +263,7 @@ test('unlockUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 2500, + value: 2500n, authorities: 0, timelock: now * 2, heightlock: null, @@ -274,7 +274,7 @@ test('unlockUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 0, + value: 0n, authorities: 0b10, timelock: now * 3, heightlock: null, @@ -301,14 +301,14 @@ test('unlockUtxos', async () => { }]); await addToAddressBalanceTable(mysql, [ - [addr, token, 0, 2 * reward + 5000, now, 5, 0, 0b10, 4 * reward + 5000], + [addr, token, 0, 2n * reward + 5000n, now, 5, 0, 0b10, 4n * reward + 5000n], ]); await addToWalletBalanceTable(mysql, [{ walletId, tokenId: token, - unlockedBalance: 0, - lockedBalance: 2 * reward + 5000, + unlockedBalance: 0n, + lockedBalance: 2n * reward + 5000n, unlockedAuthorities: 0, lockedAuthorities: 0b10, timelockExpires: now, @@ -332,8 +332,8 @@ test('unlockUtxos', async () => { await expect( checkUtxoTable(mysql, 5, txId1, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, reward, reward + 5000, now, 5, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, reward, reward + 5000, now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, reward, reward + 5000n, now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, reward, reward + 5000n, now, 5, 0, 0b10)).resolves.toBe(true); // unlock txId2 utxo.txId = txId2; @@ -342,8 +342,8 @@ test('unlockUtxos', async () => { await expect( checkUtxoTable(mysql, 5, txId2, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2 * reward, 5000, now, 5, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2 * reward, 5000, now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2n * reward, 5000n, now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2n * reward, 5000n, now, 5, 0, 0b10)).resolves.toBe(true); // unlock txId3, txId4 is still locked utxo.txId = txId3; @@ -354,8 +354,8 @@ test('unlockUtxos', async () => { await expect( checkUtxoTable(mysql, 5, txId3, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2 * reward + 2500, 2500, 2 * now, 5, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2 * reward + 2500, 2500, 2 * now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2n * reward + 2500n, 2500n, 2 * now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2n * reward + 2500n, 2500n, 2 * now, 5, 0, 0b10)).resolves.toBe(true); // unlock txId4 utxo.txId = txId4; @@ -366,8 +366,8 @@ test('unlockUtxos', async () => { await expect( checkUtxoTable(mysql, 5, txId4, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2 * reward + 5000, 0, 3 * now, 5, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2 * reward + 5000, 0, 3 * now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2n * reward + 5000n, 0n, 3 * now, 5, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2n * reward + 5000n, 0n, 3 * now, 5, 0, 0b10)).resolves.toBe(true); // unlock txId5 utxo.txId = txId5; @@ -379,8 +379,8 @@ test('unlockUtxos', async () => { await expect( checkUtxoTable(mysql, 5, txId5, 0, utxo.tokenId, utxo.address, utxo.value, utxo.authorities, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2 * reward + 5000, 0, null, 5, 0b10, 0)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2 * reward + 5000, 0, null, 5, 0b10, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2n * reward + 5000n, 0n, null, 5, 0b10, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2n * reward + 5000n, 0n, null, 5, 0b10, 0)).resolves.toBe(true); }); test('unlockTimelockedUtxos', async () => { @@ -482,8 +482,8 @@ test('unlockTimelockedUtxos', async () => { await expect( checkUtxoTable(mysql, 3, txId1, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2500, 2500, 2 * now, 3, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2500, 2500, 2 * now, 3, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 2500n, 2500n, 2 * now, 3, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 2500n, 2500n, 2 * now, 3, 0, 0b10)).resolves.toBe(true); // unlock txId2 utxo.txId = txId2; @@ -494,8 +494,8 @@ test('unlockTimelockedUtxos', async () => { await expect( checkUtxoTable(mysql, 3, txId2, 0, utxo.tokenId, utxo.address, utxo.value, 0, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 5000, 0, 3 * now, 3, 0, 0b10)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 5000, 0, 3 * now, 3, 0, 0b10)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 5000n, 0n, 3 * now, 3, 0, 0b10)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 5000n, 0n, 3 * now, 3, 0, 0b10)).resolves.toBe(true); // unlock txId3 utxo.txId = txId3; @@ -507,8 +507,8 @@ test('unlockTimelockedUtxos', async () => { await expect( checkUtxoTable(mysql, 3, txId3, 0, utxo.tokenId, utxo.address, utxo.value, utxo.authorities, utxo.timelock, utxo.heightlock, false), ).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 1, addr, token, 5000, 0, null, 3, 0b10, 0)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 5000, 0, null, 3, 0b10, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 1, addr, token, 5000n, 0n, null, 3, 0b10, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token, 5000n, 0n, null, 3, 0b10, 0)).resolves.toBe(true); }); test('getFullnodeData with an uninitialized version_data database should call the version api', async () => { diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 857e85e3..60be3bb9 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -762,10 +762,10 @@ test('updateAddressTablesWithTx', async () => { await updateAddressTablesWithTx(mysql, txId1, timestamp1, addrMap1); await expect(checkAddressTable(mysql, 2, address1, null, null, 2)).resolves.toBe(true); await expect(checkAddressTable(mysql, 2, address2, null, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token1, 10, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token2, 7, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address1, token3, 2, 0, null, 1, 0b01, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 4, address2, token1, 8, 0, null, 1, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token1, 10n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token2, 7n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address1, token3, 2n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 4, address2, token1, 8n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token1, 10, timestamp1)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token2, 7, timestamp1)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 4, address1, txId1, token3, 2, timestamp1)).resolves.toBe(true); @@ -785,11 +785,11 @@ test('updateAddressTablesWithTx', async () => { await expect(checkAddressTable(mysql, 2, address1, null, null, 3)).resolves.toBe(true); await expect(checkAddressTable(mysql, 2, address2, null, null, 2)).resolves.toBe(true); // final balance for each (address,token) - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 0, null, 2)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token2', 7, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token3', 8, 0, null, 2, 0, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address2, 'token1', 16, 0, null, 2, 0b11, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 5, address2, 'token2', 3, 0, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 0n, null, 2)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token2', 7n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token3', 8n, 0n, null, 2, 0, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address2, 'token1', 16n, 0n, null, 2, 0b11, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address2, 'token2', 3n, 0n, null, 1)).resolves.toBe(true); // tx history await expect(checkAddressTxHistoryTable(mysql, 8, address1, txId2, token1, -5, timestamp2)).resolves.toBe(true); await expect(checkAddressTxHistoryTable(mysql, 8, address1, txId2, token3, 6, timestamp2)).resolves.toBe(true); @@ -809,7 +809,7 @@ test('updateAddressTablesWithTx', async () => { address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 3, lockExpires } }), }; await updateAddressTablesWithTx(mysql, txId3, timestamp3, addrMap3); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 3, lockExpires, 3)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 3n, lockExpires, 3)).resolves.toBe(true); // another tx, with higher timelock const txId4 = 'txId4'; @@ -818,7 +818,7 @@ test('updateAddressTablesWithTx', async () => { address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 2, lockExpires: lockExpires + 1 } }), }; await updateAddressTablesWithTx(mysql, txId4, timestamp4, addrMap4); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 5, lockExpires, 4)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 5n, lockExpires, 4)).resolves.toBe(true); // another tx, with lower timelock const txId5 = 'txId5'; @@ -827,7 +827,7 @@ test('updateAddressTablesWithTx', async () => { address1: TokenBalanceMap.fromStringMap({ token1: { unlocked: 0, locked: 2, lockExpires: lockExpires - 1 } }), }; await updateAddressTablesWithTx(mysql, txId5, timestamp5, addrMap5); - await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5, 7, lockExpires - 1, 5)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 5, address1, 'token1', 5n, 7n, lockExpires - 1, 5)).resolves.toBe(true); }); test('getWalletTokens', async () => { @@ -1070,9 +1070,9 @@ test('updateAddressLockedBalance', async () => { const addr1Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 10, locked: 0, unlockedAuthorities: new Authorities(0b01) } }); const addr2Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 5, locked: 0 } }); await updateAddressLockedBalance(mysql, { [addr1]: addr1Map, [addr2]: addr2Map }); - await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60, 10, null, 3, 0b01, 0)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 3, addr2, tokenId, 5, 0, null, 1)).resolves.toBe(true); - await expect(checkAddressBalanceTable(mysql, 3, addr1, otherToken, 5, 5, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60n, 10n, null, 3, 0b01, 0)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr2, tokenId, 5n, 0n, null, 1)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, otherToken, 5n, 5n, null, 1)).resolves.toBe(true); // now pretend there's another locked authority, so final balance of locked authorities should be updated accordingly await addToUtxoTable(mysql, [{ @@ -1089,7 +1089,7 @@ test('updateAddressLockedBalance', async () => { }]); const newMap = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 0, locked: 0, unlockedAuthorities: new Authorities(0b10) } }); await updateAddressLockedBalance(mysql, { [addr1]: newMap }); - await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60, 10, null, 3, 0b11, 0b01)).resolves.toBe(true); + await expect(checkAddressBalanceTable(mysql, 3, addr1, tokenId, 60n, 10n, null, 3, 0b11, 0b01)).resolves.toBe(true); }); test('updateWalletLockedBalance', async () => { diff --git a/packages/wallet-service/tests/integration.test.ts b/packages/wallet-service/tests/integration.test.ts index e56d2d30..3511d4ac 100644 --- a/packages/wallet-service/tests/integration.test.ts +++ b/packages/wallet-service/tests/integration.test.ts @@ -14,7 +14,6 @@ import { AUTH_XPUBKEY, cleanDatabase, checkAddressTable, - checkAddressBalanceTable, checkAddressTxHistoryTable, checkUtxoTable, checkWalletBalanceTable, diff --git a/packages/wallet-service/tests/types.ts b/packages/wallet-service/tests/types.ts index 2bf07dbe..8fdf5601 100644 --- a/packages/wallet-service/tests/types.ts +++ b/packages/wallet-service/tests/types.ts @@ -10,8 +10,8 @@ export interface WalletBalanceEntry { walletId: string; tokenId: string; - unlockedBalance: number; - lockedBalance: number; + unlockedBalance: bigint; + lockedBalance: bigint; unlockedAuthorities: number; lockedAuthorities: number; timelockExpires?: number; diff --git a/packages/wallet-service/tests/utils.ts b/packages/wallet-service/tests/utils.ts index 8342ef85..2cdf3b76 100644 --- a/packages/wallet-service/tests/utils.ts +++ b/packages/wallet-service/tests/utils.ts @@ -84,7 +84,7 @@ export const cleanDatabase = async (mysql: ServerlessMysql): Promise => { export const createOutput = ( index: number, - value: number, + value: bigint, address: string, token = '00', timelock: number = null, @@ -109,7 +109,7 @@ export const createOutput = ( ); export const createInput = ( - value: number, + value: bigint, address: string, txId: string, index: number, @@ -139,7 +139,7 @@ export const checkUtxoTable = async ( index?: number, tokenId?: string, address?: string, - value?: number, + value?: bigint, authorities?: number, timelock?: number | null, heightlock?: number | null, @@ -239,8 +239,8 @@ export const checkAddressBalanceTable = async ( totalResults: number, address: string, tokenId: string, - unlocked: number, - locked: number, + unlocked: bigint, + locked: bigint, lockExpires: number | null, transactions: number, unlockedAuthorities = 0, @@ -438,8 +438,8 @@ export const checkWalletBalanceTable = async ( totalResults: number, walletId?: string, tokenId?: string, - unlocked?: number, - locked?: number, + unlocked?: bigint, + locked?: bigint, lockExpires?: number | null, transactions?: number, unlockedAuthorities = 0, diff --git a/packages/wallet-service/tsconfig.json b/packages/wallet-service/tsconfig.json index f5098fa9..0cb0e837 100644 --- a/packages/wallet-service/tsconfig.json +++ b/packages/wallet-service/tsconfig.json @@ -1,13 +1,13 @@ { "compilerOptions": { - "lib": ["es2017"], + "lib": ["es2020", "esnext"], "removeComments": true, "moduleResolution": "node", "module": "commonjs", "noUnusedLocals": false, "noUnusedParameters": false, "sourceMap": true, - "target": "es2017", + "target": "es2020", "outDir": "./dist", "inlineSources": true, "esModuleInterop": true, From 6dcf0517126b2db83f3cc163d47b0f871a615bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Mon, 31 Mar 2025 15:17:23 -0300 Subject: [PATCH 07/31] tests: fix issues caused by bigint support and typing --- .../common/__tests__/events/nftCreationTx.ts | 12 +- .../common/__tests__/utils/nft.utils.test.ts | 20 +- packages/common/src/types.ts | 20 +- .../__tests__/actors/HealthCheckActor.test.ts | 1 - .../daemon/__tests__/guards/guards.test.ts | 2 +- .../daemon/__tests__/utils/wallet.test.ts | 6 +- packages/daemon/src/db/index.ts | 6 +- packages/wallet-service/src/types.ts | 2 +- packages/wallet-service/tests/api.test.ts | 60 ++-- packages/wallet-service/tests/commons.test.ts | 118 +++---- packages/wallet-service/tests/db.test.ts | 306 +++++++++--------- .../wallet-service/tests/integration.test.ts | 23 +- packages/wallet-service/tests/mempool.test.ts | 20 +- packages/wallet-service/tests/txById.test.ts | 4 +- .../wallet-service/tests/txOutputs.test.ts | 62 ++-- .../wallet-service/tests/txProposal.test.ts | 192 +++++------ packages/wallet-service/tests/types.test.ts | 44 +-- packages/wallet-service/tests/types.ts | 2 +- packages/wallet-service/tests/utils.ts | 8 +- 19 files changed, 443 insertions(+), 465 deletions(-) diff --git a/packages/common/__tests__/events/nftCreationTx.ts b/packages/common/__tests__/events/nftCreationTx.ts index 4fcd98bb..f07cdd15 100644 --- a/packages/common/__tests__/events/nftCreationTx.ts +++ b/packages/common/__tests__/events/nftCreationTx.ts @@ -28,7 +28,7 @@ export const nftCreationTx = { is_voided: false, inputs: [ { - value: 100, + value: 100n, token_data: 0, script: 'dqkUaf+xVJ8uAPML/AzwuSB+2W9/M7qIrA==', decoded: { @@ -43,7 +43,7 @@ export const nftCreationTx = { ], outputs: [ { - value: 1, + value: 1n, token_data: 0, // Decoded script: 5ipfs://QmPCSXNDyPdhU9oQFpxFsNN3nTjg9ZoqESKY5n9Gp1XSJc script: 'NWlwZnM6Ly9RbVBDU1hORHlQZGhVOW9RRnB4RnNOTjNuVGpnOVpvcUVTS1k1bjlHcDFYU0pjrA==', @@ -53,7 +53,7 @@ export const nftCreationTx = { selected_as_input: false, }, { - value: 98, + value: 98n, token_data: 0, script: 'dqkUQcQx/3rV1s5VZXqZPc1dkQbPo6eIrA==', decoded: { @@ -65,7 +65,7 @@ export const nftCreationTx = { spent_by: null, }, { - value: 1, + value: 1n, token_data: 1, script: 'dqkUQcQx/3rV1s5VZXqZPc1dkQbPo6eIrA==', decoded: { @@ -77,7 +77,7 @@ export const nftCreationTx = { spent_by: null, }, { - value: 1, + value: 1n, token_data: 129, script: 'dqkU1YP+t130UoYD+3ys9MYt1zkWeY6IrA==', decoded: { @@ -89,7 +89,7 @@ export const nftCreationTx = { spent_by: null, }, { - value: 2, + value: 2n, token_data: 129, script: 'dqkULlcsARvA+pQS8qytBr6Ryjc/SLeIrA==', decoded: { diff --git a/packages/common/__tests__/utils/nft.utils.test.ts b/packages/common/__tests__/utils/nft.utils.test.ts index 6b52f4b9..e47a6834 100644 --- a/packages/common/__tests__/utils/nft.utils.test.ts +++ b/packages/common/__tests__/utils/nft.utils.test.ts @@ -56,7 +56,7 @@ const REAL_NFT_EVENT_DATA = { 'tx_id': '00000000ba6f3fc01a3e8561f2905c50c98422e7112604a8971bdaba1535e797', 'index': 1, 'spent_output': { - 'value': 4, + 'value': 4n, 'token_data': 0, 'script': 'dqkUWDMJLPqtb9X+jPcBSP6WLg6NIC6IrA==', 'decoded': { @@ -69,13 +69,13 @@ const REAL_NFT_EVENT_DATA = { ], 'outputs': [ { - 'value': 1, + 'value': 1n, 'token_data': 0, 'script': 'C2lwZnM6Ly8xMTExrA==', 'decoded': null }, { - 'value': 2, + 'value': 2n, 'token_data': 0, 'script': 'dqkUFUs/hBsLnxy5Jd94WWV24BCmIhmIrA==', 'decoded': { @@ -85,7 +85,7 @@ const REAL_NFT_EVENT_DATA = { } }, { - 'value': 1, + 'value': 1n, 'token_data': 1, 'script': 'dqkUhM3YhAjNc5p/oqX+yqEYcX+miNmIrA==', 'decoded': { @@ -475,7 +475,7 @@ describe('transaction transformation compatibility', () => { index: 0, spent_output: { token_data: (1 & hathorLib.constants.TOKEN_INDEX_MASK) + 1, // First token - value: 100, + value: 100n, script: 'script1', decoded: { type: 'P2PKH', @@ -486,7 +486,7 @@ describe('transaction transformation compatibility', () => { }], outputs: [{ token_data: (0 & hathorLib.constants.TOKEN_INDEX_MASK) + 1, // HTR token - value: 100, + value: 100n, script: 'script2', decoded: { type: 'P2PKH', @@ -632,7 +632,7 @@ describe('processNftEvent', () => { tx_id: '00000000ba6f3fc01a3e8561f2905c50c98422e7112604a8971bdaba1535e797', index: 1, spent_output: { - value: 4, + value: 4n, token_data: 0, script: 'dqkUWDMJLPqtb9X+jPcBSP6WLg6NIC6IrA==', decoded: { @@ -645,13 +645,13 @@ describe('processNftEvent', () => { ], outputs: [ { - value: 1, + value: 1n, token_data: 0, script: 'C2lwZnM6Ly8xMTExrA==', decoded: null }, { - value: 2, + value: 2n, token_data: 0, script: 'dqkUFUs/hBsLnxy5Jd94WWV24BCmIhmIrA==', decoded: { @@ -661,7 +661,7 @@ describe('processNftEvent', () => { } }, { - value: 1, + value: 1n, token_data: 1, script: 'dqkUhM3YhAjNc5p/oqX+yqEYcX+miNmIrA==', decoded: { diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index c1f3b7a8..6c7fbbd4 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -285,7 +285,6 @@ export class Balance { b1.totalAmountSent + b2.totalAmountSent, b1.unlockedAmount + b2.unlockedAmount, b1.lockedAmount + b2.lockedAmount, - // @ts-ignore lockExpires, Authorities.merge(b1.unlockedAuthorities, b2.unlockedAuthorities), Authorities.merge(b1.lockedAuthorities, b2.lockedAuthorities), @@ -390,15 +389,12 @@ export class TokenBalanceMap { if (output.locked) { if (isAuthority(output.token_data)) { - // @ts-ignore - obj.set(token, new Balance(0, 0, 0, output.decoded.timelock, 0, new Authorities(output.value))); + obj.set(token, new Balance(0n, 0n, 0n, output.decoded.timelock, new Authorities(0), new Authorities(output.value))); } else { - // @ts-ignore - obj.set(token, new Balance(value, 0, value, output.decoded.timelock, 0, 0)); + obj.set(token, new Balance(value, 0n, value, output.decoded.timelock, new Authorities(0), new Authorities(0))); } } else if (isAuthority(output.token_data)) { - // @ts-ignore - obj.set(token, new Balance(0, 0, 0, null, new Authorities(output.value), 0)); + obj.set(token, new Balance(0n, 0n, 0n, null, new Authorities(output.value), new Authorities(0))); } else { obj.set(token, new Balance(value, value, 0n, null)); } @@ -424,15 +420,7 @@ export class TokenBalanceMap { const authorities = new Authorities(input.value); obj.set( token, - new Balance( - 0n, - 0n, - 0n, - null, - // @ts-ignore - authorities.toNegative(), - new Authorities(0), - ), + new Balance(0n, 0n, 0n, null, authorities.toNegative(), new Authorities(0)), ); } else { obj.set(token, new Balance(0n, -input.value, 0n, null)); diff --git a/packages/daemon/__tests__/actors/HealthCheckActor.test.ts b/packages/daemon/__tests__/actors/HealthCheckActor.test.ts index 04b50257..1b393e95 100644 --- a/packages/daemon/__tests__/actors/HealthCheckActor.test.ts +++ b/packages/daemon/__tests__/actors/HealthCheckActor.test.ts @@ -3,7 +3,6 @@ import axios from 'axios'; import logger from '../../src/logger'; import { EventTypes } from '../../src/types/event'; import getConfig from '../../src/config'; -import { get } from 'lodash'; jest.useFakeTimers(); jest.spyOn(global, 'setInterval'); diff --git a/packages/daemon/__tests__/guards/guards.test.ts b/packages/daemon/__tests__/guards/guards.test.ts index 77f61376..420038e2 100644 --- a/packages/daemon/__tests__/guards/guards.test.ts +++ b/packages/daemon/__tests__/guards/guards.test.ts @@ -1,4 +1,4 @@ -import { Context, Event, FullNodeEventTypes, FullNodeEvent, StandardFullNodeEvent } from '../../src/types'; +import { Context, Event, FullNodeEventTypes, StandardFullNodeEvent } from '../../src/types'; import { metadataIgnore, metadataVoided, diff --git a/packages/daemon/__tests__/utils/wallet.test.ts b/packages/daemon/__tests__/utils/wallet.test.ts index 4d60c86e..1cf4b0d1 100644 --- a/packages/daemon/__tests__/utils/wallet.test.ts +++ b/packages/daemon/__tests__/utils/wallet.test.ts @@ -15,13 +15,13 @@ import { prepareOutputs } from '../../src/utils'; describe('prepareOutputs', () => { it('should ignore NFT outputs', () => { const nftOutputs: EventTxOutput[] = [{ - value: 1, + value: 1n, token_data: 0, script: 'OmlwZnM6Ly9pcGZzL1FtTlJtNmhRUDN2MlVMclVOZTJQTTY4V1dRb2EyUmVwY1IxejVUVVdWZmd0bzGs', // @ts-expect-error: This type is wrong, we should allow null here in the type decoded: null }, { - value: 2116, + value: 2116n, token_data: 0, script: 'dqkUCU1EY3YLi8WURhDOEsspok4Y0XiIrA==', decoded: { @@ -30,7 +30,7 @@ describe('prepareOutputs', () => { timelock: null, } }, { - value: 1, + value: 1n, token_data: 1, script: 'dqkUXO7BFkikXo2qwldGMeJlzyPSbtKIrA==', decoded: { diff --git a/packages/daemon/src/db/index.ts b/packages/daemon/src/db/index.ts index ba491a6a..44d4c5f5 100644 --- a/packages/daemon/src/db/index.ts +++ b/packages/daemon/src/db/index.ts @@ -348,8 +348,7 @@ export const getTxOutputsAtHeight = async ( authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - // @ts-ignore - locked: result.locked > 0, + locked: Number(result.locked) > 0, spentBy: result.spent_by as string, txProposalId: result.tx_proposal as string, txProposalIndex: result.tx_proposal_index as number, @@ -662,8 +661,7 @@ export const getUtxosLockedAtHeight = async ( authorities: result.authorities as number, timelock: result.timelock as number, heightlock: result.heightlock as number, - // @ts-ignore - locked: result.locked > 0, + locked: Number(result.locked) > 0, }; utxos.push(utxo); } diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index 4e46dba9..c9d0b197 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -499,7 +499,7 @@ export class TokenBalanceMap { * @param tokenBalanceMap - The js object to convert to a TokenBalanceMap * @returns - The new TokenBalanceMap object */ - static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { + static fromStringMap(tokenBalanceMap: StringMap>): TokenBalanceMap { const obj = new TokenBalanceMap(); for (const [tokenId, balance] of Object.entries(tokenBalanceMap)) { obj.set(tokenId, new Balance(balance.totalSent as bigint, balance.unlocked as bigint, balance.locked as bigint, balance.lockExpires || null, diff --git a/packages/wallet-service/tests/api.test.ts b/packages/wallet-service/tests/api.test.ts index 260457f7..9255653f 100644 --- a/packages/wallet-service/tests/api.test.ts +++ b/packages/wallet-service/tests/api.test.ts @@ -457,8 +457,8 @@ test('GET /balances', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 10, - lockedBalance: 0, + unlockedBalance: 10n, + lockedBalance: 0n, unlockedAuthorities: 0b01, lockedAuthorities: 0b10, timelockExpires: null, @@ -466,8 +466,8 @@ test('GET /balances', async () => { }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 3, - lockedBalance: 2, + unlockedBalance: 3n, + lockedBalance: 2n, unlockedAuthorities: 0b00, lockedAuthorities: 0b11, timelockExpires: lockExpires, @@ -523,8 +523,8 @@ test('GET /balances', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token3', - unlockedBalance: 5, - lockedBalance: 1, + unlockedBalance: 5n, + lockedBalance: 1n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: lockExpires2, @@ -535,7 +535,7 @@ test('GET /balances', async () => { index: 0, tokenId: 'token3', address: ADDRESSES[0], - value: 1, + value: 1n, authorities: 0, timelock: lockExpires2, heightlock: null, @@ -561,8 +561,8 @@ test('GET /balances', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token4', - unlockedBalance: 10, - lockedBalance: 5, + unlockedBalance: 10n, + lockedBalance: 5n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: lockExpires2, @@ -573,7 +573,7 @@ test('GET /balances', async () => { index: 0, tokenId: 'token4', address: ADDRESSES[0], - value: 3, + value: 3n, authorities: 0, timelock: lockExpires2, heightlock: null, @@ -584,7 +584,7 @@ test('GET /balances', async () => { index: 0, tokenId: 'token4', address: ADDRESSES[0], - value: 2, + value: 2n, authorities: 0, timelock: lockExpires, heightlock: null, @@ -609,8 +609,8 @@ test('GET /balances', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: '00', - unlockedBalance: 10, - lockedBalance: 0, + unlockedBalance: 10n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1477,7 +1477,7 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 0, tokenId: token1.id, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1489,8 +1489,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 1, tokenId: token1.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: null, heightlock: null, locked: false, @@ -1501,8 +1501,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 2, tokenId: token1.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: null, heightlock: null, locked: false, @@ -1513,7 +1513,7 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 0, tokenId: token2.id, address: ADDRESSES[0], - value: 250, + value: 250n, authorities: 0, timelock: null, heightlock: null, @@ -1525,8 +1525,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 1, tokenId: token2.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: 1000, heightlock: null, locked: true, @@ -1537,8 +1537,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 2, tokenId: token2.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: 1000, heightlock: null, locked: true, @@ -1548,8 +1548,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 0, tokenId: token2.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: null, heightlock: null, locked: false, @@ -1560,8 +1560,8 @@ test('GET /wallet/tokens/token_id/details', async () => { index: 1, tokenId: token2.id, address: ADDRESSES[0], - value: 0, - authorities: constants.TOKEN_MELT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MELT_MASK), timelock: null, heightlock: null, locked: false, @@ -1569,9 +1569,9 @@ test('GET /wallet/tokens/token_id/details', async () => { }]); await addToAddressTxHistoryTable(mysql, [ - { address: ADDRESSES[0], txId: 'txId', tokenId: token1.id, balance: 100, timestamp: 0 }, - { address: ADDRESSES[0], txId: 'txId2', tokenId: token2.id, balance: 250, timestamp: 0 }, - { address: ADDRESSES[0], txId: 'txId3', tokenId: token2.id, balance: 0, timestamp: 0 }, + { address: ADDRESSES[0], txId: 'txId', tokenId: token1.id, balance: 100n, timestamp: 0 }, + { address: ADDRESSES[0], txId: 'txId2', tokenId: token2.id, balance: 250n, timestamp: 0 }, + { address: ADDRESSES[0], txId: 'txId3', tokenId: token2.id, balance: 0n, timestamp: 0 }, ]); event = makeGatewayEventWithAuthorizer('my-wallet', { token_id: token1.id }); diff --git a/packages/wallet-service/tests/commons.test.ts b/packages/wallet-service/tests/commons.test.ts index 90d1942d..22b86bee 100644 --- a/packages/wallet-service/tests/commons.test.ts +++ b/packages/wallet-service/tests/commons.test.ts @@ -80,22 +80,22 @@ test('markLockedOutputs and getAddressBalanceMap', () => { tx.tx_id = 'txId1'; tx.timestamp = 0; tx.inputs = [ - createInput(10, 'address1', 'inputTx', 0, 'token1'), - createInput(5, 'address1', 'inputTx', 0, 'token1'), - createInput(7, 'address1', 'inputTx', 1, 'token2'), - createInput(3, 'address2', 'inputTx', 2, 'token1'), + createInput(10n, 'address1', 'inputTx', 0, 'token1'), + createInput(5n, 'address1', 'inputTx', 0, 'token1'), + createInput(7n, 'address1', 'inputTx', 1, 'token2'), + createInput(3n, 'address2', 'inputTx', 2, 'token1'), ]; tx.outputs = [ - createOutput(0, 5, 'address1', 'token1'), - createOutput(1, 2, 'address1', 'token3'), - createOutput(2, 11, 'address2', 'token1'), + createOutput(0, 5n, 'address1', 'token1'), + createOutput(1, 2n, 'address1', 'token3'), + createOutput(2, 11n, 'address2', 'token1'), ]; const map1 = new TokenBalanceMap(); - map1.set('token1', new Balance(5, -10, 0)); - map1.set('token2', new Balance(0, -7, 0)); - map1.set('token3', new Balance(2, 2, 0)); + map1.set('token1', new Balance(5n, -10n, 0n)); + map1.set('token2', new Balance(0n, -7n, 0n)); + map1.set('token3', new Balance(2n, 2n, 0n)); const map2 = new TokenBalanceMap(); - map2.set('token1', new Balance(11, 8, 0)); + map2.set('token1', new Balance(11n, 8n, 0n)); const expectedAddrMap = { address1: map1, address2: map2, @@ -121,14 +121,14 @@ test('markLockedOutputs and getAddressBalanceMap', () => { expect(tx.outputs[2].locked).toBe(true); // check balance - map2.set('token1', new Balance(11, -3, 11, now + 1)); + map2.set('token1', new Balance(11n, -3n, 11n, now + 1)); const addrMap2 = getAddressBalanceMap(tx.inputs, tx.outputs); expect(addrMap2).toStrictEqual(expectedAddrMap); // a block will have its rewards locked, even with no timelock tx.inputs = []; tx.outputs = [ - createOutput(0, 100, 'address1', 'token1'), + createOutput(0, 100n, 'address1', 'token1'), ]; markLockedOutputs(tx.outputs, now, true); for (const output of tx.outputs) { @@ -136,7 +136,7 @@ test('markLockedOutputs and getAddressBalanceMap', () => { } const addrMap3 = getAddressBalanceMap(tx.inputs, tx.outputs); const map3 = new TokenBalanceMap(); - map3.set('token1', new Balance(100, 0, 100)); + map3.set('token1', new Balance(100n, 0n, 100n)); const expectedAddrMap2 = { address1: map3, }; @@ -144,16 +144,16 @@ test('markLockedOutputs and getAddressBalanceMap', () => { // tx with authorities tx.inputs = [ - createInput(0b01, 'address1', 'inputTx', 0, 'token1', null, 129), - createInput(0b10, 'address1', 'inputTx', 1, 'token2', null, 129), + createInput(0b01n, 'address1', 'inputTx', 0, 'token1', null, 129), + createInput(0b10n, 'address1', 'inputTx', 1, 'token2', null, 129), ]; tx.outputs = [ - createOutput(0, 0b01, 'address1', 'token1', null, false, 129), - createOutput(1, 0b10, 'address1', 'token2', 1000, true, 129), + createOutput(0, 0b01n, 'address1', 'token1', null, false, 129), + createOutput(1, 0b10n, 'address1', 'token2', 1000, true, 129), ]; const map4 = new TokenBalanceMap(); - map4.set('token1', new Balance(0, 0, 0, null)); - map4.set('token2', new Balance(0, 0, 0, 1000, new Authorities([-1, 0]), new Authorities([1, 0]))); + map4.set('token1', new Balance(0n, 0n, 0n, null)); + map4.set('token2', new Balance(0n, 0n, 0n, 1000, new Authorities([-1, 0]), new Authorities([1, 0]))); const expectedAddrMap4 = { address1: map4, }; @@ -164,19 +164,19 @@ test('markLockedOutputs and getAddressBalanceMap', () => { test('getWalletBalanceMap', () => { expect.hasAssertions(); const mapAddress1 = new TokenBalanceMap(); - mapAddress1.set('token1', new Balance(1, -10, 0)); - mapAddress1.set('token2', new Balance(0, -7, 0)); - mapAddress1.set('token3', new Balance(27, 2, 0)); + mapAddress1.set('token1', new Balance(1n, -10n, 0n)); + mapAddress1.set('token2', new Balance(0n, -7n, 0n)); + mapAddress1.set('token3', new Balance(27n, 2n, 0n)); const mapAddress2 = new TokenBalanceMap(); - mapAddress2.set('token1', new Balance(10, 8, 0)); + mapAddress2.set('token1', new Balance(10n, 8n, 0n)); const mapAddress3 = new TokenBalanceMap(); - mapAddress3.set('token2', new Balance(4, 2, 0)); - mapAddress3.set('token3', new Balance(12, 6, 0)); + mapAddress3.set('token2', new Balance(4n, 2n, 0n)); + mapAddress3.set('token3', new Balance(12n, 6n, 0n)); const mapAddress4 = new TokenBalanceMap(); - mapAddress4.set('token1', new Balance(10, 2, 0)); - mapAddress4.set('token2', new Balance(14, 9, 1, 500)); + mapAddress4.set('token1', new Balance(10n, 2n, 0n)); + mapAddress4.set('token2', new Balance(14n, 9n, 1n, 500)); const mapAddress5 = new TokenBalanceMap(); - mapAddress5.set('token1', new Balance(20, 11, 0)); + mapAddress5.set('token1', new Balance(20n, 11n, 0n)); const addressBalanceMap = { address1: mapAddress1, address2: mapAddress2, @@ -191,12 +191,12 @@ test('getWalletBalanceMap', () => { address3: { walletId: 'wallet2', xpubkey: 'xpubkey2', authXpubkey: 'authxpubkey2', maxGap: 5 }, }; const mapWallet1 = new TokenBalanceMap(); - mapWallet1.set('token1', new Balance(21, 0, 0)); - mapWallet1.set('token2', new Balance(14, 2, 1, 500)); - mapWallet1.set('token3', new Balance(27, 2, 0)); + mapWallet1.set('token1', new Balance(21n, 0n, 0n)); + mapWallet1.set('token2', new Balance(14n, 2n, 1n, 500)); + mapWallet1.set('token3', new Balance(27n, 2n, 0n)); const mapWallet2 = new TokenBalanceMap(); - mapWallet2.set('token2', new Balance(4, 2, 0)); - mapWallet2.set('token3', new Balance(12, 6, 0)); + mapWallet2.set('token2', new Balance(4n, 2n, 0n)); + mapWallet2.set('token3', new Balance(12n, 6n, 0n)); const expectedWalletBalanceMap = { wallet1: mapWallet1, wallet2: mapWallet2, @@ -347,7 +347,7 @@ test('unlockUtxos', async () => { // unlock txId3, txId4 is still locked utxo.txId = txId3; - utxo.value = 2500; + utxo.value = 2500n; utxo.timelock = now; utxo.heightlock = null; await unlockUtxos(mysql, [utxo], true); @@ -359,7 +359,7 @@ test('unlockUtxos', async () => { // unlock txId4 utxo.txId = txId4; - utxo.value = 2500; + utxo.value = 2500n; utxo.timelock = now * 2; utxo.heightlock = null; await unlockUtxos(mysql, [utxo], true); @@ -371,7 +371,7 @@ test('unlockUtxos', async () => { // unlock txId5 utxo.txId = txId5; - utxo.value = 0; + utxo.value = 0n; utxo.authorities = 0b10; utxo.timelock = now * 3; utxo.heightlock = null; @@ -386,7 +386,7 @@ test('unlockUtxos', async () => { test('unlockTimelockedUtxos', async () => { expect.hasAssertions(); - const reward = 6400; + const reward = 6400n; const txId1 = 'txId1'; const txId2 = 'txId2'; const txId3 = 'txId3'; @@ -399,7 +399,7 @@ test('unlockTimelockedUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 2500, + value: 2500n, authorities: 0, timelock: now, heightlock: null, @@ -410,7 +410,7 @@ test('unlockTimelockedUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 2500, + value: 2500n, authorities: 0, timelock: now * 2, heightlock: null, @@ -421,7 +421,7 @@ test('unlockTimelockedUtxos', async () => { index: 0, tokenId: token, address: addr, - value: 0, + value: 0n, authorities: 0b10, timelock: now * 3, heightlock: null, @@ -453,8 +453,8 @@ test('unlockTimelockedUtxos', async () => { await addToWalletBalanceTable(mysql, [{ walletId, tokenId: token, - unlockedBalance: 0, - lockedBalance: 5000, + unlockedBalance: 0n, + lockedBalance: 5000n, unlockedAuthorities: 0, lockedAuthorities: 0b10, timelockExpires: now, @@ -475,7 +475,7 @@ test('unlockTimelockedUtxos', async () => { // unlock txId1, txId2 is still locked utxo.txId = txId1; - utxo.value = 2500; + utxo.value = 2500n; utxo.timelock = now; utxo.heightlock = null; await unlockTimelockedUtxos(mysql, now + 1); @@ -487,7 +487,7 @@ test('unlockTimelockedUtxos', async () => { // unlock txId2 utxo.txId = txId2; - utxo.value = 2500; + utxo.value = 2500n; utxo.timelock = now * 2; utxo.heightlock = null; await unlockTimelockedUtxos(mysql, (now * 2) + 1); @@ -499,7 +499,7 @@ test('unlockTimelockedUtxos', async () => { // unlock txId3 utxo.txId = txId3; - utxo.value = 0; + utxo.value = 0n; utxo.authorities = 0b10; utxo.timelock = now * 3; utxo.heightlock = null; @@ -652,8 +652,8 @@ describe('getWalletBalancesForTx', () => { // transaction base const utxos = [ - { index: 0, value: 5, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 1, value: 5, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 0, value: 5n, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 1, value: 5n, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, ]; // instantiate outputs @@ -736,8 +736,8 @@ describe('getWalletBalancesForTx', () => { // instantiate token balance const balanceToken1 = { - unlocked: 5, - locked: 0, + unlocked: 5n, + locked: 0n, lockExpires: null, transactions: 1, unlockedAuthorities: new Authorities(0b01), @@ -754,8 +754,8 @@ describe('getWalletBalancesForTx', () => { // transaction base const utxos = [ - { index: 0, value: 5, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 1, value: 5, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 0, value: 5n, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 1, value: 5n, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, ]; // instantiate outputs @@ -898,9 +898,9 @@ describe('getWalletBalancesForTx', () => { // transaction base const utxos = [ - { index: 0, value: 5, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 1, value: 5, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 2, value: 10, address: addr1, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 0, value: 5n, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 1, value: 5n, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 2, value: 10n, address: addr1, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, ]; // instantiate outputs @@ -1068,10 +1068,10 @@ describe('getWalletBalancesForTx', () => { // transaction base const utxos = [ - { index: 0, value: 5, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 1, value: 5, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 2, value: 10, address: addr1, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, - { index: 3, value: 10, address: addr2, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 0, value: 5n, address: addr1, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 1, value: 5n, address: addr2, tokenId: token1.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 2, value: 10n, address: addr1, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, + { index: 3, value: 10n, address: addr2, tokenId: token2.id, locked: false, timelock: null, tokenData: 0, spentBy: null }, ]; // instantiate outputs diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 60be3bb9..2ce4c9b0 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -426,14 +426,14 @@ test('initWalletTxHistory', async () => { await expect(checkWalletTxHistoryTable(mysql, 0)).resolves.toBe(true); const entries = [ - { address: addr1, txId: txId1, tokenId: token1, balance: 10, timestamp: timestamp1 }, - { address: addr1, txId: txId1, tokenId: token2, balance: 7, timestamp: timestamp1 }, - { address: addr2, txId: txId1, tokenId: token2, balance: 5, timestamp: timestamp1 }, - { address: addr3, txId: txId1, tokenId: token1, balance: 3, timestamp: timestamp1 }, - { address: addr1, txId: txId2, tokenId: token1, balance: -1, timestamp: timestamp2 }, - { address: addr1, txId: txId2, tokenId: token3, balance: 3, timestamp: timestamp2 }, - { address: addr2, txId: txId2, tokenId: token2, balance: -5, timestamp: timestamp2 }, - { address: addr3, txId: txId2, tokenId: token1, balance: 3, timestamp: timestamp2 }, + { address: addr1, txId: txId1, tokenId: token1, balance: 10n, timestamp: timestamp1 }, + { address: addr1, txId: txId1, tokenId: token2, balance: 7n, timestamp: timestamp1 }, + { address: addr2, txId: txId1, tokenId: token2, balance: 5n, timestamp: timestamp1 }, + { address: addr3, txId: txId1, tokenId: token1, balance: 3n, timestamp: timestamp1 }, + { address: addr1, txId: txId2, tokenId: token1, balance: -1n, timestamp: timestamp2 }, + { address: addr1, txId: txId2, tokenId: token3, balance: 3n, timestamp: timestamp2 }, + { address: addr2, txId: txId2, tokenId: token2, balance: -5n, timestamp: timestamp2 }, + { address: addr3, txId: txId2, tokenId: token1, balance: 3n, timestamp: timestamp2 }, ]; await addToAddressTxHistoryTable(mysql, entries); @@ -468,14 +468,14 @@ test('initWalletBalance', async () => { * address to make sure the wallet will only get the balance from its own addresses */ const historyEntries = [ - { address: addr1, txId: tx1, tokenId: token1, balance: 10, timestamp: ts1 }, - { address: addr1, txId: tx2, tokenId: token1, balance: -8, timestamp: ts2 }, - { address: addr1, txId: tx1, tokenId: token2, balance: 5, timestamp: ts1 }, - { address: addr2, txId: tx1, tokenId: token1, balance: 3, timestamp: ts1 }, - { address: addr2, txId: tx3, tokenId: token1, balance: 4, timestamp: ts3 }, - { address: addr2, txId: tx2, tokenId: token2, balance: 2, timestamp: ts2 }, - { address: addr3, txId: tx1, tokenId: token1, balance: 1, timestamp: ts1 }, - { address: addr3, txId: tx3, tokenId: token2, balance: 11, timestamp: ts3 }, + { address: addr1, txId: tx1, tokenId: token1, balance: 10n, timestamp: ts1 }, + { address: addr1, txId: tx2, tokenId: token1, balance: -8n, timestamp: ts2 }, + { address: addr1, txId: tx1, tokenId: token2, balance: 5n, timestamp: ts1 }, + { address: addr2, txId: tx1, tokenId: token1, balance: 3n, timestamp: ts1 }, + { address: addr2, txId: tx3, tokenId: token1, balance: 4n, timestamp: ts3 }, + { address: addr2, txId: tx2, tokenId: token2, balance: 2n, timestamp: ts2 }, + { address: addr3, txId: tx1, tokenId: token1, balance: 1n, timestamp: ts1 }, + { address: addr3, txId: tx3, tokenId: token2, balance: 11n, timestamp: ts3 }, ]; const addressEntries = [ // address, tokenId, unlocked, locked, lockExpires, transactions, unlocked_authorities, locked_authorities, total_received @@ -493,8 +493,8 @@ test('initWalletBalance', async () => { await initWalletBalance(mysql, walletId, [addr1, addr2]); // check balance entries - await expect(checkWalletBalanceTable(mysql, 2, walletId, token1, 7, 2, null, 3, 3)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 2, walletId, token2, 1, 6, timelock, 2, 2)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 2, walletId, token1, 7n, 2n, null, 3, 3)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 2, walletId, token2, 1n, 6n, timelock, 2, 2)).resolves.toBe(true); }); test('updateWalletTablesWithTx', async () => { @@ -522,7 +522,7 @@ test('updateWalletTablesWithTx', async () => { walletId: TokenBalanceMap.fromStringMap({ token1: { unlocked: 5, locked: 0, unlockedAuthorities: new Authorities(0b01) } }), }; await updateWalletTablesWithTx(mysql, tx1, ts1, walletBalanceMap1); - await expect(checkWalletBalanceTable(mysql, 1, walletId, token1, 5, 0, null, 1, 0b01, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 1, walletId, token1, 5n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 1, walletId, token1, tx1, 5, ts1)).resolves.toBe(true); // add tx2 @@ -535,8 +535,8 @@ test('updateWalletTablesWithTx', async () => { ), }; await updateWalletTablesWithTx(mysql, tx2, ts2, walletBalanceMap2); - await expect(checkWalletBalanceTable(mysql, 2, walletId, token1, 3, 1, 500, 2, 0b11, 0)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 2, walletId, token2, 7, 0, null, 1)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 2, walletId, token1, 3n, 1n, 500, 2, 0b11, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 2, walletId, token2, 7n, 0n, null, 1)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 3, walletId, token1, tx1, 5, ts1)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 3, walletId, token1, tx2, -1, ts2)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 3, walletId, token2, tx2, 7, ts2)).resolves.toBe(true); @@ -557,9 +557,9 @@ test('updateWalletTablesWithTx', async () => { await addToAddressBalanceTable(mysql, [['address1', token1, 0, 0, null, 1, 0b10, 0, 0]]); await updateWalletTablesWithTx(mysql, tx3, ts3, walletBalanceMap3); - await expect(checkWalletBalanceTable(mysql, 3, walletId, token1, 4, 3, 200, 3, 0b10, 0)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 3, walletId, token2, 7, 0, null, 1)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 3, walletId2, token2, 10, 0, null, 1)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, walletId, token1, 4n, 3n, 200, 3, 0b10, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, walletId, token2, 7n, 0n, null, 1)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, walletId2, token2, 10n, 0n, null, 1)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 5, walletId, token1, tx1, 5, ts1)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 5, walletId, token1, tx2, -1, ts2)).resolves.toBe(true); await expect(checkWalletTxHistoryTable(mysql, 5, walletId, token2, tx2, 7, ts2)).resolves.toBe(true); @@ -572,12 +572,12 @@ test('addUtxos, getUtxos, unlockUtxos, updateTxOutputSpentBy, unspendUtxos, getT const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', tokenId: 'token1', locked: false }, - { value: 15, address: 'address1', tokenId: 'token1', locked: false }, - { value: 25, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, - { value: 35, address: 'address2', tokenId: 'token1', locked: false }, + { value: 5n, address: 'address1', tokenId: 'token1', locked: false }, + { value: 15n, address: 'address1', tokenId: 'token1', locked: false }, + { value: 25n, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, + { value: 35n, address: 'address2', tokenId: 'token1', locked: false }, // authority utxo - { value: 0b11, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, + { value: 0b11n, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, ]; // empty list should be fine @@ -600,8 +600,8 @@ test('addUtxos, getUtxos, unlockUtxos, updateTxOutputSpentBy, unspendUtxos, getT const { token, decoded } = output; let authorities = 0; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + authorities = Number(value); + value = 0n; } await expect( checkUtxoTable(mysql, utxos.length, txId, output.index, token, decoded.address, value, authorities, decoded.timelock, null, output.locked), @@ -679,8 +679,8 @@ test('addUtxos, getUtxos, unlockUtxos, updateTxOutputSpentBy, unspendUtxos, getT const { token, decoded } = output; let authorities = 0; if (isAuthority(output.token_data)) { - authorities = value; - value = 0; + authorities = Number(value); + value = 0n; } await expect( checkUtxoTable(mysql, utxos.length, txId, index, token, decoded.address, value, authorities, decoded.timelock, null, output.locked), @@ -693,7 +693,7 @@ test('addUtxos, getUtxos, unlockUtxos, updateTxOutputSpentBy, unspendUtxos, getT index: 2, tokenId: 'token2', address: 'address2', - value: 25, + value: 25n, authorities: 0, timelock: 500, heightlock: null, @@ -717,9 +717,9 @@ test('getLockedUtxoFromInputs', async () => { expect.hasAssertions(); const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', token: 'token1', locked: false }, - { value: 25, address: 'address2', token: 'token2', timelock: 500, locked: true }, - { value: 35, address: 'address2', token: 'token1', locked: false }, + { value: 5n, address: 'address1', token: 'token1', locked: false }, + { value: 25n, address: 'address2', token: 'token2', timelock: 500, locked: true }, + { value: 35n, address: 'address2', token: 'token1', locked: false }, ]; // add to utxo table @@ -936,8 +936,8 @@ test('getWalletBalances', async () => { await addToWalletBalanceTable(mysql, [{ walletId, tokenId: token1.id, - unlockedBalance: 10, - lockedBalance: 4, + unlockedBalance: 10n, + lockedBalance: 4n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: now, @@ -945,8 +945,8 @@ test('getWalletBalances', async () => { }, { walletId, tokenId: token2.id, - unlockedBalance: 20, - lockedBalance: 5, + unlockedBalance: 20n, + lockedBalance: 5n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: now, @@ -954,8 +954,8 @@ test('getWalletBalances', async () => { }, { walletId: 'otherId', tokenId: token1.id, - unlockedBalance: 30, - lockedBalance: 1, + unlockedBalance: 30n, + lockedBalance: 1n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: now, @@ -1011,17 +1011,17 @@ test('getUtxosLockedAtHeight', async () => { const txId2 = 'txId2'; const utxos = [ // no locks - { value: 5, address: 'address1', token: 'token1', locked: false }, + { value: 5n, address: 'address1', token: 'token1', locked: false }, // only timelock - { value: 25, address: 'address2', token: 'token2', timelock: 50, locked: false }, + { value: 25n, address: 'address2', token: 'token2', timelock: 50, locked: false }, ]; const utxos2 = [ // only heightlock - { value: 35, address: 'address2', token: 'token1', timelock: null, locked: true }, + { value: 35n, address: 'address2', token: 'token1', timelock: null, locked: true }, // timelock and heightlock - { value: 45, address: 'address2', token: 'token1', timelock: 100, locked: true }, - { value: 55, address: 'address2', token: 'token1', timelock: 1000, locked: true }, + { value: 45n, address: 'address2', token: 'token1', timelock: 100, locked: true }, + { value: 55n, address: 'address2', token: 'token1', timelock: 1000, locked: true }, ]; // add to utxo table @@ -1080,7 +1080,7 @@ test('updateAddressLockedBalance', async () => { index: 0, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b01, timelock: 10000, heightlock: null, @@ -1104,8 +1104,8 @@ test('updateWalletLockedBalance', async () => { const entries = [{ walletId: wallet1, tokenId, - unlockedBalance: 10, - lockedBalance: 20, + unlockedBalance: 10n, + lockedBalance: 20n, unlockedAuthorities: 0b01, lockedAuthorities: 0, timelockExpires: now, @@ -1113,8 +1113,8 @@ test('updateWalletLockedBalance', async () => { }, { walletId: wallet2, tokenId, - unlockedBalance: 0, - lockedBalance: 100, + unlockedBalance: 0n, + lockedBalance: 100n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: now, @@ -1122,8 +1122,8 @@ test('updateWalletLockedBalance', async () => { }, { walletId: wallet1, tokenId: otherToken, - unlockedBalance: 1, - lockedBalance: 2, + unlockedBalance: 1n, + lockedBalance: 2n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1134,9 +1134,9 @@ test('updateWalletLockedBalance', async () => { const wallet1Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 15, locked: 0, unlockedAuthorities: new Authorities(0b11) } }); const wallet2Map = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 50, locked: 0 } }); await updateWalletLockedBalance(mysql, { [wallet1]: wallet1Map, [wallet2]: wallet2Map }); - await expect(checkWalletBalanceTable(mysql, 3, wallet1, tokenId, 25, 5, now, 5, 0b11, 0)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 3, wallet2, tokenId, 50, 50, now, 4)).resolves.toBe(true); - await expect(checkWalletBalanceTable(mysql, 3, wallet1, otherToken, 1, 2, null, 1)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, wallet1, tokenId, 25n, 5n, now, 5, 0b11, 0)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, wallet2, tokenId, 50n, 50n, now, 4)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, wallet1, otherToken, 1n, 2n, null, 1)).resolves.toBe(true); // now pretend there's another locked authority, so final balance of locked authorities should be updated accordingly await addToAddressTable(mysql, [{ @@ -1148,7 +1148,7 @@ test('updateWalletLockedBalance', async () => { await addToAddressBalanceTable(mysql, [['address1', tokenId, 0, 0, null, 1, 0, 0b01, 0]]); const newMap = TokenBalanceMap.fromStringMap({ [tokenId]: { unlocked: 0, locked: 0, unlockedAuthorities: new Authorities(0b10) } }); await updateWalletLockedBalance(mysql, { [wallet1]: newMap }); - await expect(checkWalletBalanceTable(mysql, 3, wallet1, tokenId, 25, 5, now, 5, 0b11, 0b01)).resolves.toBe(true); + await expect(checkWalletBalanceTable(mysql, 3, wallet1, tokenId, 25n, 5n, now, 5, 0b11, 0b01)).resolves.toBe(true); }); test('addOrUpdateTx should add weight to a tx', async () => { @@ -1302,7 +1302,7 @@ test('getWalletSortedValueUtxos', async () => { index: 0, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -1315,7 +1315,7 @@ test('getWalletSortedValueUtxos', async () => { index: 1, tokenId, address: addr1, - value: 10, + value: 10n, authorities: 0, timelock: 10000, heightlock: null, @@ -1328,7 +1328,7 @@ test('getWalletSortedValueUtxos', async () => { index: 2, tokenId, address: 'otherAddr', - value: 10, + value: 10n, authorities: 0, timelock: null, heightlock: null, @@ -1341,7 +1341,7 @@ test('getWalletSortedValueUtxos', async () => { index: 3, tokenId: 'tokenId2', address: addr1, - value: 5, + value: 5n, authorities: 0, timelock: null, heightlock: null, @@ -1354,7 +1354,7 @@ test('getWalletSortedValueUtxos', async () => { index: 4, tokenId, address: addr1, - value: 4, + value: 4n, authorities: 0, timelock: null, heightlock: null, @@ -1366,7 +1366,7 @@ test('getWalletSortedValueUtxos', async () => { index: 5, tokenId, address: addr2, - value: 1, + value: 1n, authorities: 0, timelock: null, heightlock: null, @@ -1378,7 +1378,7 @@ test('getWalletSortedValueUtxos', async () => { index: 6, tokenId, address: addr1, - value: 7, + value: 7n, authorities: 0, timelock: null, heightlock: null, @@ -1435,7 +1435,7 @@ test('markUtxosWithProposalId and getTxProposalInputs', async () => { index: 0, tokenId, address, - value: 5, + value: 5n, authorities: 0, timelock: null, heightlock: null, @@ -1448,7 +1448,7 @@ test('markUtxosWithProposalId and getTxProposalInputs', async () => { index: 1, tokenId, address, - value: 15, + value: 15n, authorities: 0, timelock: null, heightlock: null, @@ -1461,7 +1461,7 @@ test('markUtxosWithProposalId and getTxProposalInputs', async () => { index: 2, tokenId, address, - value: 25, + value: 25n, authorities: 0, timelock: null, heightlock: null, @@ -1541,7 +1541,7 @@ test('createTxProposal, updateTxProposal, getTxProposal, countUnsentTxProposals, index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, @@ -1554,7 +1554,7 @@ test('createTxProposal, updateTxProposal, getTxProposal, countUnsentTxProposals, index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, @@ -1567,7 +1567,7 @@ test('createTxProposal, updateTxProposal, getTxProposal, countUnsentTxProposals, index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, @@ -1666,13 +1666,13 @@ test('fetchAddressTxHistorySum', async () => { const timestamp1 = 10; const timestamp2 = 20; const entries = [ - { address: addr1, txId: txId1, tokenId: token1, balance: 10, timestamp: timestamp1 }, - { address: addr1, txId: txId2, tokenId: token1, balance: 20, timestamp: timestamp2 }, - { address: addr1, txId: txId3, tokenId: token1, balance: 30, timestamp: timestamp2 }, + { address: addr1, txId: txId1, tokenId: token1, balance: 10n, timestamp: timestamp1 }, + { address: addr1, txId: txId2, tokenId: token1, balance: 20n, timestamp: timestamp2 }, + { address: addr1, txId: txId3, tokenId: token1, balance: 30n, timestamp: timestamp2 }, // total: 60 - { address: addr2, txId: txId1, tokenId: token2, balance: 20, timestamp: timestamp1 }, - { address: addr2, txId: txId2, tokenId: token2, balance: 20, timestamp: timestamp2 }, - { address: addr2, txId: txId3, tokenId: token2, balance: 10, timestamp: timestamp2 }, + { address: addr2, txId: txId1, tokenId: token2, balance: 20n, timestamp: timestamp1 }, + { address: addr2, txId: txId2, tokenId: token2, balance: 20n, timestamp: timestamp2 }, + { address: addr2, txId: txId3, tokenId: token2, balance: 10n, timestamp: timestamp2 }, // total: 50 ]; @@ -1796,14 +1796,14 @@ test('checkTxWasVoided', async () => { address: address1, txId: tx1, tokenId: '00', - balance: 0, + balance: 0n, timestamp: 1, voided: true, }, { address: address2, txId: tx2, tokenId: '00', - balance: 0, + balance: 0n, timestamp: 1, voided: false, }]); @@ -1825,7 +1825,7 @@ test('cleanupVoidedTx', async () => { index: 0, tokenId, address: addr1, - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1838,7 +1838,7 @@ test('cleanupVoidedTx', async () => { address: addr1, txId, tokenId, - balance: 0, + balance: 0n, timestamp: 1, voided: true, }]); @@ -1872,7 +1872,7 @@ test('cleanupVoidedTx', async () => { index: 0, tokenId, address: addr1, - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1889,7 +1889,7 @@ test('cleanupVoidedTx', async () => { timestamp: 1, address: addr1, tokenId, - balance: 0, + balance: 0n, voided: false, }]); @@ -1987,13 +1987,13 @@ test('rebuildAddressBalancesFromUtxos', async () => { await addToAddressBalanceTable(mysql, addressEntries); const txHistory = [ - { address: addr1, txId, tokenId: token1, balance: 20, timestamp: timestamp1 }, - { address: addr1, txId: txId4, tokenId: token1, balance: 21, timestamp: timestamp1, voided: true }, + { address: addr1, txId, tokenId: token1, balance: 20n, timestamp: timestamp1 }, + { address: addr1, txId: txId4, tokenId: token1, balance: 21n, timestamp: timestamp1, voided: true }, - { address: addr2, txId, tokenId: token1, balance: 260, timestamp: timestamp1 }, - { address: addr2, txId, tokenId: token2, balance: 25, timestamp: timestamp1 }, - { address: addr2, txId: txId2, tokenId: token1, balance: 80, timestamp: timestamp1 }, - { address: addr2, txId: txId3, tokenId: token1, balance: 15, timestamp: timestamp1, voided: true }, + { address: addr2, txId, tokenId: token1, balance: 260n, timestamp: timestamp1 }, + { address: addr2, txId, tokenId: token2, balance: 25n, timestamp: timestamp1 }, + { address: addr2, txId: txId2, tokenId: token1, balance: 80n, timestamp: timestamp1 }, + { address: addr2, txId: txId3, tokenId: token1, balance: 15n, timestamp: timestamp1, voided: true }, ]; await addToAddressTxHistoryTable(mysql, txHistory); @@ -2055,13 +2055,13 @@ test('markAddressTxHistoryAsVoided', async () => { const timestamp2 = 20; const entries = [ - { address: addr1, txId: txId1, tokenId: token1, balance: 10, timestamp: timestamp1 }, - { address: addr1, txId: txId2, tokenId: token1, balance: 20, timestamp: timestamp2 }, - { address: addr1, txId: txId3, tokenId: token1, balance: 30, timestamp: timestamp2 }, + { address: addr1, txId: txId1, tokenId: token1, balance: 10n, timestamp: timestamp1 }, + { address: addr1, txId: txId2, tokenId: token1, balance: 20n, timestamp: timestamp2 }, + { address: addr1, txId: txId3, tokenId: token1, balance: 30n, timestamp: timestamp2 }, // total: 60 - { address: addr2, txId: txId1, tokenId: token2, balance: 20, timestamp: timestamp1 }, - { address: addr2, txId: txId2, tokenId: token2, balance: 20, timestamp: timestamp2 }, - { address: addr2, txId: txId3, tokenId: token2, balance: 10, timestamp: timestamp2 }, + { address: addr2, txId: txId1, tokenId: token2, balance: 20n, timestamp: timestamp1 }, + { address: addr2, txId: txId2, tokenId: token2, balance: 20n, timestamp: timestamp2 }, + { address: addr2, txId: txId3, tokenId: token2, balance: 10n, timestamp: timestamp2 }, // total: 50 ]; @@ -2124,7 +2124,7 @@ test('filterTxOutputs', async () => { index: 0, tokenId: '00', address: addr1, - value: 6000, + value: 6000n, authorities: 0, timelock: null, heightlock: null, @@ -2135,7 +2135,7 @@ test('filterTxOutputs', async () => { index: 0, tokenId, address: addr1, - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -2146,7 +2146,7 @@ test('filterTxOutputs', async () => { index: 0, tokenId, address: addr1, - value: 500, + value: 500n, authorities: 0, timelock: null, heightlock: null, @@ -2157,7 +2157,7 @@ test('filterTxOutputs', async () => { index: 1, tokenId, address: addr1, - value: 1000, + value: 1000n, authorities: 0, timelock: null, heightlock: null, @@ -2169,7 +2169,7 @@ test('filterTxOutputs', async () => { index: 2, tokenId, address: addr2, - value: 1500, + value: 1500n, authorities: 0, timelock: null, heightlock: null, @@ -2181,7 +2181,7 @@ test('filterTxOutputs', async () => { index: 3, tokenId, address: addr2, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -2193,7 +2193,7 @@ test('filterTxOutputs', async () => { index: 4, tokenId, address: addr2, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -2308,7 +2308,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 0, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -2319,7 +2319,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 1, tokenId, address: addr1, - value: 10, + value: 10n, authorities: 0, timelock: 10000, heightlock: null, @@ -2330,7 +2330,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 2, tokenId, address: 'otherAddr', - value: 10, + value: 10n, authorities: 0, timelock: null, heightlock: null, @@ -2340,9 +2340,9 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { await commitTransaction(mysql); - await expect(checkUtxoTable(mysql, 3, txId, 0, tokenId, addr1, 0, 0b01, null, null, false)).resolves.toBe(true); - await expect(checkUtxoTable(mysql, 3, txId, 1, tokenId, addr1, 10, 0, 10000, null, true)).resolves.toBe(true); - await expect(checkUtxoTable(mysql, 3, txId, 2, tokenId, 'otherAddr', 10, 0, null, null, false)).resolves.toBe(true); + await expect(checkUtxoTable(mysql, 3, txId, 0, tokenId, addr1, 0n, 0b01, null, null, false)).resolves.toBe(true); + await expect(checkUtxoTable(mysql, 3, txId, 1, tokenId, addr1, 10n, 0, 10000, null, true)).resolves.toBe(true); + await expect(checkUtxoTable(mysql, 3, txId, 2, tokenId, 'otherAddr', 10n, 0, null, null, false)).resolves.toBe(true); await beginTransaction(mysql); @@ -2351,7 +2351,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 3, tokenId: 'tokenId2', address: addr1, - value: 5, + value: 5n, authorities: 0, timelock: null, heightlock: null, @@ -2362,7 +2362,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 4, tokenId, address: addr1, - value: 4, + value: 4n, authorities: 0, timelock: null, heightlock: null, @@ -2373,7 +2373,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 5, tokenId, address: addr2, - value: 1, + value: 1n, authorities: 0, timelock: null, heightlock: null, @@ -2384,7 +2384,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { index: 6, tokenId, address: addr1, - value: 7, + value: 7n, authorities: 0, timelock: null, heightlock: null, @@ -2395,7 +2395,7 @@ test('beginTransaction, commitTransaction, rollbackTransaction', async () => { await rollbackTransaction(mysql); // check if the database still has 3 elements only - await expect(checkUtxoTable(mysql, 3, txId, 2, tokenId, 'otherAddr', 10, 0, null, null, false)).resolves.toBe(true); + await expect(checkUtxoTable(mysql, 3, txId, 2, tokenId, 'otherAddr', 10n, 0, null, null, false)).resolves.toBe(true); }); test('getMinersList', async () => { @@ -2433,13 +2433,13 @@ test('getTotalSupply', async () => { const txId = 'txId'; const utxos = [ - { value: 500, address: 'HDeadDeadDeadDeadDeadDeadDeagTPgmn', tokenId: '00', locked: false }, - { value: 5, address: 'address1', tokenId: '00', locked: false }, - { value: 15, address: 'address1', tokenId: '00', locked: false }, - { value: 25, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, - { value: 35, address: 'address2', tokenId: 'token1', locked: false }, + { value: 500n, address: 'HDeadDeadDeadDeadDeadDeadDeagTPgmn', tokenId: '00', locked: false }, + { value: 5n, address: 'address1', tokenId: '00', locked: false }, + { value: 15n, address: 'address1', tokenId: '00', locked: false }, + { value: 25n, address: 'address2', tokenId: 'token2', timelock: 500, locked: true }, + { value: 35n, address: 'address2', tokenId: 'token1', locked: false }, // authority utxo - { value: 0b11, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, + { value: 0b11n, address: 'address1', tokenId: 'token1', locked: false, tokenData: 129 }, ]; // add to utxo table @@ -2477,12 +2477,12 @@ test('getExpiredTimelocksUtxos', async () => { const txId = 'txId'; const utxos = [ - { value: 5, address: 'address1', tokenId: 'token1', locked: true }, - { value: 15, address: 'address1', tokenId: 'token1', locked: true }, - { value: 25, address: 'address2', tokenId: 'token2', timelock: 100, locked: true }, - { value: 35, address: 'address2', tokenId: 'token1', timelock: 200, locked: true }, + { value: 5n, address: 'address1', tokenId: 'token1', locked: true }, + { value: 15n, address: 'address1', tokenId: 'token1', locked: true }, + { value: 25n, address: 'address2', tokenId: 'token2', timelock: 100, locked: true }, + { value: 35n, address: 'address2', tokenId: 'token1', timelock: 200, locked: true }, // authority utxo - { value: 0b11, address: 'address1', tokenId: 'token1', timelock: 300, locked: true, tokenData: 129 }, + { value: 0b11n, address: 'address1', tokenId: 'token1', timelock: 300, locked: true, tokenData: 129 }, ]; // empty list should be fine @@ -2520,11 +2520,11 @@ test('getTotalTransactions', async () => { expect.hasAssertions(); await addToAddressTxHistoryTable(mysql, [ - { address: 'address1', txId: 'txId1', tokenId: 'token1', balance: -5, timestamp: 1000 }, - { address: 'address1', txId: 'txId2', tokenId: 'token1', balance: 5, timestamp: 1000 }, - { address: 'address1', txId: 'txId3', tokenId: 'token1', balance: 10, timestamp: 1000 }, - { address: 'address2', txId: 'txId4', tokenId: 'token2', balance: -5, timestamp: 1000 }, - { address: 'address2', txId: 'txId5', tokenId: 'token2', balance: 50, timestamp: 1000 }, + { address: 'address1', txId: 'txId1', tokenId: 'token1', balance: -5n, timestamp: 1000 }, + { address: 'address1', txId: 'txId2', tokenId: 'token1', balance: 5n, timestamp: 1000 }, + { address: 'address1', txId: 'txId3', tokenId: 'token1', balance: 10n, timestamp: 1000 }, + { address: 'address2', txId: 'txId4', tokenId: 'token2', balance: -5n, timestamp: 1000 }, + { address: 'address2', txId: 'txId5', tokenId: 'token2', balance: 50n, timestamp: 1000 }, ]); expect(await getTotalTransactions(mysql, 'token1')).toStrictEqual(3); @@ -2556,7 +2556,7 @@ test('getAvailableAuthorities', async () => { index: 0, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -2567,7 +2567,7 @@ test('getAvailableAuthorities', async () => { index: 1, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b11, timelock: 1000, heightlock: null, @@ -2578,7 +2578,7 @@ test('getAvailableAuthorities', async () => { index: 2, tokenId, address: addr1, - value: 0, + value: 0n, authorities: 0b10, timelock: null, heightlock: null, @@ -2589,7 +2589,7 @@ test('getAvailableAuthorities', async () => { index: 3, tokenId: tokenId2, address: addr2, - value: 0, + value: 0n, authorities: 0b01, timelock: null, heightlock: null, @@ -2612,8 +2612,8 @@ test('getUtxo, getAuthorityUtxo', async () => { index: 0, tokenId, address: addr1, - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: 10000, heightlock: null, locked: true, @@ -2624,8 +2624,8 @@ test('getUtxo, getAuthorityUtxo', async () => { index: 1, tokenId, address: addr1, - value: 0, - authorities: constants.TOKEN_MELT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MELT_MASK), timelock: 10000, heightlock: null, locked: true, @@ -2648,8 +2648,8 @@ test('getUtxo, getAuthorityUtxo', async () => { spentBy: null, }); - const mintUtxo = await getAuthorityUtxo(mysql, tokenId, constants.TOKEN_MINT_MASK); - const meltUtxo = await getAuthorityUtxo(mysql, tokenId, constants.TOKEN_MELT_MASK); + const mintUtxo = await getAuthorityUtxo(mysql, tokenId, Number(constants.TOKEN_MINT_MASK)); + const meltUtxo = await getAuthorityUtxo(mysql, tokenId, Number(constants.TOKEN_MELT_MASK)); expect(mintUtxo).toStrictEqual({ txId: 'txId', @@ -2697,14 +2697,14 @@ test('getAffectedAddressTxCountFromTxList', async () => { const timestamp2 = 20; const entries: AddressTxHistoryTableEntry[] = [ - { address: addr1, txId: txId1, tokenId: token1, balance: 10, timestamp: timestamp1, voided: true }, - { address: addr1, txId: txId1, tokenId: token2, balance: 7, timestamp: timestamp1, voided: true }, - { address: addr2, txId: txId1, tokenId: token2, balance: 5, timestamp: timestamp1, voided: true }, - { address: addr3, txId: txId1, tokenId: token1, balance: 3, timestamp: timestamp1, voided: true }, - { address: addr1, txId: txId2, tokenId: token1, balance: -1, timestamp: timestamp2, voided: false }, - { address: addr1, txId: txId2, tokenId: token3, balance: 3, timestamp: timestamp2, voided: false }, - { address: addr2, txId: txId3, tokenId: token2, balance: -5, timestamp: timestamp2, voided: true }, - { address: addr3, txId: txId3, tokenId: token1, balance: 3, timestamp: timestamp2, voided: true }, + { address: addr1, txId: txId1, tokenId: token1, balance: 10n, timestamp: timestamp1, voided: true }, + { address: addr1, txId: txId1, tokenId: token2, balance: 7n, timestamp: timestamp1, voided: true }, + { address: addr2, txId: txId1, tokenId: token2, balance: 5n, timestamp: timestamp1, voided: true }, + { address: addr3, txId: txId1, tokenId: token1, balance: 3n, timestamp: timestamp1, voided: true }, + { address: addr1, txId: txId2, tokenId: token1, balance: -1n, timestamp: timestamp2, voided: false }, + { address: addr1, txId: txId2, tokenId: token3, balance: 3n, timestamp: timestamp2, voided: false }, + { address: addr2, txId: txId3, tokenId: token2, balance: -5n, timestamp: timestamp2, voided: true }, + { address: addr3, txId: txId3, tokenId: token1, balance: 3n, timestamp: timestamp2, voided: true }, ]; await addToAddressTxHistoryTable(mysql, entries); @@ -3110,8 +3110,8 @@ describe('getTransactionById', () => { { id: token2.id, name: token2.name, symbol: token2.symbol, transactions: 0 }, ]); const entries = [ - { address: addr1, txId: txId1, tokenId: token1.id, balance: 10, timestamp: timestamp1 }, - { address: addr1, txId: txId1, tokenId: token2.id, balance: 7, timestamp: timestamp1 }, + { address: addr1, txId: txId1, tokenId: token1.id, balance: 10n, timestamp: timestamp1 }, + { address: addr1, txId: txId1, tokenId: token2.id, balance: 7n, timestamp: timestamp1 }, ]; await addToAddressTxHistoryTable(mysql, entries); await initWalletTxHistory(mysql, walletId1, [addr1]); @@ -3542,7 +3542,7 @@ describe('Clear unsent txProposals utxos', () => { index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, @@ -3555,7 +3555,7 @@ describe('Clear unsent txProposals utxos', () => { index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, @@ -3568,7 +3568,7 @@ describe('Clear unsent txProposals utxos', () => { index: 0, tokenId: '00', address: 'address1', - value: 5, + value: 5n, authorities: 0, timelock: 0, heightlock: 0, diff --git a/packages/wallet-service/tests/integration.test.ts b/packages/wallet-service/tests/integration.test.ts index 3511d4ac..9f811322 100644 --- a/packages/wallet-service/tests/integration.test.ts +++ b/packages/wallet-service/tests/integration.test.ts @@ -1,9 +1,8 @@ import { mockedAddAlert } from '@tests/utils/alerting.utils.mock'; import { initFirebaseAdminMock } from '@tests/utils/firebase-admin.mock'; import eventTemplate from '@events/eventTemplate.json'; -import { loadWallet, loadWalletFailed } from '@src/api/wallet'; -import { createWallet, getMinersList } from '@src/db'; -import * as txProcessor from '@src/txProcessor'; +import { loadWalletFailed } from '@src/api/wallet'; +import { createWallet } from '@src/db'; import { WalletStatus } from '@src/types'; import { Transaction, TxInput, Severity } from '@wallet-service/common/src/types'; import { closeDbConnection, getDbConnection, getUnixTimestamp, getWalletId } from '@src/utils'; @@ -13,22 +12,16 @@ import { XPUBKEY, AUTH_XPUBKEY, cleanDatabase, - checkAddressTable, - checkAddressTxHistoryTable, - checkUtxoTable, - checkWalletBalanceTable, checkWalletTable, - checkWalletTxHistoryTable, createOutput, createInput, - addToUtxoTable, } from '@tests/utils'; import { SNSEvent } from 'aws-lambda'; const mysql = getDbConnection(); initFirebaseAdminMock(); -const blockReward = 6400; +const blockReward = 6400n; const htrToken = '00'; const walletId = getWalletId(XPUBKEY); const now = getUnixTimestamp(); @@ -92,8 +85,8 @@ tx.tx_id = txId3; tx.timestamp += 20; tx.inputs = [createInput(blockReward, ADDRESSES[0], txId1, 0)]; tx.outputs = [ - createOutput(0, blockReward - 5000, ADDRESSES[1]), - createOutput(1, 5000, ADDRESSES[2]), + createOutput(0, blockReward - 5000n, ADDRESSES[1]), + createOutput(1, 5000n, ADDRESSES[2]), ]; // tx sends one of last tx's outputs to 2 addresses, one of which is not from this wallet. Also, output sent to this wallet is locked @@ -105,11 +98,11 @@ const txId4 = 'txId4'; tx2.tx_id = txId4; tx2.timestamp += 20; tx2.inputs = [ - createInput(5000, ADDRESSES[2], txId2, 1), + createInput(5000n, ADDRESSES[2], txId2, 1), ]; tx2.outputs = [ - createOutput(0, 1000, ADDRESSES[6], '00', timelock), // belongs to this wallet - createOutput(1, 4000, 'HCuWC2qgNP47BtWtsTM48PokKitVdR6pch'), // other wallet + createOutput(0, 1000n, ADDRESSES[6], '00', timelock), // belongs to this wallet + createOutput(1, 4000n, 'HCuWC2qgNP47BtWtsTM48PokKitVdR6pch'), // other wallet ]; // tx2Inputs on the format addToUtxoTable expects diff --git a/packages/wallet-service/tests/mempool.test.ts b/packages/wallet-service/tests/mempool.test.ts index 311ac682..8a19e786 100644 --- a/packages/wallet-service/tests/mempool.test.ts +++ b/packages/wallet-service/tests/mempool.test.ts @@ -41,7 +41,7 @@ test('onHandleOldVoidedTxs', async () => { index: 0, tokenId: '00', address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -52,7 +52,7 @@ test('onHandleOldVoidedTxs', async () => { index: 0, tokenId: '00', address: ADDRESSES[1], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -63,7 +63,7 @@ test('onHandleOldVoidedTxs', async () => { index: 0, tokenId: '00', address: ADDRESSES[2], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -74,7 +74,7 @@ test('onHandleOldVoidedTxs', async () => { index: 1, tokenId: '00', address: ADDRESSES[3], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -83,10 +83,10 @@ test('onHandleOldVoidedTxs', async () => { }]; const txHistory = [ - { address: ADDRESSES[0], txId: TX_IDS[0], tokenId: '00', balance: 50, timestamp: 10 }, - { address: ADDRESSES[1], txId: TX_IDS[1], tokenId: '00', balance: 100, timestamp: 10 }, - { address: ADDRESSES[2], txId: TX_IDS[2], tokenId: '00', balance: 150, timestamp: 10 }, - { address: ADDRESSES[3], txId: TX_IDS[2], tokenId: '00', balance: 200, timestamp: 10 }, + { address: ADDRESSES[0], txId: TX_IDS[0], tokenId: '00', balance: 50n, timestamp: 10 }, + { address: ADDRESSES[1], txId: TX_IDS[1], tokenId: '00', balance: 100n, timestamp: 10 }, + { address: ADDRESSES[2], txId: TX_IDS[2], tokenId: '00', balance: 150n, timestamp: 10 }, + { address: ADDRESSES[3], txId: TX_IDS[2], tokenId: '00', balance: 200n, timestamp: 10 }, ]; const addressEntries = [ @@ -111,7 +111,7 @@ test('onHandleOldVoidedTxs', async () => { await onHandleOldVoidedTxs(); - await expect(checkUtxoTable(mysql, 4, TX_IDS[0], 0, '00', ADDRESSES[0], 50, 0, null, null, false, null, true)).resolves.toBe(true); + await expect(checkUtxoTable(mysql, 4, TX_IDS[0], 0, '00', ADDRESSES[0], 50n, 0, null, null, false, null, true)).resolves.toBe(true); }); test('onHandleOldVoidedTxs should try to confirm the block by fetching the first_block', async () => { @@ -128,7 +128,7 @@ test('onHandleOldVoidedTxs should try to confirm the block by fetching the first index: 0, tokenId: '00', address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, diff --git a/packages/wallet-service/tests/txById.test.ts b/packages/wallet-service/tests/txById.test.ts index 011de406..baa9d4f7 100644 --- a/packages/wallet-service/tests/txById.test.ts +++ b/packages/wallet-service/tests/txById.test.ts @@ -44,8 +44,8 @@ test('get a transaction given its ID', async () => { { id: token2.id, name: token2.name, symbol: token2.symbol, transactions: 0 }, ]); const entries = [ - { address: addr1, txId: txId1, tokenId: token1.id, balance: 10, timestamp: timestamp1 }, - { address: addr1, txId: txId1, tokenId: token2.id, balance: 7, timestamp: timestamp1 }, + { address: addr1, txId: txId1, tokenId: token1.id, balance: 10n, timestamp: timestamp1 }, + { address: addr1, txId: txId1, tokenId: token2.id, balance: 7n, timestamp: timestamp1 }, ]; await addToAddressTxHistoryTable(mysql, entries); await initWalletTxHistory(mysql, walletId1, [addr1]); diff --git a/packages/wallet-service/tests/txOutputs.test.ts b/packages/wallet-service/tests/txOutputs.test.ts index 40936992..c912c1c4 100644 --- a/packages/wallet-service/tests/txOutputs.test.ts +++ b/packages/wallet-service/tests/txOutputs.test.ts @@ -56,7 +56,7 @@ test('filter utxos api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -67,7 +67,7 @@ test('filter utxos api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -78,7 +78,7 @@ test('filter utxos api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[2], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -89,7 +89,7 @@ test('filter utxos api with invalid parameters', async () => { index: 1, tokenId: token1, address: ADDRESSES[3], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -186,7 +186,7 @@ test('filter tx_output api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -197,7 +197,7 @@ test('filter tx_output api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -208,7 +208,7 @@ test('filter tx_output api with invalid parameters', async () => { index: 0, tokenId: token1, address: ADDRESSES[2], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -219,7 +219,7 @@ test('filter tx_output api with invalid parameters', async () => { index: 1, tokenId: token1, address: ADDRESSES[3], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -315,7 +315,7 @@ test('get utxos with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -326,7 +326,7 @@ test('get utxos with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -337,7 +337,7 @@ test('get utxos with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -348,7 +348,7 @@ test('get utxos with wallet id', async () => { index: 1, tokenId: token1, address: ADDRESSES[0], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -421,7 +421,7 @@ test('get tx outputs with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -432,7 +432,7 @@ test('get tx outputs with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -443,7 +443,7 @@ test('get tx outputs with wallet id', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -454,7 +454,7 @@ test('get tx outputs with wallet id', async () => { index: 1, tokenId: token1, address: ADDRESSES[0], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -527,7 +527,7 @@ test('get authority utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 0, + value: 0n, authorities: 1, timelock: null, heightlock: null, @@ -538,7 +538,7 @@ test('get authority utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 0, + value: 0n, authorities: 2, timelock: null, heightlock: null, @@ -549,7 +549,7 @@ test('get authority utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 0, + value: 0n, authorities: 1, timelock: null, heightlock: null, @@ -560,7 +560,7 @@ test('get authority utxos', async () => { index: 1, tokenId: token1, address: ADDRESSES[0], - value: 0, + value: 0n, authorities: 1, timelock: null, heightlock: null, @@ -571,7 +571,7 @@ test('get authority utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -656,7 +656,7 @@ test('get a specific utxo', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -667,7 +667,7 @@ test('get a specific utxo', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -678,7 +678,7 @@ test('get a specific utxo', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -689,7 +689,7 @@ test('get a specific utxo', async () => { index: 1, tokenId: token1, address: ADDRESSES[0], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -760,7 +760,7 @@ test('get utxos from addresses that are not my own should fail with ApiError.ADD index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -771,7 +771,7 @@ test('get utxos from addresses that are not my own should fail with ApiError.ADD index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -782,7 +782,7 @@ test('get utxos from addresses that are not my own should fail with ApiError.ADD index: 0, tokenId: token1, address: ADDRESSES[1], - value: 150, + value: 150n, authorities: 0, timelock: null, heightlock: null, @@ -793,7 +793,7 @@ test('get utxos from addresses that are not my own should fail with ApiError.ADD index: 1, tokenId: token1, address: ADDRESSES[1], - value: 200, + value: 200n, authorities: 0, timelock: null, heightlock: null, @@ -846,7 +846,7 @@ test('get spent tx_output', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 50, + value: 50n, authorities: 0, timelock: null, heightlock: null, @@ -857,7 +857,7 @@ test('get spent tx_output', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, diff --git a/packages/wallet-service/tests/txProposal.test.ts b/packages/wallet-service/tests/txProposal.test.ts index b42a0c3c..aedf0aa4 100644 --- a/packages/wallet-service/tests/txProposal.test.ts +++ b/packages/wallet-service/tests/txProposal.test.ts @@ -107,7 +107,7 @@ test('POST /txproposals with utxos that are already used on another txproposal s index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -118,7 +118,7 @@ test('POST /txproposals with utxos that are already used on another txproposal s index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -129,7 +129,7 @@ test('POST /txproposals with utxos that are already used on another txproposal s index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -141,8 +141,8 @@ test('POST /txproposals with utxos that are already used on another txproposal s await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -150,8 +150,8 @@ test('POST /txproposals with utxos that are already used on another txproposal s }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -172,7 +172,7 @@ test('POST /txproposals with utxos that are already used on another txproposal s const outputs = [ new hathorLib.Output( - 300, + 300n, p2pkhAddress, { tokenData: 1, }, @@ -251,7 +251,7 @@ test('POST /txproposals with too many outputs should fail with ApiError.TOO_MANY ]; const outputs = [...Array(10).keys()].map(() => ( - new hathorLib.Output(300, new hathorLib.P2PKH(new hathorLib.Address(ADDRESSES[0], { + new hathorLib.Output(300n, new hathorLib.P2PKH(new hathorLib.Address(ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), })).createScript(), { tokenData: 1, @@ -295,7 +295,7 @@ test('POST /txproposals with a wallet that is not ready should fail with ApiErro index: 0, tokenId: 'token1', address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -306,7 +306,7 @@ test('POST /txproposals with a wallet that is not ready should fail with ApiErro index: 0, tokenId: 'token1', address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -317,7 +317,7 @@ test('POST /txproposals with a wallet that is not ready should fail with ApiErro index: 0, tokenId: 'token2', address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -329,8 +329,8 @@ test('POST /txproposals with a wallet that is not ready should fail with ApiErro await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -338,8 +338,8 @@ test('POST /txproposals with a wallet that is not ready should fail with ApiErro }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -388,7 +388,7 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -399,7 +399,7 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -410,7 +410,7 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -422,8 +422,8 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -431,8 +431,8 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -449,7 +449,7 @@ test('PUT /txproposals/{proposalId} with an empty body should fail with ApiError // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address(ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), })).createScript(), { @@ -529,7 +529,7 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -540,7 +540,7 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -551,7 +551,7 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -563,8 +563,8 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -572,8 +572,8 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -590,7 +590,7 @@ test('PUT /txproposals/{proposalId} on a proposal which status is not OPEN or SE // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH( new hathorLib.Address( ADDRESSES[0], { @@ -654,7 +654,7 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -665,7 +665,7 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -676,7 +676,7 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -688,8 +688,8 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -697,8 +697,8 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -715,7 +715,7 @@ test('PUT /txproposals/{proposalId} on a proposal which is not owned by the user // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -805,7 +805,7 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -816,7 +816,7 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -827,7 +827,7 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -839,8 +839,8 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -848,8 +848,8 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -866,7 +866,7 @@ test('PUT /txproposals/{proposalId} with an invalid txHex should fail and update // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -949,7 +949,7 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -960,7 +960,7 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -971,7 +971,7 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -983,8 +983,8 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -992,8 +992,8 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1010,7 +1010,7 @@ test('PUT /txproposals/{proposalId} should update tx_proposal to SEND_ERROR on f // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -1069,7 +1069,7 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1080,7 +1080,7 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1091,7 +1091,7 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1103,8 +1103,8 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1112,8 +1112,8 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1130,7 +1130,7 @@ test('DELETE /txproposals/{proposalId} should delete a tx_proposal and remove th // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -1239,7 +1239,7 @@ test('POST /txproposals one output and input on txHex', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1250,7 +1250,7 @@ test('POST /txproposals one output and input on txHex', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1261,7 +1261,7 @@ test('POST /txproposals one output and input on txHex', async () => { index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1273,8 +1273,8 @@ test('POST /txproposals one output and input on txHex', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1282,8 +1282,8 @@ test('POST /txproposals one output and input on txHex', async () => { }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1300,7 +1300,7 @@ test('POST /txproposals one output and input on txHex', async () => { // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -1369,7 +1369,7 @@ test('POST /txproposals with denied utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1380,7 +1380,7 @@ test('POST /txproposals with denied utxos', async () => { index: 0, tokenId: token1, address: ADDRESSES[1], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1391,7 +1391,7 @@ test('POST /txproposals with denied utxos', async () => { index: 0, tokenId: token2, address: ADDRESSES[1], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1403,7 +1403,7 @@ test('POST /txproposals with denied utxos', async () => { const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH(new hathorLib.Address( ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK), @@ -1450,7 +1450,7 @@ test('POST /txproposals a tx create action on txHex', async () => { index: 0, tokenId: '00', address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1471,7 +1471,7 @@ test('POST /txproposals a tx create action on txHex', async () => { const outputs = [ // change output 100 htr deposited: new hathorLib.Output( - 200, + 200n, new hathorLib.P2PKH( new hathorLib.Address( ADDRESSES[0], { @@ -1507,7 +1507,7 @@ test('POST /txproposals a tx create action on txHex', async () => { ), // New created tokens new hathorLib.Output( - 100 * 100, + 100n * 100n, new hathorLib.P2PKH( new hathorLib.Address( ADDRESSES[0], { @@ -1587,7 +1587,7 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1598,7 +1598,7 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1609,7 +1609,7 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1621,8 +1621,8 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1630,8 +1630,8 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1648,7 +1648,7 @@ test('PUT /txproposals/{proposalId} with txhex', async () => { // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH( new hathorLib.Address(ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK) }), ).createScript(), @@ -1729,7 +1729,7 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in index: 0, tokenId: token1, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1740,7 +1740,7 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in index: 0, tokenId: token1, address: ADDRESSES[0], - value: 100, + value: 100n, authorities: 0, timelock: null, heightlock: null, @@ -1751,7 +1751,7 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in index: 0, tokenId: token2, address: ADDRESSES[0], - value: 300, + value: 300n, authorities: 0, timelock: null, heightlock: null, @@ -1763,8 +1763,8 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in await addToWalletBalanceTable(mysql, [{ walletId: 'my-wallet', tokenId: 'token1', - unlockedBalance: 400, - lockedBalance: 0, + unlockedBalance: 400n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1772,8 +1772,8 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in }, { walletId: 'my-wallet', tokenId: 'token2', - unlockedBalance: 300, - lockedBalance: 0, + unlockedBalance: 300n, + lockedBalance: 0n, unlockedAuthorities: 0, lockedAuthorities: 0, timelockExpires: null, @@ -1790,7 +1790,7 @@ test('PUT /txproposals/{proposalId} with a different txhex than the one sent in // only one output, spending the whole 300 utxo of token1 const outputs = [ new hathorLib.Output( - 300, + 300n, new hathorLib.P2PKH( new hathorLib.Address(ADDRESSES[0], { network: new hathorLib.Network(process.env.NETWORK) }), ).createScript(), @@ -1837,7 +1837,7 @@ test('checkMissingUtxos', async () => { index: 0, tokenId: '00', address: ADDRESSES[0], - value: 0, + value: 0n, authorities: 0, timelock: 0, heightlock: 0, diff --git a/packages/wallet-service/tests/types.test.ts b/packages/wallet-service/tests/types.test.ts index 94d4d195..53ce98b3 100644 --- a/packages/wallet-service/tests/types.test.ts +++ b/packages/wallet-service/tests/types.test.ts @@ -37,23 +37,23 @@ test('Authorities', () => { test('Balance merge', () => { expect.hasAssertions(); - const b1 = new Balance(3, 1, 2, null, new Authorities(0b01), new Authorities(0b00)); - const b2 = new Balance(7, 3, 4, null, new Authorities(0b10), new Authorities(0b11)); - expect(Balance.merge(b1, b2)).toStrictEqual(new Balance(10, 4, 6, null, new Authorities(0b11), new Authorities(0b11))); - - const b3 = new Balance(3, 1, 2, 1000); - const b4 = new Balance(7, 3, 4); - expect(Balance.merge(b3, b4)).toStrictEqual(new Balance(10, 4, 6, 1000)); - expect(Balance.merge(b4, b3)).toStrictEqual(new Balance(10, 4, 6, 1000)); - - const b5 = new Balance(30, 10, 20, 2000); - expect(Balance.merge(b3, b5)).toStrictEqual(new Balance(33, 11, 22, 1000)); - expect(Balance.merge(b5, b3)).toStrictEqual(new Balance(33, 11, 22, 1000)); + const b1 = new Balance(3n, 1n, 2n, null, new Authorities(0b01), new Authorities(0b00)); + const b2 = new Balance(7n, 3n, 4n, null, new Authorities(0b10), new Authorities(0b11)); + expect(Balance.merge(b1, b2)).toStrictEqual(new Balance(10n, 4n, 6n, null, new Authorities(0b11), new Authorities(0b11))); + + const b3 = new Balance(3n, 1n, 2n, 1000); + const b4 = new Balance(7n, 3n, 4n); + expect(Balance.merge(b3, b4)).toStrictEqual(new Balance(10n, 4n, 6n, 1000)); + expect(Balance.merge(b4, b3)).toStrictEqual(new Balance(10n, 4n, 6n, 1000)); + + const b5 = new Balance(30n, 10n, 20n, 2000); + expect(Balance.merge(b3, b5)).toStrictEqual(new Balance(33n, 11n, 22n, 1000)); + expect(Balance.merge(b5, b3)).toStrictEqual(new Balance(33n, 11n, 22n, 1000)); }); test('Balance total and authorities', () => { expect.hasAssertions(); - const b = new Balance(3, 1, 2, null, new Authorities(0b01), new Authorities(0b10)); + const b = new Balance(3n, 1n, 2n, null, new Authorities(0b01), new Authorities(0b10)); expect(b.total()).toBe(3); expect(b.authorities()).toStrictEqual(new Authorities(0b11)); }); @@ -64,7 +64,7 @@ test('TokenBalanceMap basic', () => { // return an empty balance expect(t1.get('token1')).toStrictEqual(new Balance()); // add balance for a token and fetch it again - const b1 = new Balance(14, 5, 9, 1000); + const b1 = new Balance(14n, 5n, 9n, 1000); t1.set('token1', b1); expect(t1.get('token1')).toStrictEqual(b1); // balance for a different token should still be 0 @@ -74,7 +74,7 @@ test('TokenBalanceMap basic', () => { test('TokenBalanceMap clone', () => { expect.hasAssertions(); const t1 = new TokenBalanceMap(); - t1.set('token1', new Balance(14, 5, 9, 1000)); + t1.set('token1', new Balance(14n, 5n, 9n, 1000)); const t2 = t1.clone(); expect(t1).toStrictEqual(t2); expect(t1).not.toBe(t2); @@ -85,8 +85,8 @@ test('TokenBalanceMap clone', () => { test('TokenBalanceMap fromStringMap', () => { expect.hasAssertions(); const t1 = new TokenBalanceMap(); - t1.set('token1', new Balance(15, 0, 15)); - t1.set('token2', new Balance(5, 2, -3, 1000)); + t1.set('token1', new Balance(15n, 0n, 15n)); + t1.set('token2', new Balance(5n, 2n, -3n, 1000)); const t2 = TokenBalanceMap.fromStringMap({ token1: { totalSent: 15, unlocked: 0, locked: 15 }, token2: { totalSent: 5, unlocked: 2, locked: -3, lockExpires: 1000 }, @@ -105,9 +105,9 @@ test('TokenBalanceMap merge', () => { token3: { totalSent: 10, unlocked: 9, locked: 0 }, }); const merged = new TokenBalanceMap(); - merged.set('token1', new Balance(20, 2, 7, 1000)); - merged.set('token2', new Balance(12, 5, 7)); - merged.set('token3', new Balance(10, 9, 0)); + merged.set('token1', new Balance(20n, 2n, 7n, 1000)); + merged.set('token2', new Balance(12n, 5n, 7n)); + merged.set('token3', new Balance(10n, 9n, 0n)); expect(TokenBalanceMap.merge(t1, t2)).toStrictEqual(merged); // with null/undefined parameter @@ -128,7 +128,7 @@ test('TokenBalanceMap fromTxOutput fromTxInput', () => { timelock, }; const txOutput: TxOutput = { - value: 200, + value: 200n, token_data: 0, script: 'not-used', token: '00', @@ -139,7 +139,7 @@ test('TokenBalanceMap fromTxOutput fromTxInput', () => { const txInput: TxInput = { tx_id: '00000000000000029411240dc4aea675b672c260f1419c8a3b87cfa203398098', index: 2, - value: 200, + value: 200n, token_data: 0, script: 'not-used', token: '00', diff --git a/packages/wallet-service/tests/types.ts b/packages/wallet-service/tests/types.ts index 8fdf5601..7cd3a366 100644 --- a/packages/wallet-service/tests/types.ts +++ b/packages/wallet-service/tests/types.ts @@ -22,7 +22,7 @@ export interface AddressTxHistoryTableEntry { address: string; txId: string; tokenId: string; - balance: number; + balance: bigint; timestamp: number; voided?: boolean; } diff --git a/packages/wallet-service/tests/utils.ts b/packages/wallet-service/tests/utils.ts index 2cdf3b76..d33ebccb 100644 --- a/packages/wallet-service/tests/utils.ts +++ b/packages/wallet-service/tests/utils.ts @@ -1034,14 +1034,14 @@ export const buildWalletBalanceValueMap = ( tokenId: 'token1', tokenSymbol: 'T1', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - total: 10, - totalAmountSent: 10, - unlockedAmount: 10, + total: 10n, + totalAmountSent: 10n, + unlockedAmount: 10n, unlockedAuthorities: { melt: false, mint: false, From 332944c31be472b6cc7922ff651e164059673866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Mon, 31 Mar 2025 15:24:47 -0300 Subject: [PATCH 08/31] chore: lockfile updates --- flake.lock | 12 ++++++------ yarn.lock | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 7c1d546f..9df99fe4 100644 --- a/flake.lock +++ b/flake.lock @@ -54,11 +54,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1742923925, - "narHash": "sha256-biPjLws6FiBVUUDHEMFq5pUQL84Wf7PntPYdo3oKkFw=", + "lastModified": 1743320628, + "narHash": "sha256-FurMxmjEEqEMld11eX2vgfAx0Rz0JhoFm8UgxbfCZa8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "25d1b84f5c90632a623c48d83a2faf156451e6b1", + "rev": "63158b9cbb6ec93d26255871c447b0f01da81619", "type": "github" }, "original": { @@ -91,11 +91,11 @@ }, "unstableNixPkgs": { "locked": { - "lastModified": 1742889210, - "narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=", + "lastModified": 1743315132, + "narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "698214a32beb4f4c8e3942372c694f40848b360d", + "rev": "52faf482a3889b7619003c0daec593a1912fddc1", "type": "github" }, "original": { diff --git a/yarn.lock b/yarn.lock index 12065a25..496c34b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15931,11 +15931,11 @@ __metadata: "typescript@patch:typescript@npm%3A5.4.3#optional!builtin": version: 5.4.3 - resolution: "typescript@patch:typescript@npm%3A5.4.3#optional!builtin::version=5.4.3&hash=d69c25" + resolution: "typescript@patch:typescript@npm%3A5.4.3#optional!builtin::version=5.4.3&hash=5adc0c" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/3abea475798fdf7ee46e75dafc50c85f30fd1e7061559ec2af61646f23d16c91742703f04f0ac55be52f58ca05c02f77404b7b94bbad16278c9a54c9eeb4f4ea + checksum: 10/5aedd97595582b08aadb8a70e8e3ddebaf5a9c1e5ad4d6503c2fcfc15329b5cf8d01145b09913e9555683ac16c5123a96be32b6d72614098ebd42df520eed9b1 languageName: node linkType: hard From 039b984c57df0b9bd80254efd3749936b548abd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 1 Apr 2025 11:54:53 -0300 Subject: [PATCH 09/31] tests(daemon): expect bigint values --- packages/daemon/__tests__/db/index.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/daemon/__tests__/db/index.test.ts b/packages/daemon/__tests__/db/index.test.ts index a8bab3a2..233b0c64 100644 --- a/packages/daemon/__tests__/db/index.test.ts +++ b/packages/daemon/__tests__/db/index.test.ts @@ -382,15 +382,15 @@ describe('tx output methods', () => { // { value: 35, address: 'address2', token: 'token1', timelock: null}, let results = await getUtxosLockedAtHeight(mysql, 99, 10); expect(results).toHaveLength(1); - expect(results[0].value).toBe(35); + expect(results[0].value).toBe(35n); // fetch on timestamp=100 and heightlock=10. Should return: // { value: 35, address: 'address2', token: 'token1', timelock: null}, // { value: 45, address: 'address2', token: 'token1', timelock: 100}, results = await getUtxosLockedAtHeight(mysql, 100, 10); expect(results).toHaveLength(2); - expect([35, 45]).toContain(results[0].value); - expect([35, 45]).toContain(results[1].value); + expect([35n, 45n]).toContain(results[0].value); + expect([35n, 45n]).toContain(results[1].value); // fetch on timestamp=100 and heightlock=9. Should return empty results = await getUtxosLockedAtHeight(mysql, 1000, 9); @@ -442,7 +442,7 @@ describe('tx output methods', () => { expect(unlockedUtxos2[1].value).toStrictEqual(outputs[3].value); expect(unlockedUtxos3).toHaveLength(3); // last one is an authority utxo - expect(unlockedUtxos3[2].authorities).toStrictEqual(outputs[4].value); + expect(unlockedUtxos3[2].authorities).toStrictEqual(Number(outputs[4].value)); }); test('getLockedUtxoFromInputs', async () => { @@ -465,7 +465,7 @@ describe('tx output methods', () => { const inputs = utxos.map((utxo, index) => createEventTxInput(utxo.value, utxo.address, txId, index, utxo.timelock)); const results = await getLockedUtxoFromInputs(mysql, inputs); expect(results).toHaveLength(1); - expect(results[0].value).toBe(25); + expect(results[0].value).toBe(25n); }); }); From 004f851f18441760817f11bac957ef34f2493de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 1 Apr 2025 12:16:04 -0300 Subject: [PATCH 10/31] tests: expect bigint values --- packages/wallet-service/tests/db.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 2ce4c9b0..8ce0cdc4 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -519,7 +519,7 @@ test('updateWalletTablesWithTx', async () => { // add tx1 const walletBalanceMap1 = { - walletId: TokenBalanceMap.fromStringMap({ token1: { unlocked: 5, locked: 0, unlockedAuthorities: new Authorities(0b01) } }), + walletId: TokenBalanceMap.fromStringMap({ token1: { unlocked: 5n, locked: 0n, unlockedAuthorities: new Authorities(0b01) } }), }; await updateWalletTablesWithTx(mysql, tx1, ts1, walletBalanceMap1); await expect(checkWalletBalanceTable(mysql, 1, walletId, token1, 5n, 0n, null, 1, 0b01, 0)).resolves.toBe(true); From fd9d9cf17b9038db6da9179911d6e82191c8dbe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 1 Apr 2025 13:01:14 -0300 Subject: [PATCH 11/31] tests: use JSONBigInt where applicabel --- packages/wallet-service/src/db/index.ts | 6 +++--- .../src/utils/pushnotification.utils.ts | 5 +++-- packages/wallet-service/src/ws/utils.ts | 3 ++- packages/wallet-service/tests/types.test.ts | 20 +++++++++---------- .../utils/pushnotification.utils.test.ts | 4 +++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 353fb2aa..a8b83e62 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -8,7 +8,7 @@ import { strict as assert } from 'assert'; import { ServerlessMysql } from 'serverless-mysql'; import { get } from 'lodash'; import { OkPacket } from 'mysql'; -import { constants } from '@hathor/wallet-lib'; +import { constants, bigIntUtils } from '@hathor/wallet-lib'; import { AddressIndexMap, AddressInfo, @@ -1593,7 +1593,7 @@ export const updateVersionData = async (mysql: ServerlessMysql, timestamp: numbe const entry = { id: 1, timestamp, - data: JSON.stringify(data), + data: bigIntUtils.JSONBigInt.stringify(data), }; await mysql.query( @@ -1614,7 +1614,7 @@ export const getVersionData = async (mysql: ServerlessMysql): Promise<{ timestam if (results.length > 0) { const data = results[0]; - const entry: FullNodeApiVersionResponse = JSON.parse(data.data as string); + const entry: FullNodeApiVersionResponse = bigIntUtils.JSONBigInt.parse(data.data as string); const { error } = FullnodeVersionSchema.validate(entry); if (error) { throw error; diff --git a/packages/wallet-service/src/utils/pushnotification.utils.ts b/packages/wallet-service/src/utils/pushnotification.utils.ts index 8e5ef5af..53d84a6a 100644 --- a/packages/wallet-service/src/utils/pushnotification.utils.ts +++ b/packages/wallet-service/src/utils/pushnotification.utils.ts @@ -14,6 +14,7 @@ import createDefaultLogger from '@src/logger'; import config from '@src/config'; import { assertEnvVariablesExistence } from '@wallet-service/common/src/utils/index.utils'; import { addAlert } from '@wallet-service/common/src/utils/alerting.utils'; +import { bigIntUtils } from '@hathor/wallet-lib'; const logger = createDefaultLogger(); @@ -243,7 +244,7 @@ export class PushNotificationUtils { const command = new InvokeCommand({ FunctionName: SEND_NOTIFICATION_FUNCTION_NAME, InvocationType: 'Event', - Payload: JSON.stringify(notification), + Payload: bigIntUtils.JSONBigInt.stringify(notification), }); const response: InvokeCommandOutput = await client.send(command); @@ -279,7 +280,7 @@ export class PushNotificationUtils { const command = new InvokeCommand({ FunctionName: ON_TX_PUSH_NOTIFICATION_REQUESTED_FUNCTION_NAME, InvocationType: 'Event', - Payload: JSON.stringify(walletBalanceValueMap), + Payload: bigIntUtils.JSONBigInt.stringify(walletBalanceValueMap), }); const response: InvokeCommandOutput = await client.send(command); diff --git a/packages/wallet-service/src/ws/utils.ts b/packages/wallet-service/src/ws/utils.ts index 1c28dc33..13cb601e 100644 --- a/packages/wallet-service/src/ws/utils.ts +++ b/packages/wallet-service/src/ws/utils.ts @@ -17,6 +17,7 @@ import util from 'util'; import { Severity } from '@wallet-service/common/src/types'; import { WsConnectionInfo } from '@src/types'; import { endWsConnection } from '@src/redis'; +import { bigIntUtils } from '@hathor/wallet-lib'; const logger = createDefaultLogger(); @@ -64,7 +65,7 @@ export const sendMessageToClient = async ( endpoint: connInfo.url, }); - const message = JSON.stringify(payload); + const message = bigIntUtils.JSONBigInt.stringify(payload); const command = new PostToConnectionCommand({ ConnectionId: connInfo.id, diff --git a/packages/wallet-service/tests/types.test.ts b/packages/wallet-service/tests/types.test.ts index 53ce98b3..ed9a17ea 100644 --- a/packages/wallet-service/tests/types.test.ts +++ b/packages/wallet-service/tests/types.test.ts @@ -54,7 +54,7 @@ test('Balance merge', () => { test('Balance total and authorities', () => { expect.hasAssertions(); const b = new Balance(3n, 1n, 2n, null, new Authorities(0b01), new Authorities(0b10)); - expect(b.total()).toBe(3); + expect(b.total()).toBe(3n); expect(b.authorities()).toStrictEqual(new Authorities(0b11)); }); @@ -88,8 +88,8 @@ test('TokenBalanceMap fromStringMap', () => { t1.set('token1', new Balance(15n, 0n, 15n)); t1.set('token2', new Balance(5n, 2n, -3n, 1000)); const t2 = TokenBalanceMap.fromStringMap({ - token1: { totalSent: 15, unlocked: 0, locked: 15 }, - token2: { totalSent: 5, unlocked: 2, locked: -3, lockExpires: 1000 }, + token1: { totalSent: 15n, unlocked: 0n, locked: 15n }, + token2: { totalSent: 5n, unlocked: 2n, locked: -3n, lockExpires: 1000 }, }); expect(t2).toStrictEqual(t1); }); @@ -97,12 +97,12 @@ test('TokenBalanceMap fromStringMap', () => { test('TokenBalanceMap merge', () => { expect.hasAssertions(); const t1 = TokenBalanceMap.fromStringMap({ - token1: { totalSent: 10, unlocked: 0, locked: 10 }, - token2: { totalSent: 12, unlocked: 5, locked: 7 }, + token1: { totalSent: 10n, unlocked: 0n, locked: 10n }, + token2: { totalSent: 12n, unlocked: 5n, locked: 7n }, }); const t2 = TokenBalanceMap.fromStringMap({ - token1: { totalSent: 10, unlocked: 2, locked: -3, lockExpires: 1000 }, - token3: { totalSent: 10, unlocked: 9, locked: 0 }, + token1: { totalSent: 10n, unlocked: 2n, locked: -3n, lockExpires: 1000 }, + token3: { totalSent: 10n, unlocked: 9n, locked: 0n }, }); const merged = new TokenBalanceMap(); merged.set('token1', new Balance(20n, 2n, 7n, 1000)); @@ -146,10 +146,10 @@ test('TokenBalanceMap fromTxOutput fromTxInput', () => { decoded, }; - expect(TokenBalanceMap.fromTxInput(txInput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 0, unlocked: -txInput.value, locked: 0 } })); - expect(TokenBalanceMap.fromTxOutput(txOutput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 200, unlocked: txOutput.value, locked: 0 } })); + expect(TokenBalanceMap.fromTxInput(txInput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 0n, unlocked: -txInput.value, locked: 0n } })); + expect(TokenBalanceMap.fromTxOutput(txOutput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 200n, unlocked: txOutput.value, locked: 0n } })); // locked txOutput.locked = true; - expect(TokenBalanceMap.fromTxOutput(txOutput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 200, locked: txOutput.value, unlocked: 0, lockExpires: timelock } })); + expect(TokenBalanceMap.fromTxOutput(txOutput)).toStrictEqual(TokenBalanceMap.fromStringMap({ '00': { totalSent: 200n, locked: txOutput.value, unlocked: 0n, lockExpires: timelock } })); }); diff --git a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts index 3a15d80e..515e0ae4 100644 --- a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts +++ b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts @@ -12,6 +12,8 @@ import { sendMock, lambdaInvokeCommandMock } from '@tests/utils/aws-sdk.mock'; import { LambdaClient } from '@aws-sdk/client-lambda'; import { buildWalletBalanceValueMap } from '@tests/utils'; +import { bigIntUtils } from '@hathor/wallet-lib'; + const isFirebaseInitializedMock = jest.spyOn(pushnotificationUtils, 'isFirebaseInitialized'); describe('PushNotificationUtils', () => { @@ -566,7 +568,7 @@ describe('PushNotificationUtils', () => { expect(lambdaInvokeCommandMock).toHaveBeenCalledWith({ FunctionName: buildFunctionName(FunctionName.ON_TX_PUSH_NOTIFICATION_REQUESTED), InvocationType: 'Event', - Payload: JSON.stringify(walletMap), + Payload: bigIntUtils.JSONBigInt.stringify(walletMap), }); }); From 355d2dec33fd4cb9cb2490faf5859c09b5064690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 1 Apr 2025 13:22:30 -0300 Subject: [PATCH 12/31] tests: expect bigint values --- packages/wallet-service/src/db/index.ts | 6 ++-- packages/wallet-service/src/types.ts | 6 ++-- packages/wallet-service/tests/db.test.ts | 40 ++++++++++++------------ packages/wallet-service/tests/utils.ts | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index a8b83e62..58fde1a0 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -2339,8 +2339,8 @@ export const fetchAddressBalance = async ( return results.map((result): AddressBalance => ({ address: result.address as string, tokenId: result.token_id as string, - unlockedBalance: result.unlocked_balance as number, - lockedBalance: result.locked_balance as number, + unlockedBalance: BigInt(result.unlocked_balance as string), + lockedBalance: BigInt(result.locked_balance as string), lockedAuthorities: result.locked_authorities as number, unlockedAuthorities: result.unlocked_authorities as number, timelockExpires: result.timelock_expires as number, @@ -2374,7 +2374,7 @@ export const fetchAddressTxHistorySum = async ( return results.map((result): AddressTotalBalance => ({ address: result.address as string, tokenId: result.token_id as string, - balance: result.balance as number, + balance: BigInt(result.balance as string), transactions: result.transactions as number, })); }; diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index c9d0b197..4b27afdc 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -631,8 +631,8 @@ export interface Tx { export interface AddressBalance { address: string; tokenId: string; - unlockedBalance: number; - lockedBalance: number; + unlockedBalance: bigint; + lockedBalance: bigint; unlockedAuthorities: number; lockedAuthorities: number; timelockExpires: number; @@ -642,7 +642,7 @@ export interface AddressBalance { export interface AddressTotalBalance { address: string; tokenId: string; - balance: number; + balance: bigint; transactions: number; } diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 8ce0cdc4..c2a7a483 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -733,7 +733,7 @@ test('getLockedUtxoFromInputs', async () => { const inputs = utxos.map((utxo, index) => createInput(utxo.value, utxo.address, txId, index, utxo.token, utxo.timelock)); const results = await getLockedUtxoFromInputs(mysql, inputs); expect(results).toHaveLength(1); - expect(results[0].value).toBe(25); + expect(results[0].value).toBe(25n); }); test('updateAddressTablesWithTx', async () => { @@ -1034,15 +1034,15 @@ test('getUtxosLockedAtHeight', async () => { // { value: 35, address: 'address2', token: 'token1', timelock: null}, let results = await getUtxosLockedAtHeight(mysql, 99, 10); expect(results).toHaveLength(1); - expect(results[0].value).toBe(35); + expect(results[0].value).toBe(35n); // fetch on timestamp=100 and heightlock=10. Should return: - // { value: 35, address: 'address2', token: 'token1', timelock: null}, - // { value: 45, address: 'address2', token: 'token1', timelock: 100}, + // { value: 35n, address: 'address2', token: 'token1', timelock: null}, + // { value: 45n, address: 'address2', token: 'token1', timelock: 100}, results = await getUtxosLockedAtHeight(mysql, 100, 10); expect(results).toHaveLength(2); - expect([35, 45]).toContain(results[0].value); - expect([35, 45]).toContain(results[1].value); + expect([35n, 45n]).toContain(results[0].value); + expect([35n, 45n]).toContain(results[1].value); // fetch on timestamp=100 and heightlock=9. Should return empty results = await getUtxosLockedAtHeight(mysql, 1000, 9); @@ -1926,34 +1926,34 @@ test('rebuildAddressBalancesFromUtxos', async () => { const timestamp1 = 10; const utxosTx1 = [ - { value: 5, address: addr1, token: token1, locked: false, spentBy: null }, - { value: 15, address: addr1, token: token1, locked: false, spentBy: null }, - { value: 75, address: addr2, token: token1, heightlock: 70, locked: true, spentBy: null }, - { value: 150, address: addr2, token: token1, heightlock: 70, locked: true, spentBy: null }, - { value: 35, address: addr2, token: token1, locked: false, spentBy: null }, + { value: 5n, address: addr1, token: token1, locked: false, spentBy: null }, + { value: 15n, address: addr1, token: token1, locked: false, spentBy: null }, + { value: 75n, address: addr2, token: token1, heightlock: 70, locked: true, spentBy: null }, + { value: 150n, address: addr2, token: token1, heightlock: 70, locked: true, spentBy: null }, + { value: 35n, address: addr2, token: token1, locked: false, spentBy: null }, - { value: 25, address: addr2, token: token2, timelock: 500, locked: true, spentBy: null }, + { value: 25n, address: addr2, token: token2, timelock: 500, locked: true, spentBy: null }, // authority utxo - { value: 0b11, address: addr1, token: token1, locked: false, tokenData: 129, spentBy: null }, + { value: 0b11n, address: addr1, token: token1, locked: false, tokenData: 129, spentBy: null }, ]; const utxosTx2 = [ // spent utxos - { value: 80, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, - { value: 90, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 80n, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 90n, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, ]; const utxosTx3 = [ // spent utxos - { value: 5, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, - { value: 10, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 5n, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 10n, address: addr2, token: token1, heightlock: 70, locked: false, spentBy: null }, ]; const utxosTx4 = [ // spent utxos - { value: 20, address: addr1, token: token1, heightlock: 70, locked: false, spentBy: null }, - { value: 1, address: addr1, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 20n, address: addr1, token: token1, heightlock: 70, locked: false, spentBy: null }, + { value: 1n, address: addr1, token: token1, heightlock: 70, locked: false, spentBy: null }, ]; const mapUtxoListToOutput = (utxoList: any[]) => utxoList.map((utxo, index) => createOutput( @@ -2016,7 +2016,7 @@ test('rebuildAddressBalancesFromUtxos', async () => { const addressBalances = await fetchAddressBalance(mysql, [addr1, addr2]); - expect(addressBalances[0].unlockedBalance).toStrictEqual(41); + expect(addressBalances[0].unlockedBalance).toStrictEqual(41n); expect(addressBalances[0].unlockedAuthorities).toStrictEqual(0b11); expect(addressBalances[0].address).toStrictEqual(addr1); expect(addressBalances[0].transactions).toStrictEqual(1); diff --git a/packages/wallet-service/tests/utils.ts b/packages/wallet-service/tests/utils.ts index d33ebccb..046be12a 100644 --- a/packages/wallet-service/tests/utils.ts +++ b/packages/wallet-service/tests/utils.ts @@ -563,7 +563,7 @@ export const countTxOutputTable = async ( ); if (results.length > 0) { - return results[0].count as number; + return Number(results[0].count); } return 0; From 6f5dc2678da8747e6b1fe66417b8eba9ce581991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Wed, 2 Apr 2025 16:25:08 -0300 Subject: [PATCH 13/31] tests: expect bigint values --- packages/daemon/src/actions/index.ts | 1 + packages/wallet-service/src/types.ts | 8 +-- packages/wallet-service/src/utils.ts | 1 + packages/wallet-service/tests/db.test.ts | 62 ++++++++++++------------ 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/daemon/src/actions/index.ts b/packages/daemon/src/actions/index.ts index 91d6f4bd..59eaea31 100644 --- a/packages/daemon/src/actions/index.ts +++ b/packages/daemon/src/actions/index.ts @@ -35,6 +35,7 @@ export const storeInitialState = assign({ * to the original event (that initiated the metadata diff check) */ export const unwrapEvent = assign({ + // @ts-ignore: The return event.event.originalEvent.event is not the correct type for an event. event: (_context: Context, event: Event) => { if (event.type !== 'METADATA_DECIDED') { throw new Error(`Received unhandled ${event.type} on unwrapEvent action`); diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index 4b27afdc..6d2dcdcd 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -681,8 +681,8 @@ export interface IFilterTxOutput { tokenId?: string; authority?: number; ignoreLocked?: boolean; - biggerThan?: number; - smallerThan?: number; + biggerThan?: bigint; + smallerThan?: bigint; maxOutputs?: number; skipSpent?: boolean; txId?: string; @@ -695,8 +695,8 @@ export enum InputSelectionAlgo { export interface IWalletInsufficientFunds { tokenId: string; - requested: number; - available: number; + requested: bigint; + available: bigint; } export interface DbTxOutputWithPath extends DbTxOutput { diff --git a/packages/wallet-service/src/utils.ts b/packages/wallet-service/src/utils.ts index b8815521..21737f2b 100644 --- a/packages/wallet-service/src/utils.ts +++ b/packages/wallet-service/src/utils.ts @@ -48,6 +48,7 @@ export const sha256d = (data: string, encoding: BinaryToTextEncoding): string => const hash1 = createHash('sha256'); hash1.update(data); const hash2 = createHash('sha256'); + // @ts-ignore: `digest` returns a Buffer which is not a BinaryLike required by `update` hash2.update(hash1.digest()); return hash2.digest(encoding); }; diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index c2a7a483..259bce22 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -973,14 +973,14 @@ test('getWalletBalances', async () => { for (const balance of returnedBalances) { if (balance.token.id === token1.id) { expect(balance.token).toStrictEqual(token1); - expect(balance.balance.unlockedAmount).toBe(10); - expect(balance.balance.lockedAmount).toBe(4); + expect(balance.balance.unlockedAmount).toBe(10n); + expect(balance.balance.lockedAmount).toBe(4n); expect(balance.balance.lockExpires).toBe(now); expect(balance.transactions).toBe(1); } else { expect(balance.token).toStrictEqual(token2); - expect(balance.balance.unlockedAmount).toBe(20); - expect(balance.balance.lockedAmount).toBe(5); + expect(balance.balance.unlockedAmount).toBe(20n); + expect(balance.balance.lockedAmount).toBe(5n); expect(balance.transactions).toBe(2); expect(balance.balance.lockExpires).toBe(now); } @@ -994,8 +994,8 @@ test('getWalletBalances', async () => { returnedBalances = await getWalletBalances(mysql, walletId, [token2.id]); expect(returnedBalances).toHaveLength(1); expect(returnedBalances[0].token).toStrictEqual(token2); - expect(returnedBalances[0].balance.unlockedAmount).toBe(20); - expect(returnedBalances[0].balance.lockedAmount).toBe(5); + expect(returnedBalances[0].balance.unlockedAmount).toBe(20n); + expect(returnedBalances[0].balance.lockedAmount).toBe(5n); expect(returnedBalances[0].balance.lockExpires).toBe(now); expect(returnedBalances[0].transactions).toBe(2); @@ -1390,13 +1390,13 @@ test('getWalletSortedValueUtxos', async () => { const utxos = await getWalletSortedValueUtxos(mysql, walletId, tokenId); expect(utxos).toHaveLength(3); expect(utxos[0]).toStrictEqual({ - txId, index: 6, tokenId, address: addr1, value: 7, authorities: 0, timelock: null, heightlock: null, locked: false, + txId, index: 6, tokenId, address: addr1, value: 7n, authorities: 0, timelock: null, heightlock: null, locked: false, }); expect(utxos[1]).toStrictEqual({ - txId, index: 4, tokenId, address: addr1, value: 4, authorities: 0, timelock: null, heightlock: null, locked: false, + txId, index: 4, tokenId, address: addr1, value: 4n, authorities: 0, timelock: null, heightlock: null, locked: false, }); expect(utxos[2]).toStrictEqual({ - txId, index: 5, tokenId, address: addr2, value: 1, authorities: 0, timelock: null, heightlock: null, locked: false, + txId, index: 5, tokenId, address: addr2, value: 1n, authorities: 0, timelock: null, heightlock: null, locked: false, }); }); @@ -1680,8 +1680,8 @@ test('fetchAddressTxHistorySum', async () => { const history = await fetchAddressTxHistorySum(mysql, [addr1, addr2]); - expect(history[0].balance).toStrictEqual(60); - expect(history[1].balance).toStrictEqual(50); + expect(history[0].balance).toStrictEqual(60n); + expect(history[1].balance).toStrictEqual(50n); }); test('fetchAddressBalance', async () => { @@ -1710,30 +1710,30 @@ test('fetchAddressBalance', async () => { expect(addressBalances[0].address).toStrictEqual('addr1'); expect(addressBalances[0].tokenId).toStrictEqual('token1'); - expect(addressBalances[0].unlockedBalance).toStrictEqual(2); - expect(addressBalances[0].lockedBalance).toStrictEqual(0); + expect(addressBalances[0].unlockedBalance).toStrictEqual(2n); + expect(addressBalances[0].lockedBalance).toStrictEqual(0n); expect(addressBalances[1].address).toStrictEqual('addr1'); expect(addressBalances[1].tokenId).toStrictEqual('token2'); - expect(addressBalances[1].unlockedBalance).toStrictEqual(1); - expect(addressBalances[1].lockedBalance).toStrictEqual(4); + expect(addressBalances[1].unlockedBalance).toStrictEqual(1n); + expect(addressBalances[1].lockedBalance).toStrictEqual(4n); expect(addressBalances[2].address).toStrictEqual('addr2'); expect(addressBalances[2].tokenId).toStrictEqual('token1'); - expect(addressBalances[2].unlockedBalance).toStrictEqual(5); - expect(addressBalances[2].lockedBalance).toStrictEqual(2); + expect(addressBalances[2].unlockedBalance).toStrictEqual(5n); + expect(addressBalances[2].lockedBalance).toStrictEqual(2n); expect(addressBalances[3].address).toStrictEqual('addr2'); expect(addressBalances[3].tokenId).toStrictEqual('token2'); - expect(addressBalances[3].unlockedBalance).toStrictEqual(0); - expect(addressBalances[3].lockedBalance).toStrictEqual(2); + expect(addressBalances[3].unlockedBalance).toStrictEqual(0n); + expect(addressBalances[3].lockedBalance).toStrictEqual(2n); expect(addressBalances[4].address).toStrictEqual('addr3'); expect(addressBalances[4].tokenId).toStrictEqual('token1'); - expect(addressBalances[4].unlockedBalance).toStrictEqual(0); - expect(addressBalances[4].lockedBalance).toStrictEqual(1); + expect(addressBalances[4].unlockedBalance).toStrictEqual(0n); + expect(addressBalances[4].lockedBalance).toStrictEqual(1n); expect(addressBalances[5].address).toStrictEqual('addr3'); expect(addressBalances[5].tokenId).toStrictEqual('token2'); - expect(addressBalances[5].unlockedBalance).toStrictEqual(10); - expect(addressBalances[5].lockedBalance).toStrictEqual(1); + expect(addressBalances[5].unlockedBalance).toStrictEqual(10n); + expect(addressBalances[5].lockedBalance).toStrictEqual(1n); }); test('addTx, fetchTx, getTransactionsById and markTxsAsVoided', async () => { @@ -2022,8 +2022,8 @@ test('rebuildAddressBalancesFromUtxos', async () => { expect(addressBalances[0].transactions).toStrictEqual(1); expect(addressBalances[0].tokenId).toStrictEqual('token1'); - expect(addressBalances[1].unlockedBalance).toStrictEqual(220); - expect(addressBalances[1].lockedBalance).toStrictEqual(225); + expect(addressBalances[1].unlockedBalance).toStrictEqual(220n); + expect(addressBalances[1].lockedBalance).toStrictEqual(225n); expect(addressBalances[1].address).toStrictEqual(addr2); expect(addressBalances[1].transactions).toStrictEqual(2); expect(addressBalances[1].tokenId).toStrictEqual('token1'); @@ -2218,14 +2218,14 @@ test('filterTxOutputs', async () => { expect(utxos).toHaveLength(2); // filter all utxos between 100 and 1500 - utxos = await filterTxOutputs(mysql, { addresses: [addr1, addr2], tokenId, biggerThan: 100, smallerThan: 1500 }); + utxos = await filterTxOutputs(mysql, { addresses: [addr1, addr2], tokenId, biggerThan: 100n, smallerThan: 1500n }); expect(utxos).toHaveLength(2); expect(utxos[0]).toStrictEqual({ txId: txId2, index: 1, tokenId, address: addr1, - value: 1000, + value: 1000n, authorities: 0, timelock: null, heightlock: null, @@ -2239,7 +2239,7 @@ test('filterTxOutputs', async () => { index: 0, tokenId, address: addr1, - value: 500, + value: 500n, authorities: 0, timelock: null, heightlock: null, @@ -2257,7 +2257,7 @@ test('filterTxOutputs', async () => { index: 2, tokenId, address: addr2, - value: 1500, + value: 1500n, authorities: 0, timelock: null, heightlock: null, @@ -2271,7 +2271,7 @@ test('filterTxOutputs', async () => { index: 1, tokenId, address: addr1, - value: 1000, + value: 1000n, authorities: 0, timelock: null, heightlock: null, @@ -2282,7 +2282,7 @@ test('filterTxOutputs', async () => { }); // authorities != 0 and maxOutputs == 1 should return only one authority utxo - utxos = await filterTxOutputs(mysql, { addresses: [addr1, addr2], biggerThan: 0, smallerThan: 3, authority: 1, tokenId, maxOutputs: 1 }); + utxos = await filterTxOutputs(mysql, { addresses: [addr1, addr2], biggerThan: 0n, smallerThan: 3n, authority: 1, tokenId, maxOutputs: 1 }); expect(utxos).toHaveLength(1); }); From d81149c11e41ce76f0ccbd3b8fa20b18ca87960c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Wed, 2 Apr 2025 17:04:12 -0300 Subject: [PATCH 14/31] tests: expect bigint values --- packages/wallet-service/src/api/totalSupply.ts | 4 ++-- packages/wallet-service/src/api/txById.ts | 3 ++- packages/wallet-service/src/db/index.ts | 14 +++++++------- packages/wallet-service/src/types.ts | 2 +- packages/wallet-service/tests/db.test.ts | 14 +++++++------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/wallet-service/src/api/totalSupply.ts b/packages/wallet-service/src/api/totalSupply.ts index 5698bb2d..767b8607 100644 --- a/packages/wallet-service/src/api/totalSupply.ts +++ b/packages/wallet-service/src/api/totalSupply.ts @@ -50,13 +50,13 @@ export const onTotalSupplyRequest: APIGatewayProxyHandler = middy(async (event) } const tokenId = value.tokenId; - const totalSupply: number = await getTotalSupply(mysql, tokenId); + const totalSupply: bigint = await getTotalSupply(mysql, tokenId); await closeDbConnection(mysql); return { statusCode: 200, - body: JSON.stringify({ + body: hathorLib.bigIntUtils.JSONBigInt.stringify({ success: true, totalSupply, }), diff --git a/packages/wallet-service/src/api/txById.ts b/packages/wallet-service/src/api/txById.ts index 7e6f25af..a65da733 100644 --- a/packages/wallet-service/src/api/txById.ts +++ b/packages/wallet-service/src/api/txById.ts @@ -15,6 +15,7 @@ import middy from '@middy/core'; import cors from '@middy/http-cors'; import Joi, { ValidationError } from 'joi'; import { TxByIdRequest } from '@src/types'; +import { bigIntUtils } from '@hathor/wallet-lib'; const mysql = getDbConnection(); @@ -55,7 +56,7 @@ export const get: APIGatewayProxyHandler = middy(walletIdProxyHandler(async (wal return { statusCode: 200, - body: JSON.stringify({ success: true, txTokens }), + body: bigIntUtils.JSONBigInt.stringify({ success: true, txTokens }), }; })) .use(cors()) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 58fde1a0..071938cf 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -2556,7 +2556,7 @@ export const getMinersList = async ( address: result.address as string, firstBlock: result.first_block as string, lastBlock: result.last_block as string, - count: result.count as number, + count: Number(result.count), }); } @@ -2573,7 +2573,7 @@ export const getMinersList = async ( export const getTotalSupply = async ( mysql: ServerlessMysql, tokenId: string, -): Promise => { +): Promise => { const results: DbSelectResult = await mysql.query(` SELECT SUM(value) as value FROM tx_output @@ -2595,7 +2595,7 @@ export const getTotalSupply = async ( throw new Error('Total supply query returned no results'); } - return results[0].value as number; + return BigInt(results[0].value as string); }; /** @@ -2654,7 +2654,7 @@ export const getTotalTransactions = async ( throw new Error('Total transactions query returned no results'); } - return results[0].count as number; + return Number(results[0].count as string); }; /** @@ -2714,7 +2714,7 @@ export const getAffectedAddressTxCountFromTxList = async ( const addressTransactions = results.reduce((acc, result) => { const address = result.address as string; - const txCount = result.txCount as number; + const txCount = Number(result.txCount); const tokenId = result.tokenId as string; acc[`${address}_${tokenId}`] = txCount; @@ -2976,7 +2976,7 @@ export const getTransactionById = async ( const txTokens = []; result.forEach((eachTxToken) => { - const txToken = { + const txToken: TxByIdToken = { txId: eachTxToken.tx_id, timestamp: eachTxToken.timestamp, version: eachTxToken.version, @@ -2986,7 +2986,7 @@ export const getTransactionById = async ( tokenId: eachTxToken.token_id, tokenName: eachTxToken.name, tokenSymbol: eachTxToken.symbol, - } as TxByIdToken; + }; txTokens.push(txToken); }); diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index 6d2dcdcd..7b0207cc 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -746,7 +746,7 @@ export interface TxByIdToken { version: number; voided: boolean; weight: number; - balance: Balance; + balance: bigint; tokenId: string; tokenName: string; tokenSymbol: string; diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 259bce22..a89cc851 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -2028,7 +2028,7 @@ test('rebuildAddressBalancesFromUtxos', async () => { expect(addressBalances[1].transactions).toStrictEqual(2); expect(addressBalances[1].tokenId).toStrictEqual('token1'); - expect(addressBalances[2].lockedBalance).toStrictEqual(25); + expect(addressBalances[2].lockedBalance).toStrictEqual(25n); expect(addressBalances[2].address).toStrictEqual(addr2); expect(addressBalances[2].transactions).toStrictEqual(1); expect(addressBalances[2].tokenId).toStrictEqual('token2'); @@ -2455,9 +2455,9 @@ test('getTotalSupply', async () => { await addUtxos(mysql, txId, outputs); - expect(await getTotalSupply(mysql, '00')).toStrictEqual(20); - expect(await getTotalSupply(mysql, 'token2')).toStrictEqual(25); - expect(await getTotalSupply(mysql, 'token1')).toStrictEqual(35); + expect(await getTotalSupply(mysql, '00')).toStrictEqual(20n); + expect(await getTotalSupply(mysql, 'token2')).toStrictEqual(25n); + expect(await getTotalSupply(mysql, 'token1')).toStrictEqual(35n); const mysqlQuerySpy = jest.spyOn(mysql, 'query'); mysqlQuerySpy.mockImplementationOnce(() => Promise.resolve({ length: null })); @@ -2513,7 +2513,7 @@ test('getExpiredTimelocksUtxos', async () => { expect(unlockedUtxos2[1].value).toStrictEqual(outputs[3].value); expect(unlockedUtxos3).toHaveLength(3); // last one is an authority utxo - expect(unlockedUtxos3[2].authorities).toStrictEqual(outputs[4].value); + expect(unlockedUtxos3[2].authorities).toStrictEqual(Number(outputs[4].value)); }); test('getTotalTransactions', async () => { @@ -2638,8 +2638,8 @@ test('getUtxo, getAuthorityUtxo', async () => { index: 0, tokenId, address: addr1, - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: 10000, heightlock: null, locked: true, From e392fd02fdd7a26082fd4b1bfd78a33bb0078224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Mon, 7 Apr 2025 13:06:19 -0300 Subject: [PATCH 15/31] chore: lock update --- yarn.lock | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index b8f587ac..496c34b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5199,6 +5199,21 @@ __metadata: languageName: node linkType: hard +"abstract-level@npm:1.0.4, abstract-level@npm:^1.0.2, abstract-level@npm:^1.0.4": + version: 1.0.4 + resolution: "abstract-level@npm:1.0.4" + dependencies: + buffer: "npm:^6.0.3" + catering: "npm:^2.1.0" + is-buffer: "npm:^2.0.5" + level-supports: "npm:^4.0.0" + level-transcoder: "npm:^1.0.1" + module-error: "npm:^1.0.1" + queue-microtask: "npm:^1.2.3" + checksum: 10/8edf4cf55b7b66b653296f53a643bcf1501074be099d8c44351595cd33f769b7b2aed216d5fffe1c99ebea4acf14f5ae093e98baa60ea1d236ea8a3387350ebb + languageName: node + linkType: hard + "acorn-import-assertions@npm:^1.9.0": version: 1.9.0 resolution: "acorn-import-assertions@npm:1.9.0" @@ -6184,6 +6199,18 @@ __metadata: languageName: node linkType: hard +"browser-level@npm:^1.0.1": + version: 1.0.1 + resolution: "browser-level@npm:1.0.1" + dependencies: + abstract-level: "npm:^1.0.2" + catering: "npm:^2.1.1" + module-error: "npm:^1.0.2" + run-parallel-limit: "npm:^1.1.0" + checksum: 10/e712569111782da76853fecf648b43ff878ff2301c2830a9e7399685b646824a85f304dea5f023e02ee41a63a972f9aad734bd411069095adc9c79784fc649a5 + languageName: node + linkType: hard + "browserify-aes@npm:^1.0.6": version: 1.2.0 resolution: "browserify-aes@npm:1.2.0" @@ -6346,7 +6373,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:6.0.3": +"buffer@npm:6.0.3, buffer@npm:^6.0.3": version: 6.0.3 resolution: "buffer@npm:6.0.3" dependencies: @@ -6523,6 +6550,13 @@ __metadata: languageName: node linkType: hard +"catering@npm:^2.1.0, catering@npm:^2.1.1": + version: 2.1.1 + resolution: "catering@npm:2.1.1" + checksum: 10/4669c9fa5f3a73273535fb458a964d8aba12dc5102d8487049cf03623bef3cdff4b5d9f92ff04c00f1001057a7cc7df6e700752ac622c2a7baf7bcff34166683 + languageName: node + linkType: hard + "chalk@npm:^2.4.1, chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" @@ -6655,6 +6689,20 @@ __metadata: languageName: node linkType: hard +"classic-level@npm:^1.2.0": + version: 1.4.1 + resolution: "classic-level@npm:1.4.1" + dependencies: + abstract-level: "npm:^1.0.2" + catering: "npm:^2.1.0" + module-error: "npm:^1.0.1" + napi-macros: "npm:^2.2.2" + node-gyp: "npm:latest" + node-gyp-build: "npm:^4.3.0" + checksum: 10/11f9362301477cb5cf3b147e5846754e0e4296231e265145101403f4a5cb797a685b6a9b6b4c880a42b05772f846a222a5a7a563262ca15b5ca03e25e9a805db + languageName: node + linkType: hard + "clean-stack@npm:^2.0.0": version: 2.2.0 resolution: "clean-stack@npm:2.2.0" @@ -10081,6 +10129,13 @@ __metadata: languageName: node linkType: hard +"is-buffer@npm:^2.0.5": + version: 2.0.5 + resolution: "is-buffer@npm:2.0.5" + checksum: 10/3261a8b858edcc6c9566ba1694bf829e126faa88911d1c0a747ea658c5d81b14b6955e3a702d59dabadd58fdd440c01f321aa71d6547105fd21d03f94d0597e7 + languageName: node + linkType: hard + "is-builtin-module@npm:^3.2.1": version: 3.2.1 resolution: "is-builtin-module@npm:3.2.1" @@ -12231,6 +12286,13 @@ __metadata: languageName: node linkType: hard +"module-error@npm:^1.0.1, module-error@npm:^1.0.2": + version: 1.0.2 + resolution: "module-error@npm:1.0.2" + checksum: 10/5d653e35bd55b3e95f8aee2cdac108082ea892e71b8f651be92cde43e4ee86abee4fa8bd7fc3fe5e68b63926d42f63c54cd17b87a560c31f18739295575a3962 + languageName: node + linkType: hard + "moment-timezone@npm:^0.5.43": version: 0.5.43 resolution: "moment-timezone@npm:0.5.43" @@ -12360,6 +12422,13 @@ __metadata: languageName: node linkType: hard +"napi-macros@npm:^2.2.2": + version: 2.2.2 + resolution: "napi-macros@npm:2.2.2" + checksum: 10/2cdb9c40ad4b424b14fbe5e13c5329559e2b511665acf41cdcda172fd2270202dc747a2d288b687c72bc70f654c797bc24a93adb67631128d62461588d7cc070 + languageName: node + linkType: hard + "native-promise-only@npm:^0.8.1": version: 0.8.1 resolution: "native-promise-only@npm:0.8.1" @@ -13469,7 +13538,7 @@ __metadata: languageName: node linkType: hard -"queue-microtask@npm:1.2.3, queue-microtask@npm:^1.2.2": +"queue-microtask@npm:1.2.3, queue-microtask@npm:^1.2.2, queue-microtask@npm:^1.2.3": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" checksum: 10/72900df0616e473e824202113c3df6abae59150dfb73ed13273503127235320e9c8ca4aaaaccfd58cf417c6ca92a6e68ee9a5c3182886ae949a768639b388a7b From 2165e497055dd0b4ca026a0b90cc8dec07cbb1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Mon, 7 Apr 2025 15:38:23 -0300 Subject: [PATCH 16/31] chore: lock update --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index eb0baca0..61a186de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15952,11 +15952,11 @@ __metadata: "typescript@patch:typescript@npm%3A^5.8.2#optional!builtin": version: 5.8.2 - resolution: "typescript@patch:typescript@npm%3A5.8.2#optional!builtin::version=5.8.2&hash=d69c25" + resolution: "typescript@patch:typescript@npm%3A5.8.2#optional!builtin::version=5.8.2&hash=5786d5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10/6ae9b2c4d3254ec2eaee6f26ed997e19c02177a212422993209f81e87092b2bb0a4738085549c5b0164982a5609364c047c72aeb281f6c8d802cd0d1c6f0d353 + checksum: 10/97920a082ffc57583b1cb6bc4faa502acc156358e03f54c7fc7fdf0b61c439a717f4c9070c449ee9ee683d4cfc3bb203127c2b9794b2950f66d9d307a4ff262c languageName: node linkType: hard From 8e53fe953885c0a89f07ce031d1ab4317286f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 16:06:54 -0300 Subject: [PATCH 17/31] chore: parse using JSONbigint --- packages/wallet-service/src/api/txOutputs.ts | 10 +++++----- packages/wallet-service/src/db/index.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/wallet-service/src/api/txOutputs.ts b/packages/wallet-service/src/api/txOutputs.ts index 51c68da4..7cf3323a 100644 --- a/packages/wallet-service/src/api/txOutputs.ts +++ b/packages/wallet-service/src/api/txOutputs.ts @@ -16,7 +16,7 @@ import { } from '@src/types'; import { closeDbAndGetError } from '@src/api/utils'; import { getDbConnection } from '@src/utils'; -import { constants } from '@hathor/wallet-lib'; +import { constants, bigIntUtils } from '@hathor/wallet-lib'; import middy from '@middy/core'; import cors from '@middy/http-cors'; import errorHandler from '@src/api/middlewares/errorHandler'; @@ -95,11 +95,11 @@ export const getFilteredUtxos = middy(walletIdProxyHandler(async (walletId, even // The /wallet/utxos API expects `utxos` on the response body, we should transform the // response accordingly if (response.statusCode === 200) { - const body = JSON.parse(response.body); + const body = bigIntUtils.JSONBigInt.parse(response.body); body.utxos = body.txOutputs; delete body.txOutputs; - response.body = JSON.stringify(body); + response.body = bigIntUtils.JSONBigInt.stringify(body); } return response; @@ -168,7 +168,7 @@ const _getFilteredTxOutputs = async (walletId: string, filters: IFilterTxOutput) return { statusCode: 200, - body: JSON.stringify({ + body: bigIntUtils.JSONBigInt.stringify({ success: true, txOutputs: txOutputList, }), @@ -194,7 +194,7 @@ const _getFilteredTxOutputs = async (walletId: string, filters: IFilterTxOutput) return { statusCode: 200, - body: JSON.stringify({ + body: bigIntUtils.JSONBigInt.stringify({ success: true, txOutputs: txOutputsWithPath, }), diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 071938cf..8f8c83ad 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -2982,7 +2982,7 @@ export const getTransactionById = async ( version: eachTxToken.version, voided: !!eachTxToken.voided, weight: eachTxToken.weight, - balance: eachTxToken.balance, + balance: BigInt(eachTxToken.balance), tokenId: eachTxToken.token_id, tokenName: eachTxToken.name, tokenSymbol: eachTxToken.symbol, From b2f7e70dd4efa5386cf5d8b774c8aca8d244c18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 16:58:56 -0300 Subject: [PATCH 18/31] chore: parse using JSONbigint --- packages/wallet-service/src/api/balances.ts | 3 ++- packages/wallet-service/src/db/index.ts | 2 +- packages/wallet-service/tests/db.test.ts | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/wallet-service/src/api/balances.ts b/packages/wallet-service/src/api/balances.ts index bed929cf..e5daac65 100644 --- a/packages/wallet-service/src/api/balances.ts +++ b/packages/wallet-service/src/api/balances.ts @@ -23,6 +23,7 @@ import middy from '@middy/core'; import cors from '@middy/http-cors'; import Joi from 'joi'; import errorHandler from '@src/api/middlewares/errorHandler'; +import { bigIntUtils } from '@hathor/wallet-lib'; const mysql = getDbConnection(); @@ -79,7 +80,7 @@ export const get: APIGatewayProxyHandler = middy(walletIdProxyHandler(async (wal return { statusCode: 200, - body: JSON.stringify({ success: true, balances }), + body: bigIntUtils.JSONBigInt.stringify({ success: true, balances }), }; })).use(cors()) .use(warmupMiddleware()) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 8f8c83ad..79cdebf2 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -3092,7 +3092,7 @@ export const countStalePushDevices = async (mysql: ServerlessMysql): Promise; - return count; + return Number(count); }; /** diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index a89cc851..7cda0a53 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -1580,7 +1580,7 @@ test('createTxProposal, updateTxProposal, getTxProposal, countUnsentTxProposals, // Release txProposalUtxos should properly release the utxos. This method will throw an error if the // updated count is different from the sent tx proposals count. await releaseTxProposalUtxos(mysql, [txProposalId1, txProposalId2, txProposalId3]); - await expect(releaseTxProposalUtxos(mysql, ['invalid-tx-proposal'])).rejects.toMatchInlineSnapshot('[AssertionError: Not all utxos were correctly updated]'); + await expect(releaseTxProposalUtxos(mysql, ['invalid-tx-proposal'])).rejects.toThrow('AssertionError: Not all utxos were correctly updated'); }); test('updateVersionData', async () => { @@ -2656,8 +2656,8 @@ test('getUtxo, getAuthorityUtxo', async () => { index: 0, tokenId, address: addr1, - value: 0, - authorities: constants.TOKEN_MINT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MINT_MASK), timelock: 10000, heightlock: null, locked: true, @@ -2670,8 +2670,8 @@ test('getUtxo, getAuthorityUtxo', async () => { index: 1, tokenId, address: addr1, - value: 0, - authorities: constants.TOKEN_MELT_MASK, + value: 0n, + authorities: Number(constants.TOKEN_MELT_MASK), timelock: 10000, heightlock: null, locked: true, @@ -3122,7 +3122,7 @@ describe('getTransactionById', () => { const [secondToken] = txTokens.filter((eachToken) => eachToken.tokenId === 'token2'); expect(firstToken).toStrictEqual({ - balance: 10, + balance: 10n, timestamp: timestamp1, tokenId: token1.id, tokenName: token1.name, @@ -3133,7 +3133,7 @@ describe('getTransactionById', () => { weight: weight1, }); expect(secondToken).toStrictEqual({ - balance: 7, + balance: 7n, timestamp: timestamp1, tokenId: token2.id, tokenName: token2.name, From 687cf2c00606bd77f87b7bc4095f5ef3a8d4470c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 17:41:06 -0300 Subject: [PATCH 19/31] chore: parse using JSONbigint --- packages/wallet-service/src/api/tokens.ts | 4 +- packages/wallet-service/src/api/txhistory.ts | 4 +- packages/wallet-service/src/db/index.ts | 2 +- packages/wallet-service/src/types.ts | 2 +- packages/wallet-service/tests/commons.test.ts | 56 +++++++++---------- .../wallet-service/tests/txOutputs.test.ts | 9 +-- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/packages/wallet-service/src/api/tokens.ts b/packages/wallet-service/src/api/tokens.ts index 3b062bc8..2325a5ae 100644 --- a/packages/wallet-service/src/api/tokens.ts +++ b/packages/wallet-service/src/api/tokens.ts @@ -15,7 +15,7 @@ import { getDbConnection } from '@src/utils'; import { ApiError } from '@src/api/errors'; import { closeDbAndGetError, warmupMiddleware, txIdJoiValidator } from '@src/api/utils'; import Joi from 'joi'; -import { constants } from '@hathor/wallet-lib'; +import { bigIntUtils, constants } from '@hathor/wallet-lib'; import middy from '@middy/core'; import cors from '@middy/http-cors'; import errorHandler from '@src/api/middlewares/errorHandler'; @@ -100,7 +100,7 @@ export const getTokenDetails = middy(walletIdProxyHandler(async (walletId, event return { statusCode: 200, - body: JSON.stringify({ + body: bigIntUtils.JSONBigInt.stringify({ success: true, details: { tokenInfo, diff --git a/packages/wallet-service/src/api/txhistory.ts b/packages/wallet-service/src/api/txhistory.ts index 4c9a0c15..ff5e4bcc 100644 --- a/packages/wallet-service/src/api/txhistory.ts +++ b/packages/wallet-service/src/api/txhistory.ts @@ -6,7 +6,7 @@ */ import 'source-map-support/register'; -import hathorLib from '@hathor/wallet-lib'; +import hathorLib, { bigIntUtils } from '@hathor/wallet-lib'; import { ApiError } from '@src/api/errors'; import { closeDbAndGetError, warmupMiddleware } from '@src/api/utils'; @@ -85,7 +85,7 @@ export const get = middy(walletIdProxyHandler(async (walletId, event) => { return { statusCode: 200, - body: JSON.stringify({ success: true, history, skip, count }), + body: bigIntUtils.JSONBigInt.stringify({ success: true, history, skip, count }), }; })).use(cors()) .use(warmupMiddleware()) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index 79cdebf2..f28629a3 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -1472,7 +1472,7 @@ LEFT OUTER JOIN transaction ON transaction.tx_id = wallet_tx_history.tx_id txId: result.tx_id, timestamp: result.timestamp, voided: result.voided, - balance: result.balance, + balance: BigInt(result.balance as string), version: result.version, }; history.push(tx); diff --git a/packages/wallet-service/src/types.ts b/packages/wallet-service/src/types.ts index 7b0207cc..e550655e 100644 --- a/packages/wallet-service/src/types.ts +++ b/packages/wallet-service/src/types.ts @@ -447,7 +447,7 @@ export interface TxTokenBalance { txId: string; timestamp: number; voided: boolean; - balance: Balance; + balance: bigint; version: number; } diff --git a/packages/wallet-service/tests/commons.test.ts b/packages/wallet-service/tests/commons.test.ts index 72bbabaf..082a70fd 100644 --- a/packages/wallet-service/tests/commons.test.ts +++ b/packages/wallet-service/tests/commons.test.ts @@ -811,18 +811,18 @@ describe('getWalletBalancesForTx', () => { tokenId: 'token1', tokenSymbol: 'T1', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - totalAmountSent: 0, - unlockedAmount: -5, + totalAmountSent: 0n, + unlockedAmount: -5n, unlockedAuthorities: { melt: false, mint: false, }, - total: -5, + total: -5n, }, ], }, @@ -873,16 +873,16 @@ describe('getWalletBalancesForTx', () => { // instantiate token balance const balanceToken1 = { - unlocked: 5, - locked: 0, + unlocked: 5n, + locked: 0n, lockExpires: null, transactions: 1, unlockedAuthorities: new Authorities(0b01), lockedAuthorities: 0, }; const balanceToken2 = { - unlocked: 10, - locked: 0, + unlocked: 10n, + locked: 0n, lockExpires: null, transactions: 1, unlockedAuthorities: new Authorities(0b01), @@ -964,14 +964,14 @@ describe('getWalletBalancesForTx', () => { tokenId: 'token2', tokenSymbol: 'T2', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - total: -10, - totalAmountSent: 0, - unlockedAmount: -10, + total: -10n, + totalAmountSent: 0n, + unlockedAmount: -10n, unlockedAuthorities: { melt: false, mint: false, @@ -981,18 +981,18 @@ describe('getWalletBalancesForTx', () => { tokenId: 'token1', tokenSymbol: 'T1', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - totalAmountSent: 0, - unlockedAmount: -5, + totalAmountSent: 0n, + unlockedAmount: -5n, unlockedAuthorities: { melt: false, mint: false, }, - total: -5, + total: -5n, }, ], }, @@ -1043,16 +1043,16 @@ describe('getWalletBalancesForTx', () => { // instantiate token balance const balanceToken1 = { - unlocked: 5, - locked: 0, + unlocked: 5n, + locked: 0n, lockExpires: null, transactions: 1, unlockedAuthorities: new Authorities(0b01), lockedAuthorities: 0, }; const balanceToken2 = { - unlocked: 10, - locked: 0, + unlocked: 10n, + locked: 0n, lockExpires: null, transactions: 1, unlockedAuthorities: new Authorities(0b01), @@ -1135,14 +1135,14 @@ describe('getWalletBalancesForTx', () => { tokenId: 'token2', tokenSymbol: 'T2', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - total: 10, - totalAmountSent: 10, - unlockedAmount: 10, + total: 10n, + totalAmountSent: 10n, + unlockedAmount: 10n, unlockedAuthorities: { melt: false, mint: false, @@ -1152,18 +1152,18 @@ describe('getWalletBalancesForTx', () => { tokenId: 'token1', tokenSymbol: 'T1', lockExpires: null, - lockedAmount: 0, + lockedAmount: 0n, lockedAuthorities: { melt: false, mint: false, }, - totalAmountSent: 5, - unlockedAmount: 5, + totalAmountSent: 5n, + unlockedAmount: 5n, unlockedAuthorities: { melt: false, mint: false, }, - total: 5, + total: 5n, }, ], }, diff --git a/packages/wallet-service/tests/txOutputs.test.ts b/packages/wallet-service/tests/txOutputs.test.ts index c912c1c4..20234b2d 100644 --- a/packages/wallet-service/tests/txOutputs.test.ts +++ b/packages/wallet-service/tests/txOutputs.test.ts @@ -372,7 +372,7 @@ test('get utxos with wallet id', async () => { index: utxo.index, tokenId: utxo.tokenId, address: utxo.address, - value: utxo.value, + value: Number(utxo.value), authorities: utxo.authorities, timelock: utxo.timelock, heightlock: utxo.heightlock, @@ -478,7 +478,7 @@ test('get tx outputs with wallet id', async () => { index: utxo.index, tokenId: utxo.tokenId, address: utxo.address, - value: utxo.value, + value: Number(utxo.value), authorities: utxo.authorities, timelock: utxo.timelock, heightlock: utxo.heightlock, @@ -586,7 +586,7 @@ test('get authority utxos', async () => { index: utxo.index, tokenId: utxo.tokenId, address: utxo.address, - value: utxo.value, + value: Number(utxo.value), authorities: utxo.authorities, timelock: utxo.timelock, heightlock: utxo.heightlock, @@ -712,7 +712,7 @@ test('get a specific utxo', async () => { index: utxo.index, tokenId: utxo.tokenId, address: utxo.address, - value: utxo.value, + value: Number(utxo.value), authorities: utxo.authorities, timelock: utxo.timelock, heightlock: utxo.heightlock, @@ -877,6 +877,7 @@ test('get spent tx_output', async () => { const formatTxOutput = (txOutput, path) => ({ ...txOutput, + value: Number(txOutput.value), txProposalIndex: null, txProposalId: null, addressPath: `m/44'/280'/0'/0/${path}`, From 68d9c3e0f8482071ea4bcdaa7b3df8c03f7423e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 17:55:28 -0300 Subject: [PATCH 20/31] chore: add bigint values instead of strings --- packages/wallet-service/src/db/index.ts | 2 +- packages/wallet-service/tests/db.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index f28629a3..5b136d28 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -536,7 +536,7 @@ export const initWalletBalance = async (mysql: ServerlessMysql, walletId: string const row1 = results1[i]; const row2 = results2[i]; assert.strictEqual(row1.token_id, row2.token_id); - assert.strictEqual(row1.unlocked_balance + row1.locked_balance, row2.balance); + assert.strictEqual(BigInt(row1.unlocked_balance as string) + BigInt(row1.locked_balance as string), BigInt(row2.balance as string)); balanceEntries.push([ walletId, row1.token_id, diff --git a/packages/wallet-service/tests/db.test.ts b/packages/wallet-service/tests/db.test.ts index 7cda0a53..24a657fe 100644 --- a/packages/wallet-service/tests/db.test.ts +++ b/packages/wallet-service/tests/db.test.ts @@ -1580,7 +1580,7 @@ test('createTxProposal, updateTxProposal, getTxProposal, countUnsentTxProposals, // Release txProposalUtxos should properly release the utxos. This method will throw an error if the // updated count is different from the sent tx proposals count. await releaseTxProposalUtxos(mysql, [txProposalId1, txProposalId2, txProposalId3]); - await expect(releaseTxProposalUtxos(mysql, ['invalid-tx-proposal'])).rejects.toThrow('AssertionError: Not all utxos were correctly updated'); + await expect(releaseTxProposalUtxos(mysql, ['invalid-tx-proposal'])).rejects.toThrow('Not all utxos were correctly updated'); }); test('updateVersionData', async () => { From 058aa516b290385444b31c4ebe79daad7c7e0611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 19:14:02 -0300 Subject: [PATCH 21/31] chore: parse websocket event --- packages/daemon/package.json | 3 ++- packages/daemon/src/actors/WebSocketActor.ts | 13 ++++++++++--- packages/daemon/src/utils/wallet.ts | 8 ++++++-- yarn.lock | 8 ++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 778441dd..f4b84a75 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -62,6 +62,7 @@ "websocket": "1.0.33", "winston": "3.13.0", "ws": "8.13.0", - "xstate": "4.38.2" + "xstate": "4.38.2", + "zod": "3.24.2" } } diff --git a/packages/daemon/src/actors/WebSocketActor.ts b/packages/daemon/src/actors/WebSocketActor.ts index 8f15b7fd..9e4efcbf 100644 --- a/packages/daemon/src/actors/WebSocketActor.ts +++ b/packages/daemon/src/actors/WebSocketActor.ts @@ -10,6 +10,8 @@ import { Event } from '../types'; import { get } from 'lodash'; import logger from '../logger'; import { getFullnodeWsUrl } from '../utils'; +import { bigIntUtils } from '@hathor/wallet-lib'; +import { FullNodeEventSchema } from '../types/schemas'; const PING_TIMEOUT = 30000; // 30s timeout const PING_INTERVAL = 5000; // Will ping every 5s @@ -47,7 +49,7 @@ export default (callback: any, receive: any) => { return; } - const payload = JSON.stringify(event.event); + const payload = bigIntUtils.JSONBigInt.stringify(event.event); logger.debug('Sending:') logger.debug(payload); @@ -68,16 +70,21 @@ export default (callback: any, receive: any) => { }; socket.onmessage = (socketEvent) => { - const event = JSON.parse(socketEvent.data.toString()); + let event = bigIntUtils.JSONBigInt.parse(socketEvent.data.toString()); const type = get(event, 'event.type'); logger.debug(`Received ${type}: ${get(event, 'event.id')} from socket.`, event); if (!type) { - logger.error(JSON.stringify(event)); + logger.error(bigIntUtils.JSONBigInt.stringify(event)); throw new Error('Received an event with no defined type'); } + const parseResult = FullNodeEventSchema.safeParse(event) + if (parseResult.success) { + event = parseResult.data; + } + callback({ type: 'FULLNODE_EVENT', event, diff --git a/packages/daemon/src/utils/wallet.ts b/packages/daemon/src/utils/wallet.ts index fb57605a..19c44f0a 100644 --- a/packages/daemon/src/utils/wallet.ts +++ b/packages/daemon/src/utils/wallet.ts @@ -122,7 +122,7 @@ export const getAddressBalanceMap = ( inputs: TxInput[], outputs: TxOutput[], ): StringMap => { - const addressBalanceMap = {}; + const addressBalanceMap: StringMap = {}; for (const input of inputs) { if (!isDecodedValid(input.decoded)) { @@ -132,11 +132,15 @@ export const getAddressBalanceMap = ( } const address = input.decoded?.address; + /* istanbul ignore if */ + if (!address) { + // This should never happen + throw new Error('Decoded input data has no address'); + } // get the TokenBalanceMap from this input const tokenBalanceMap = TokenBalanceMap.fromTxInput(input); // merge it with existing TokenBalanceMap for the address - // @ts-ignore addressBalanceMap[address] = TokenBalanceMap.merge(addressBalanceMap[address], tokenBalanceMap); } diff --git a/yarn.lock b/yarn.lock index 61a186de..46b1eddc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15227,6 +15227,7 @@ __metadata: winston: "npm:3.13.0" ws: "npm:8.13.0" xstate: "npm:4.38.2" + zod: "npm:3.24.2" peerDependencies: "@hathor/wallet-lib": 2.1.1 "@wallet-service/common": 1.5.0 @@ -16856,3 +16857,10 @@ __metadata: checksum: 10/846fd73e1af0def79c19d510ea9e4a795544a67d5b34b7e1c4d0425bf6bfd1c719446d94cdfa1721c1987d891321d61f779e8236fde517dc0e524aa851a6eff1 languageName: node linkType: hard + +"zod@npm:3.24.2": + version: 3.24.2 + resolution: "zod@npm:3.24.2" + checksum: 10/604c62a8cf8e330d78b106a557f4b44f5d14845d20b1360a423ccc09b58cb8525ccf7e4b40cf1bd4852d22393d2c67774b5817ec5a2fedab25f543b36ed15943 + languageName: node + linkType: hard From cf9d64c8ade68d549d2834f848c6c65eaf17607d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Tue, 8 Apr 2025 19:19:35 -0300 Subject: [PATCH 22/31] feat: add zod schema to daemon --- packages/daemon/src/types/schemas.ts | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 packages/daemon/src/types/schemas.ts diff --git a/packages/daemon/src/types/schemas.ts b/packages/daemon/src/types/schemas.ts new file mode 100644 index 00000000..ce2ae644 --- /dev/null +++ b/packages/daemon/src/types/schemas.ts @@ -0,0 +1,66 @@ +/** + * Copyright (c) Hathor Labs and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { z } from 'zod'; + +export const Sha256HexSchema = z.string().regex(/^[a-fA-F0-9]{64}$/); + +export const BigIntSchema = z + .union([z.bigint(), z.number(), z.string().regex(/^\d+$/)]) + .pipe(z.coerce.bigint()); + +export const EventTxOutputSchema = z.object({ + value: BigIntSchema, + token_data: z.number(), + script: z.string(), + locked: z.boolean().optional(), + decoded: z.object({ + type: z.string(), + address: z.string(), + timelock: z.number().nullish(), + }), +}); + +export const EventTxInputSchema = z.object({ + tx_id: Sha256HexSchema, + index: z.number().positive(), + spent_output: EventTxOutputSchema, +}) + +export const FullNodeEventSchema = z.object({ + id: z.number(), + timestamp: z.number().positive(), + type: z.enum([ + 'VERTEX_METADATA_CHANGED', + 'VERTEX_REMOVED', + 'NEW_VERTEX_ACCEPTED', + 'LOAD_STARTED', + 'LOAD_FINISHED', + 'REORG_FINISHED', + 'REORG_STARTED', + ]), + data: z.object({ + hash: Sha256HexSchema, + timestamp: z.number().positive(), + version: z.number().positive(), + weight: z.number(), + nonce: z.number(), + inputs: z.array(EventTxInputSchema), + outputs: z.array(EventTxOutputSchema), + parents: z.array(Sha256HexSchema).length(2), + tokens: z.array(z.string()), + token_name: z.string().nullish(), + token_symbol: z.string().nullish(), + signal_bits: z.number(), + metadata: z.object({ + hash: Sha256HexSchema, + voided_by: z.array(z.string()), + first_block: z.string().nullish(), + height: z.number(), + }), + }) +}); From 4c4db9fbc8d128d6b381628332b579c2573f0719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Wed, 9 Apr 2025 15:50:51 -0300 Subject: [PATCH 23/31] chore: convert to bigint values --- packages/common/src/types.ts | 4 ++-- packages/daemon/__tests__/integration/utils/index.ts | 1 - packages/daemon/src/db/index.ts | 2 +- packages/daemon/src/utils/wallet.ts | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 40cd7726..d62e79ff 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -384,7 +384,7 @@ export class TokenBalanceMap { throw new Error('Output has no decoded script'); } const token = output.token; - const value = output.value; + const value = BigInt(output.value); const obj = new TokenBalanceMap(); if (output.locked) { @@ -423,7 +423,7 @@ export class TokenBalanceMap { new Balance(0n, 0n, 0n, null, authorities.toNegative(), new Authorities(0)), ); } else { - obj.set(token, new Balance(0n, -input.value, 0n, null)); + obj.set(token, new Balance(0n, -BigInt(input.value), 0n, null)); } return obj; } diff --git a/packages/daemon/__tests__/integration/utils/index.ts b/packages/daemon/__tests__/integration/utils/index.ts index fd38b055..2bdc34e8 100644 --- a/packages/daemon/__tests__/integration/utils/index.ts +++ b/packages/daemon/__tests__/integration/utils/index.ts @@ -79,7 +79,6 @@ export async function transitionUntilEvent(mysql: Connection, machine: Interpret return await new Promise((resolve) => { machine.onTransition(async (state) => { if (state.matches('CONNECTED.idle')) { - // @ts-ignore const lastSyncedEvent = await getLastSyncedEvent(mysql); if (lastSyncedEvent?.last_event_id === eventId) { machine.stop(); diff --git a/packages/daemon/src/db/index.ts b/packages/daemon/src/db/index.ts index 44d4c5f5..2a4c3bb6 100644 --- a/packages/daemon/src/db/index.ts +++ b/packages/daemon/src/db/index.ts @@ -527,7 +527,7 @@ export const updateAddressTablesWithTx = async ( // which means it is the "total_received" for this address total_received: tokenBalance.totalAmountSent, // if it's < 0, there must be an entry already, so it will execute "ON DUPLICATE KEY UPDATE" instead of setting it to 0 - unlocked_balance: (tokenBalance.unlockedAmount < 0 ? 0 : tokenBalance.unlockedAmount), + unlocked_balance: (tokenBalance.unlockedAmount < 0n ? 0n : tokenBalance.unlockedAmount), // this is never less than 0, as locked balance only changes when a tx is unlocked locked_balance: tokenBalance.lockedAmount, unlocked_authorities: tokenBalance.unlockedAuthorities.toUnsignedInteger(), diff --git a/packages/daemon/src/utils/wallet.ts b/packages/daemon/src/utils/wallet.ts index 19c44f0a..50a04001 100644 --- a/packages/daemon/src/utils/wallet.ts +++ b/packages/daemon/src/utils/wallet.ts @@ -158,7 +158,6 @@ export const getAddressBalanceMap = ( const tokenBalanceMap = TokenBalanceMap.fromTxOutput(output); // merge it with existing TokenBalanceMap for the address - // @ts-ignore addressBalanceMap[address] = TokenBalanceMap.merge(addressBalanceMap[address], tokenBalanceMap); } From 792d4045a225819cb3c08de2a8689732759b11bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Wed, 9 Apr 2025 16:29:21 -0300 Subject: [PATCH 24/31] chore: fix zod schema --- packages/daemon/src/actors/WebSocketActor.ts | 6 ++++-- packages/daemon/src/types/schemas.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/daemon/src/actors/WebSocketActor.ts b/packages/daemon/src/actors/WebSocketActor.ts index 9e4efcbf..efa70ecf 100644 --- a/packages/daemon/src/actors/WebSocketActor.ts +++ b/packages/daemon/src/actors/WebSocketActor.ts @@ -11,7 +11,7 @@ import { get } from 'lodash'; import logger from '../logger'; import { getFullnodeWsUrl } from '../utils'; import { bigIntUtils } from '@hathor/wallet-lib'; -import { FullNodeEventSchema } from '../types/schemas'; +import { WsFullNodeEventSchema } from '../types/schemas'; const PING_TIMEOUT = 30000; // 30s timeout const PING_INTERVAL = 5000; // Will ping every 5s @@ -74,13 +74,15 @@ export default (callback: any, receive: any) => { const type = get(event, 'event.type'); logger.debug(`Received ${type}: ${get(event, 'event.id')} from socket.`, event); + console.debug(`Event: ${socketEvent.data.toString()}`); if (!type) { logger.error(bigIntUtils.JSONBigInt.stringify(event)); throw new Error('Received an event with no defined type'); } - const parseResult = FullNodeEventSchema.safeParse(event) + const parseResult = WsFullNodeEventSchema.safeParse(event) + console.debug(`Parse result: ${parseResult}`); if (parseResult.success) { event = parseResult.data; } diff --git a/packages/daemon/src/types/schemas.ts b/packages/daemon/src/types/schemas.ts index ce2ae644..5534ca39 100644 --- a/packages/daemon/src/types/schemas.ts +++ b/packages/daemon/src/types/schemas.ts @@ -29,7 +29,7 @@ export const EventTxInputSchema = z.object({ tx_id: Sha256HexSchema, index: z.number().positive(), spent_output: EventTxOutputSchema, -}) +}); export const FullNodeEventSchema = z.object({ id: z.number(), @@ -64,3 +64,12 @@ export const FullNodeEventSchema = z.object({ }), }) }); + +export const WsFullNodeEventSchema = z.object({ + type: z.literal('EVENT'), + peer_id: z.string(), + network: z.string(), + latest_event_id: z.number(), + stream_id: z.string(), + event: FullNodeEventSchema, +}); From f0f4f3761b0994ad1bec1db26f11b1cdc19036ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Fri, 11 Apr 2025 10:54:11 -0300 Subject: [PATCH 25/31] tests(integration): expect bigint amounts and use bigint JSON parsing --- packages/daemon/__tests__/db/index.test.ts | 28 +++++++++---------- .../custom_script.balances.ts | 28 +++++++++---------- .../scenario_configs/empty_script.balances.ts | 28 +++++++++---------- .../invalid_mempool_transaction.balances.ts | 26 ++++++++--------- .../scenario_configs/reorg.balances.ts | 8 +++--- ..._chain_blocks_and_transactions.balances.ts | 28 +++++++++---------- .../unvoided_transactions.balances.ts | 28 +++++++++---------- .../__tests__/integration/utils/index.ts | 4 +-- packages/daemon/src/actions/index.ts | 3 +- packages/daemon/src/actors/WebSocketActor.ts | 9 +++--- packages/daemon/src/db/index.ts | 6 ++-- packages/daemon/src/index.ts | 5 ++-- packages/daemon/src/services/index.ts | 4 +-- packages/daemon/src/types/address.ts | 6 ++-- packages/daemon/src/types/token.ts | 2 +- packages/daemon/src/utils/aws.ts | 5 ++-- packages/daemon/src/utils/wallet.ts | 4 +-- 17 files changed, 112 insertions(+), 110 deletions(-) diff --git a/packages/daemon/__tests__/db/index.test.ts b/packages/daemon/__tests__/db/index.test.ts index 233b0c64..be789055 100644 --- a/packages/daemon/__tests__/db/index.test.ts +++ b/packages/daemon/__tests__/db/index.test.ts @@ -965,30 +965,30 @@ describe('address and wallet related tests', () => { expect(addressBalances[0].address).toStrictEqual('addr1'); expect(addressBalances[0].tokenId).toStrictEqual('token1'); - expect(addressBalances[0].unlockedBalance).toStrictEqual(2); - expect(addressBalances[0].lockedBalance).toStrictEqual(0); + expect(addressBalances[0].unlockedBalance).toStrictEqual(2n); + expect(addressBalances[0].lockedBalance).toStrictEqual(0n); expect(addressBalances[1].address).toStrictEqual('addr1'); expect(addressBalances[1].tokenId).toStrictEqual('token2'); - expect(addressBalances[1].unlockedBalance).toStrictEqual(1); - expect(addressBalances[1].lockedBalance).toStrictEqual(4); + expect(addressBalances[1].unlockedBalance).toStrictEqual(1n); + expect(addressBalances[1].lockedBalance).toStrictEqual(4n); expect(addressBalances[2].address).toStrictEqual('addr2'); expect(addressBalances[2].tokenId).toStrictEqual('token1'); - expect(addressBalances[2].unlockedBalance).toStrictEqual(5); - expect(addressBalances[2].lockedBalance).toStrictEqual(2); + expect(addressBalances[2].unlockedBalance).toStrictEqual(5n); + expect(addressBalances[2].lockedBalance).toStrictEqual(2n); expect(addressBalances[3].address).toStrictEqual('addr2'); expect(addressBalances[3].tokenId).toStrictEqual('token2'); - expect(addressBalances[3].unlockedBalance).toStrictEqual(0); - expect(addressBalances[3].lockedBalance).toStrictEqual(2); + expect(addressBalances[3].unlockedBalance).toStrictEqual(0n); + expect(addressBalances[3].lockedBalance).toStrictEqual(2n); expect(addressBalances[4].address).toStrictEqual('addr3'); expect(addressBalances[4].tokenId).toStrictEqual('token1'); - expect(addressBalances[4].unlockedBalance).toStrictEqual(0); - expect(addressBalances[4].lockedBalance).toStrictEqual(1); + expect(addressBalances[4].unlockedBalance).toStrictEqual(0n); + expect(addressBalances[4].lockedBalance).toStrictEqual(1n); expect(addressBalances[5].address).toStrictEqual('addr3'); expect(addressBalances[5].tokenId).toStrictEqual('token2'); - expect(addressBalances[5].unlockedBalance).toStrictEqual(10); - expect(addressBalances[5].lockedBalance).toStrictEqual(1); + expect(addressBalances[5].unlockedBalance).toStrictEqual(10n); + expect(addressBalances[5].lockedBalance).toStrictEqual(1n); }); test('fetchAddressTxHistorySum', async () => { @@ -1018,8 +1018,8 @@ describe('address and wallet related tests', () => { const history = await fetchAddressTxHistorySum(mysql, [addr1, addr2]); - expect(history[0].balance).toStrictEqual(60); - expect(history[1].balance).toStrictEqual(50); + expect(history[0].balance).toStrictEqual(60n); + expect(history[1].balance).toStrictEqual(50n); }); }); diff --git a/packages/daemon/__tests__/integration/scenario_configs/custom_script.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/custom_script.balances.ts index 6cada8af..8010f858 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/custom_script.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/custom_script.balances.ts @@ -1,16 +1,16 @@ export default { - 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000, - 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400, - 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400, - 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400, - 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400, - 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400, - 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400, - 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400, - 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400, - 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400, - 'HJPSMHCFv2dRb78wZPMsAzwLQHSkBpfuLn': 6400, - 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 1000, - 'H9hHteu9QdAS5p6X743Mpfue6G19rV9GeY': 5400, - 'HSd6PqXesUmHHv6MoN24aUiMuw7Pdcxrwk': 6400 + 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000n, + 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400n, + 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400n, + 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400n, + 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400n, + 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400n, + 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400n, + 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400n, + 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400n, + 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400n, + 'HJPSMHCFv2dRb78wZPMsAzwLQHSkBpfuLn': 6400n, + 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 1000n, + 'H9hHteu9QdAS5p6X743Mpfue6G19rV9GeY': 5400n, + 'HSd6PqXesUmHHv6MoN24aUiMuw7Pdcxrwk': 6400n, } diff --git a/packages/daemon/__tests__/integration/scenario_configs/empty_script.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/empty_script.balances.ts index e59f3324..d686baa7 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/empty_script.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/empty_script.balances.ts @@ -1,16 +1,16 @@ export default { - 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000, - 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400, - 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400, - 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400, - 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400, - 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400, - 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400, - 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400, - 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400, - 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400, - 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400, - 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 1000, - 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 5400, - 'HRH8Wbmr1A3BrLswSBhvVE4hhsv4jUdyVA': 6400 + 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000n, + 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400n, + 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400n, + 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400n, + 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400n, + 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400n, + 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400n, + 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400n, + 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400n, + 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400n, + 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400n, + 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 1000n, + 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 5400n, + 'HRH8Wbmr1A3BrLswSBhvVE4hhsv4jUdyVA': 6400n, }; diff --git a/packages/daemon/__tests__/integration/scenario_configs/invalid_mempool_transaction.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/invalid_mempool_transaction.balances.ts index 70c28ab3..2f81b0fb 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/invalid_mempool_transaction.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/invalid_mempool_transaction.balances.ts @@ -1,15 +1,15 @@ export default { - 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 0, - 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000, - 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400, - 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400, - 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400, - 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400, - 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400, - 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400, - 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400, - 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400, - 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 6400, - 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 0, - 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 0 + 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 0n, + 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000n, + 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400n, + 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400n, + 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400n, + 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400n, + 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400n, + 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400n, + 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400n, + 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400n, + 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 6400n, + 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 0n, + 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 0n, } diff --git a/packages/daemon/__tests__/integration/scenario_configs/reorg.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/reorg.balances.ts index 3dffad2d..91bdc3b7 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/reorg.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/reorg.balances.ts @@ -1,6 +1,6 @@ export default { - 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000, - 'HFyF1jYJP9FXfiC3LRqf3q4768TBL1rxbn': 6400, - 'HMbS5P3NTLQ5oR5TfLNvAkeQ7L8MPn9VM3': 6400, - 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 0, + 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000n, + 'HFyF1jYJP9FXfiC3LRqf3q4768TBL1rxbn': 6400n, + 'HMbS5P3NTLQ5oR5TfLNvAkeQ7L8MPn9VM3': 6400n, + 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 0n, } diff --git a/packages/daemon/__tests__/integration/scenario_configs/single_chain_blocks_and_transactions.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/single_chain_blocks_and_transactions.balances.ts index b0422a90..23b4306c 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/single_chain_blocks_and_transactions.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/single_chain_blocks_and_transactions.balances.ts @@ -1,16 +1,16 @@ export default { - 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400, - 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400, - 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400, - 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400, - 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400, - 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400, - 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400, - 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400, - 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400, - 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400, - 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 3000, - 'HRH8Wbmr1A3BrLswSBhvVE4hhsv4jUdyVA': 3400, - 'HSd6PqXesUmHHv6MoN24aUiMuw7Pdcxrwk': 6400, - 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 0, + 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400n, + 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400n, + 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400n, + 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400n, + 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400n, + 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400n, + 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400n, + 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400n, + 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400n, + 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400n, + 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 3000n, + 'HRH8Wbmr1A3BrLswSBhvVE4hhsv4jUdyVA': 3400n, + 'HSd6PqXesUmHHv6MoN24aUiMuw7Pdcxrwk': 6400n, + 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 0n, } diff --git a/packages/daemon/__tests__/integration/scenario_configs/unvoided_transactions.balances.ts b/packages/daemon/__tests__/integration/scenario_configs/unvoided_transactions.balances.ts index 7fdce785..bad3a376 100644 --- a/packages/daemon/__tests__/integration/scenario_configs/unvoided_transactions.balances.ts +++ b/packages/daemon/__tests__/integration/scenario_configs/unvoided_transactions.balances.ts @@ -1,16 +1,16 @@ export default { - 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400, - 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400, - 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400, - 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400, - 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400, - 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400, - 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400, - 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400, - 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400, - 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400, - 'H9hHteu9QdAS5p6X743Mpfue6G19rV9GeY': 6400, - 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 5400, - 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 1000, - 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000 + 'HFtz2f59Lms4p3Jfgtsr73s97MbJHsRENh': 6400n, + 'HJQbEERnD5Ak3f2dsi8zAmsZrCWTT8FZns': 6400n, + 'HRSYchTEsFFpZAkgSTMsohNGQ6eLPyhXvJ': 6400n, + 'HQfVqxyxQV4BHwnsMnRXpZGmwPYiNSVmMu': 6400n, + 'HPnkpR2vnBuCoZCEnRZNHMBtf8ygeSidbW': 6400n, + 'HPNvtPZaDF44i6CL91u4BvZPu6z2xPNt26': 6400n, + 'HQijr325t63VJFdc4vYkaTyd87oeBLpSed': 6400n, + 'H8fCNrYGkj4B6VzKgtRiHBgoSxM31d65JR': 6400n, + 'HAqrADnn7GyyT68fSX8zmtsRNFyabPzoRQ': 6400n, + 'HRTH6uGo7zn3LWrosBYn7eXkwAeHAHTRh8': 6400n, + 'H9hHteu9QdAS5p6X743Mpfue6G19rV9GeY': 6400n, + 'HNqTfEASfdx7H4vMUGzfD2HyD3GeKuxjTJ': 5400n, + 'HRQe4CXj8AZXzSmuNztU8iQR74QTQMbnTs': 1000n, + 'HRXVDmLVdq8pgok1BCUKpiFWdAVAy4a5AJ': 100000000000n, }; diff --git a/packages/daemon/__tests__/integration/utils/index.ts b/packages/daemon/__tests__/integration/utils/index.ts index 2bdc34e8..232669b8 100644 --- a/packages/daemon/__tests__/integration/utils/index.ts +++ b/packages/daemon/__tests__/integration/utils/index.ts @@ -47,8 +47,8 @@ export const fetchAddressBalances = async ( return results.map((result): AddressBalance => ({ address: result.address as string, tokenId: result.token_id as string, - unlockedBalance: result.unlocked_balance as number, - lockedBalance: result.locked_balance as number, + unlockedBalance: BigInt(result.unlocked_balance), + lockedBalance: BigInt(result.locked_balance), lockedAuthorities: result.locked_authorities as number, unlockedAuthorities: result.unlocked_authorities as number, timelockExpires: result.timelock_expires as number, diff --git a/packages/daemon/src/actions/index.ts b/packages/daemon/src/actions/index.ts index 59eaea31..845b10b6 100644 --- a/packages/daemon/src/actions/index.ts +++ b/packages/daemon/src/actions/index.ts @@ -11,6 +11,7 @@ import { get } from 'lodash'; import logger from '../logger'; import { hashTxData } from '../utils'; import { createStartStreamMessage, createSendAckMessage } from '../actors'; +import { bigIntUtils } from '@hathor/wallet-lib'; /* * This action is used to store the initial event id on the context @@ -194,4 +195,4 @@ export const stopHealthcheckPing = sendTo( /* * Logs the event as an error log */ -export const logEventError = (_context: Context, event: Event) => logger.error(JSON.stringify(event)); +export const logEventError = (_context: Context, event: Event) => logger.error(bigIntUtils.JSONBigInt.stringify(event)); diff --git a/packages/daemon/src/actors/WebSocketActor.ts b/packages/daemon/src/actors/WebSocketActor.ts index efa70ecf..5dfc5250 100644 --- a/packages/daemon/src/actors/WebSocketActor.ts +++ b/packages/daemon/src/actors/WebSocketActor.ts @@ -11,7 +11,7 @@ import { get } from 'lodash'; import logger from '../logger'; import { getFullnodeWsUrl } from '../utils'; import { bigIntUtils } from '@hathor/wallet-lib'; -import { WsFullNodeEventSchema } from '../types/schemas'; +import { FullNodeEventSchema } from '../types/schemas'; const PING_TIMEOUT = 30000; // 30s timeout const PING_INTERVAL = 5000; // Will ping every 5s @@ -74,17 +74,16 @@ export default (callback: any, receive: any) => { const type = get(event, 'event.type'); logger.debug(`Received ${type}: ${get(event, 'event.id')} from socket.`, event); - console.debug(`Event: ${socketEvent.data.toString()}`); if (!type) { logger.error(bigIntUtils.JSONBigInt.stringify(event)); throw new Error('Received an event with no defined type'); } - const parseResult = WsFullNodeEventSchema.safeParse(event) - console.debug(`Parse result: ${parseResult}`); + const parseResult = FullNodeEventSchema.safeParse(event?.event); if (parseResult.success) { - event = parseResult.data; + // Found a valid transaction, we need to use the parsed data to convert values if needed. + event.event = parseResult.data; } callback({ diff --git a/packages/daemon/src/db/index.ts b/packages/daemon/src/db/index.ts index 2a4c3bb6..e571cade 100644 --- a/packages/daemon/src/db/index.ts +++ b/packages/daemon/src/db/index.ts @@ -1363,8 +1363,8 @@ export const fetchAddressBalance = async ( return results.map((result): AddressBalance => ({ address: result.address as string, tokenId: result.token_id as string, - unlockedBalance: result.unlocked_balance as number, - lockedBalance: result.locked_balance as number, + unlockedBalance: BigInt(result.unlocked_balance), + lockedBalance: BigInt(result.locked_balance), lockedAuthorities: result.locked_authorities as number, unlockedAuthorities: result.unlocked_authorities as number, timelockExpires: result.timelock_expires as number, @@ -1402,7 +1402,7 @@ export const fetchAddressTxHistorySum = async ( return results.map((result): AddressTotalBalance => ({ address: result.address as string, tokenId: result.token_id as string, - balance: parseInt(result.balance), + balance: BigInt(result.balance), transactions: parseInt(result.transactions), })); }; diff --git a/packages/daemon/src/index.ts b/packages/daemon/src/index.ts index 49e3d308..571c6dac 100644 --- a/packages/daemon/src/index.ts +++ b/packages/daemon/src/index.ts @@ -9,6 +9,7 @@ import { interpret } from 'xstate'; import { SyncMachine } from './machines'; import logger from './logger'; import { checkEnvVariables } from './config'; +import { bigIntUtils } from '@hathor/wallet-lib'; const main = async () => { checkEnvVariables(); @@ -16,11 +17,11 @@ const main = async () => { const machine = interpret(SyncMachine); machine.onTransition((state) => { - logger.info(`Transitioned to ${JSON.stringify(state.value)}`); + logger.info(`Transitioned to ${bigIntUtils.JSONBigInt.stringify(state.value)}`); }); machine.onEvent((event) => { - logger.info(`Processing event: ${JSON.stringify(event.type)}`); + logger.info(`Processing event: ${bigIntUtils.JSONBigInt.stringify(event.type)}`); }); machine.start(); diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index aa8ff9a7..75f3e971 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import hathorLib from '@hathor/wallet-lib'; +import hathorLib, { bigIntUtils } from '@hathor/wallet-lib'; import { Connection as MysqlConnection } from 'mysql2/promise'; import axios from 'axios'; import { get } from 'lodash'; @@ -619,7 +619,7 @@ export const updateLastSyncedEvent = async (context: Context) => { && lastDbSyncedEvent.last_event_id > lastEventId) { logger.error('Tried to store an event lower than the one on the database', { lastEventId, - lastDbSyncedEvent: JSON.stringify(lastDbSyncedEvent), + lastDbSyncedEvent: bigIntUtils.JSONBigInt.stringify(lastDbSyncedEvent), }); mysql.destroy(); throw new Error('Event lower than stored one.'); diff --git a/packages/daemon/src/types/address.ts b/packages/daemon/src/types/address.ts index 3b2eef88..370e573e 100644 --- a/packages/daemon/src/types/address.ts +++ b/packages/daemon/src/types/address.ts @@ -17,8 +17,8 @@ export interface GenerateAddresses { export interface AddressBalance { address: string; tokenId: string; - unlockedBalance: number; - lockedBalance: number; + unlockedBalance: bigint; + lockedBalance: bigint; unlockedAuthorities: number; lockedAuthorities: number; timelockExpires: number; @@ -28,7 +28,7 @@ export interface AddressBalance { export interface AddressTotalBalance { address: string; tokenId: string; - balance: number; + balance: bigint; transactions: number; } diff --git a/packages/daemon/src/types/token.ts b/packages/daemon/src/types/token.ts index c53da8a9..86a0b658 100644 --- a/packages/daemon/src/types/token.ts +++ b/packages/daemon/src/types/token.ts @@ -22,7 +22,7 @@ export class TokenInfo { this.symbol = symbol; this.transactions = transactions || 0; - // XXX: get config from settings? + // XXX: currently we only support Hathor/HTR as the default token const hathorConfig = constants.DEFAULT_NATIVE_TOKEN_CONFIG; if (this.id === constants.NATIVE_TOKEN_UID) { diff --git a/packages/daemon/src/utils/aws.ts b/packages/daemon/src/utils/aws.ts index 7a35927b..9a93ecd9 100644 --- a/packages/daemon/src/utils/aws.ts +++ b/packages/daemon/src/utils/aws.ts @@ -5,6 +5,7 @@ import { StringMap } from '../types'; import getConfig from '../config'; import logger from '../logger'; import { addAlert, Transaction } from '@wallet-service/common'; +import { bigIntUtils } from '@hathor/wallet-lib'; export function buildFunctionName(functionName: string): string { const { STAGE } = getConfig(); @@ -36,7 +37,7 @@ export const invokeOnTxPushNotificationRequestedLambda = async (walletBalanceVal const command = new InvokeCommand({ FunctionName: ON_TX_PUSH_NOTIFICATION_REQUESTED_FUNCTION_NAME, InvocationType: 'Event', - Payload: JSON.stringify(walletBalanceValueMap), + Payload: bigIntUtils.JSONBigInt.stringify(walletBalanceValueMap), }); const response: InvokeCommandOutput = await client.send(command); @@ -69,7 +70,7 @@ export const sendRealtimeTx = async (wallets: string[], tx: Transaction): Promis throw new Error('Queue URL is invalid'); } - await sendMessageSQS(JSON.stringify({ + await sendMessageSQS(bigIntUtils.JSONBigInt.stringify({ wallets, tx, }), NEW_TX_SQS); diff --git a/packages/daemon/src/utils/wallet.ts b/packages/daemon/src/utils/wallet.ts index 50a04001..4f68801d 100644 --- a/packages/daemon/src/utils/wallet.ts +++ b/packages/daemon/src/utils/wallet.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import hathorLib, { constants, Output, walletUtils, addressUtils } from '@hathor/wallet-lib'; +import hathorLib, { constants, Output, walletUtils, addressUtils, bigIntUtils } from '@hathor/wallet-lib'; import { Connection as MysqlConnection } from 'mysql2/promise'; import { strict as assert } from 'assert'; import { @@ -376,7 +376,7 @@ export const validateAddressBalances = async (mysql: MysqlConnection, addresses: const addressBalances: AddressBalance[] = await fetchAddressBalance(mysql, addresses); const addressTxHistorySums: AddressTotalBalance[] = await fetchAddressTxHistorySum(mysql, addresses); - logger.debug(`Validating address balances for ${JSON.stringify(addresses)}`); + logger.debug(`Validating address balances for ${bigIntUtils.JSONBigInt.stringify(addresses)}`); /* We need to filter out zero transactions address balances as we won't have * any records in the address_tx_history table and the assertion ahead will From 8466a7ee942c03b9e9257d608762576a0a8335a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Fri, 11 Apr 2025 11:00:25 -0300 Subject: [PATCH 26/31] chore: remove zod as dependency --- packages/daemon/package.json | 3 +- packages/daemon/src/actors/WebSocketActor.ts | 7 -- packages/daemon/src/types/schemas.ts | 75 -------------------- yarn.lock | 8 --- 4 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 packages/daemon/src/types/schemas.ts diff --git a/packages/daemon/package.json b/packages/daemon/package.json index f4b84a75..778441dd 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -62,7 +62,6 @@ "websocket": "1.0.33", "winston": "3.13.0", "ws": "8.13.0", - "xstate": "4.38.2", - "zod": "3.24.2" + "xstate": "4.38.2" } } diff --git a/packages/daemon/src/actors/WebSocketActor.ts b/packages/daemon/src/actors/WebSocketActor.ts index 5dfc5250..1ce9cbf3 100644 --- a/packages/daemon/src/actors/WebSocketActor.ts +++ b/packages/daemon/src/actors/WebSocketActor.ts @@ -11,7 +11,6 @@ import { get } from 'lodash'; import logger from '../logger'; import { getFullnodeWsUrl } from '../utils'; import { bigIntUtils } from '@hathor/wallet-lib'; -import { FullNodeEventSchema } from '../types/schemas'; const PING_TIMEOUT = 30000; // 30s timeout const PING_INTERVAL = 5000; // Will ping every 5s @@ -80,12 +79,6 @@ export default (callback: any, receive: any) => { throw new Error('Received an event with no defined type'); } - const parseResult = FullNodeEventSchema.safeParse(event?.event); - if (parseResult.success) { - // Found a valid transaction, we need to use the parsed data to convert values if needed. - event.event = parseResult.data; - } - callback({ type: 'FULLNODE_EVENT', event, diff --git a/packages/daemon/src/types/schemas.ts b/packages/daemon/src/types/schemas.ts deleted file mode 100644 index 5534ca39..00000000 --- a/packages/daemon/src/types/schemas.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) Hathor Labs and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -import { z } from 'zod'; - -export const Sha256HexSchema = z.string().regex(/^[a-fA-F0-9]{64}$/); - -export const BigIntSchema = z - .union([z.bigint(), z.number(), z.string().regex(/^\d+$/)]) - .pipe(z.coerce.bigint()); - -export const EventTxOutputSchema = z.object({ - value: BigIntSchema, - token_data: z.number(), - script: z.string(), - locked: z.boolean().optional(), - decoded: z.object({ - type: z.string(), - address: z.string(), - timelock: z.number().nullish(), - }), -}); - -export const EventTxInputSchema = z.object({ - tx_id: Sha256HexSchema, - index: z.number().positive(), - spent_output: EventTxOutputSchema, -}); - -export const FullNodeEventSchema = z.object({ - id: z.number(), - timestamp: z.number().positive(), - type: z.enum([ - 'VERTEX_METADATA_CHANGED', - 'VERTEX_REMOVED', - 'NEW_VERTEX_ACCEPTED', - 'LOAD_STARTED', - 'LOAD_FINISHED', - 'REORG_FINISHED', - 'REORG_STARTED', - ]), - data: z.object({ - hash: Sha256HexSchema, - timestamp: z.number().positive(), - version: z.number().positive(), - weight: z.number(), - nonce: z.number(), - inputs: z.array(EventTxInputSchema), - outputs: z.array(EventTxOutputSchema), - parents: z.array(Sha256HexSchema).length(2), - tokens: z.array(z.string()), - token_name: z.string().nullish(), - token_symbol: z.string().nullish(), - signal_bits: z.number(), - metadata: z.object({ - hash: Sha256HexSchema, - voided_by: z.array(z.string()), - first_block: z.string().nullish(), - height: z.number(), - }), - }) -}); - -export const WsFullNodeEventSchema = z.object({ - type: z.literal('EVENT'), - peer_id: z.string(), - network: z.string(), - latest_event_id: z.number(), - stream_id: z.string(), - event: FullNodeEventSchema, -}); diff --git a/yarn.lock b/yarn.lock index 46b1eddc..61a186de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15227,7 +15227,6 @@ __metadata: winston: "npm:3.13.0" ws: "npm:8.13.0" xstate: "npm:4.38.2" - zod: "npm:3.24.2" peerDependencies: "@hathor/wallet-lib": 2.1.1 "@wallet-service/common": 1.5.0 @@ -16857,10 +16856,3 @@ __metadata: checksum: 10/846fd73e1af0def79c19d510ea9e4a795544a67d5b34b7e1c4d0425bf6bfd1c719446d94cdfa1721c1987d891321d61f779e8236fde517dc0e524aa851a6eff1 languageName: node linkType: hard - -"zod@npm:3.24.2": - version: 3.24.2 - resolution: "zod@npm:3.24.2" - checksum: 10/604c62a8cf8e330d78b106a557f4b44f5d14845d20b1360a423ccc09b58cb8525ccf7e4b40cf1bd4852d22393d2c67774b5817ec5a2fedab25f543b36ed15943 - languageName: node - linkType: hard From df5b222cb0dad279b9cb91f7c301bedcf295cbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Fri, 11 Apr 2025 11:21:17 -0300 Subject: [PATCH 27/31] chore: do not use JSONBigInt when not needed --- packages/daemon/src/services/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index 75f3e971..67f42a79 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import hathorLib, { bigIntUtils } from '@hathor/wallet-lib'; +import hathorLib from '@hathor/wallet-lib'; import { Connection as MysqlConnection } from 'mysql2/promise'; import axios from 'axios'; import { get } from 'lodash'; @@ -619,7 +619,7 @@ export const updateLastSyncedEvent = async (context: Context) => { && lastDbSyncedEvent.last_event_id > lastEventId) { logger.error('Tried to store an event lower than the one on the database', { lastEventId, - lastDbSyncedEvent: bigIntUtils.JSONBigInt.stringify(lastDbSyncedEvent), + lastDbSyncedEvent: lastDbSyncedEvent, }); mysql.destroy(); throw new Error('Event lower than stored one.'); From d1675ce0f851f5365c4af00a073a224e2ffe9fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carneiro?= Date: Fri, 11 Apr 2025 11:24:30 -0300 Subject: [PATCH 28/31] chore: do not use JSONBigInt when not needed --- packages/daemon/src/services/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/daemon/src/services/index.ts b/packages/daemon/src/services/index.ts index 67f42a79..aa8ff9a7 100644 --- a/packages/daemon/src/services/index.ts +++ b/packages/daemon/src/services/index.ts @@ -619,7 +619,7 @@ export const updateLastSyncedEvent = async (context: Context) => { && lastDbSyncedEvent.last_event_id > lastEventId) { logger.error('Tried to store an event lower than the one on the database', { lastEventId, - lastDbSyncedEvent: lastDbSyncedEvent, + lastDbSyncedEvent: JSON.stringify(lastDbSyncedEvent), }); mysql.destroy(); throw new Error('Event lower than stored one.'); From 08925be75d82ea512bc3e3aea4d14fd4ef12de0b Mon Sep 17 00:00:00 2001 From: Andre Carneiro Date: Thu, 3 Jul 2025 12:51:40 -0300 Subject: [PATCH 29/31] chore: update to v2.5.1 --- package.json | 2 +- packages/common/package.json | 2 +- packages/daemon/package.json | 2 +- packages/wallet-service/package.json | 2 +- yarn.lock | 120 +++------------------------ 5 files changed, 14 insertions(+), 114 deletions(-) diff --git a/package.json b/package.json index 781639ac..a51acd83 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@aws-sdk/client-apigatewaymanagementapi": "3.540.0", "@aws-sdk/client-lambda": "3.540.0", "@aws-sdk/client-sqs": "3.540.0", - "@hathor/wallet-lib": "2.1.1", + "@hathor/wallet-lib": "2.5.1", "@wallet-service/common": "1.5.0", "bip32": "^4.0.0", "bitcoinjs-lib": "^6.1.5", diff --git a/packages/common/package.json b/packages/common/package.json index a20412fe..b3136a27 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -8,7 +8,7 @@ "test": "jest --runInBand --collectCoverage --detectOpenHandles --forceExit" }, "peerDependencies": { - "@hathor/wallet-lib": "2.1.1" + "@hathor/wallet-lib": "2.5.1" }, "dependencies": { "@aws-sdk/client-lambda": "3.540.0", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 778441dd..50146647 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -46,7 +46,7 @@ "typescript": "4.9.5" }, "peerDependencies": { - "@hathor/wallet-lib": "2.1.1", + "@hathor/wallet-lib": "2.5.1", "@wallet-service/common": "1.5.0" }, "dependencies": { diff --git a/packages/wallet-service/package.json b/packages/wallet-service/package.json index bd757b78..206393a0 100644 --- a/packages/wallet-service/package.json +++ b/packages/wallet-service/package.json @@ -40,7 +40,7 @@ "winston": "3.13.0" }, "peerDependencies": { - "@hathor/wallet-lib": "2.1.1", + "@hathor/wallet-lib": "2.5.1", "@wallet-service/common": "1.5.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 61a186de..8c0b9fa0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2160,24 +2160,21 @@ __metadata: languageName: node linkType: hard -"@hathor/wallet-lib@npm:2.1.1": - version: 2.1.1 - resolution: "@hathor/wallet-lib@npm:2.1.1" +"@hathor/wallet-lib@npm:2.5.1": + version: 2.5.1 + resolution: "@hathor/wallet-lib@npm:2.5.1" dependencies: - abstract-level: "npm:1.0.4" axios: "npm:1.7.7" bitcore-lib: "npm:8.25.10" bitcore-mnemonic: "npm:8.25.10" buffer: "npm:6.0.3" crypto-js: "npm:4.2.0" isomorphic-ws: "npm:5.0.0" - level: "npm:8.0.1" - level-transcoder: "npm:1.0.1" lodash: "npm:4.17.21" queue-microtask: "npm:1.2.3" ws: "npm:8.17.1" zod: "npm:3.23.8" - checksum: 10/692e740b80be632b6a9eb9b302dffa3b04cb295ceebdc9f10d1bf3a7cd654f2837818a2ebbcb8110de6827706939d454a212f74ca0460557b4d382d2cd611e7a + checksum: 10/6afb2123a29de80d09cfcbe14c69709a41cd36e1f4fdcbe5dcb74690057dbff482d434a904e734a0154ded4fb8e168eb443acba4d9b5815795d92f677f274b09 languageName: node linkType: hard @@ -5014,7 +5011,7 @@ __metadata: typescript: "npm:5.4.3" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 2.1.1 + "@hathor/wallet-lib": 2.5.1 languageName: unknown linkType: soft @@ -5199,21 +5196,6 @@ __metadata: languageName: node linkType: hard -"abstract-level@npm:1.0.4, abstract-level@npm:^1.0.2, abstract-level@npm:^1.0.4": - version: 1.0.4 - resolution: "abstract-level@npm:1.0.4" - dependencies: - buffer: "npm:^6.0.3" - catering: "npm:^2.1.0" - is-buffer: "npm:^2.0.5" - level-supports: "npm:^4.0.0" - level-transcoder: "npm:^1.0.1" - module-error: "npm:^1.0.1" - queue-microtask: "npm:^1.2.3" - checksum: 10/8edf4cf55b7b66b653296f53a643bcf1501074be099d8c44351595cd33f769b7b2aed216d5fffe1c99ebea4acf14f5ae093e98baa60ea1d236ea8a3387350ebb - languageName: node - linkType: hard - "acorn-import-assertions@npm:^1.9.0": version: 1.9.0 resolution: "acorn-import-assertions@npm:1.9.0" @@ -6199,18 +6181,6 @@ __metadata: languageName: node linkType: hard -"browser-level@npm:^1.0.1": - version: 1.0.1 - resolution: "browser-level@npm:1.0.1" - dependencies: - abstract-level: "npm:^1.0.2" - catering: "npm:^2.1.1" - module-error: "npm:^1.0.2" - run-parallel-limit: "npm:^1.1.0" - checksum: 10/e712569111782da76853fecf648b43ff878ff2301c2830a9e7399685b646824a85f304dea5f023e02ee41a63a972f9aad734bd411069095adc9c79784fc649a5 - languageName: node - linkType: hard - "browserify-aes@npm:^1.0.6": version: 1.2.0 resolution: "browserify-aes@npm:1.2.0" @@ -6373,7 +6343,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:6.0.3, buffer@npm:^6.0.3": +"buffer@npm:6.0.3": version: 6.0.3 resolution: "buffer@npm:6.0.3" dependencies: @@ -6550,13 +6520,6 @@ __metadata: languageName: node linkType: hard -"catering@npm:^2.1.0, catering@npm:^2.1.1": - version: 2.1.1 - resolution: "catering@npm:2.1.1" - checksum: 10/4669c9fa5f3a73273535fb458a964d8aba12dc5102d8487049cf03623bef3cdff4b5d9f92ff04c00f1001057a7cc7df6e700752ac622c2a7baf7bcff34166683 - languageName: node - linkType: hard - "chalk@npm:^2.4.1, chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" @@ -6689,20 +6652,6 @@ __metadata: languageName: node linkType: hard -"classic-level@npm:^1.2.0": - version: 1.4.1 - resolution: "classic-level@npm:1.4.1" - dependencies: - abstract-level: "npm:^1.0.2" - catering: "npm:^2.1.0" - module-error: "npm:^1.0.1" - napi-macros: "npm:^2.2.2" - node-gyp: "npm:latest" - node-gyp-build: "npm:^4.3.0" - checksum: 10/11f9362301477cb5cf3b147e5846754e0e4296231e265145101403f4a5cb797a685b6a9b6b4c880a42b05772f846a222a5a7a563262ca15b5ca03e25e9a805db - languageName: node - linkType: hard - "clean-stack@npm:^2.0.0": version: 2.2.0 resolution: "clean-stack@npm:2.2.0" @@ -9727,7 +9676,7 @@ __metadata: "@aws-sdk/client-apigatewaymanagementapi": "npm:3.540.0" "@aws-sdk/client-lambda": "npm:3.540.0" "@aws-sdk/client-sqs": "npm:3.540.0" - "@hathor/wallet-lib": "npm:2.1.1" + "@hathor/wallet-lib": "npm:2.5.1" "@types/jest": "npm:29.5.13" "@typescript-eslint/eslint-plugin": "npm:^7.4.0" "@typescript-eslint/parser": "npm:^7.4.0" @@ -10130,13 +10079,6 @@ __metadata: languageName: node linkType: hard -"is-buffer@npm:^2.0.5": - version: 2.0.5 - resolution: "is-buffer@npm:2.0.5" - checksum: 10/3261a8b858edcc6c9566ba1694bf829e126faa88911d1c0a747ea658c5d81b14b6955e3a702d59dabadd58fdd440c01f321aa71d6547105fd21d03f94d0597e7 - languageName: node - linkType: hard - "is-builtin-module@npm:^3.2.1": version: 3.2.1 resolution: "is-builtin-module@npm:3.2.1" @@ -11493,34 +11435,6 @@ __metadata: languageName: node linkType: hard -"level-supports@npm:^4.0.0": - version: 4.0.1 - resolution: "level-supports@npm:4.0.1" - checksum: 10/e2f177af813a25af29d15406a14240e2e10e5efb1c35b03643c885ac5931af760b9337826506b6395f98cf6b1e68ba294bfc345a248a1ae3f9c69e08e81824b2 - languageName: node - linkType: hard - -"level-transcoder@npm:1.0.1, level-transcoder@npm:^1.0.1": - version: 1.0.1 - resolution: "level-transcoder@npm:1.0.1" - dependencies: - buffer: "npm:^6.0.3" - module-error: "npm:^1.0.1" - checksum: 10/2fb41a1d8037fc279f851ead8cdc3852b738f1f935ac2895183cd606aae3e57008e085c7c2bd2b2d43cfd057333108cfaed604092e173ac2abdf5ab1b8333f9e - languageName: node - linkType: hard - -"level@npm:8.0.1": - version: 8.0.1 - resolution: "level@npm:8.0.1" - dependencies: - abstract-level: "npm:^1.0.4" - browser-level: "npm:^1.0.1" - classic-level: "npm:^1.2.0" - checksum: 10/a9c6d1fc50e30b2cc80b3c975b34de0eb12daab7fb4f8a546a28303705a45685340a904544fcd32e9a380fae7c62474ebd9cdb0108021ddbc7b88dd9c913f126 - languageName: node - linkType: hard - "leven@npm:^3.1.0": version: 3.1.0 resolution: "leven@npm:3.1.0" @@ -12287,13 +12201,6 @@ __metadata: languageName: node linkType: hard -"module-error@npm:^1.0.1, module-error@npm:^1.0.2": - version: 1.0.2 - resolution: "module-error@npm:1.0.2" - checksum: 10/5d653e35bd55b3e95f8aee2cdac108082ea892e71b8f651be92cde43e4ee86abee4fa8bd7fc3fe5e68b63926d42f63c54cd17b87a560c31f18739295575a3962 - languageName: node - linkType: hard - "moment-timezone@npm:^0.5.43": version: 0.5.43 resolution: "moment-timezone@npm:0.5.43" @@ -12423,13 +12330,6 @@ __metadata: languageName: node linkType: hard -"napi-macros@npm:^2.2.2": - version: 2.2.2 - resolution: "napi-macros@npm:2.2.2" - checksum: 10/2cdb9c40ad4b424b14fbe5e13c5329559e2b511665acf41cdcda172fd2270202dc747a2d288b687c72bc70f654c797bc24a93adb67631128d62461588d7cc070 - languageName: node - linkType: hard - "native-promise-only@npm:^0.8.1": version: 0.8.1 resolution: "native-promise-only@npm:0.8.1" @@ -13539,7 +13439,7 @@ __metadata: languageName: node linkType: hard -"queue-microtask@npm:1.2.3, queue-microtask@npm:^1.2.2, queue-microtask@npm:^1.2.3": +"queue-microtask@npm:1.2.3, queue-microtask@npm:^1.2.2": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" checksum: 10/72900df0616e473e824202113c3df6abae59150dfb73ed13273503127235320e9c8ca4aaaaccfd58cf417c6ca92a6e68ee9a5c3182886ae949a768639b388a7b @@ -15228,7 +15128,7 @@ __metadata: ws: "npm:8.13.0" xstate: "npm:4.38.2" peerDependencies: - "@hathor/wallet-lib": 2.1.1 + "@hathor/wallet-lib": 2.5.1 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft @@ -16324,7 +16224,7 @@ __metadata: webpack-node-externals: "npm:3.0.0" winston: "npm:3.13.0" peerDependencies: - "@hathor/wallet-lib": 2.1.1 + "@hathor/wallet-lib": 2.5.1 "@wallet-service/common": 1.5.0 languageName: unknown linkType: soft From 648fe1a4ba37d9489cfb2a880fb52e097327797e Mon Sep 17 00:00:00 2001 From: Andre Carneiro Date: Thu, 3 Jul 2025 16:53:51 -0300 Subject: [PATCH 30/31] chore: change fullnode image --- .../__tests__/integration/balances.test.ts | 32 ++++++++----------- .../integration/scripts/docker-compose.yml | 12 +++---- .../__tests__/integration/utils/index.ts | 3 +- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/packages/daemon/__tests__/integration/balances.test.ts b/packages/daemon/__tests__/integration/balances.test.ts index be99e9d4..5cac3ffa 100644 --- a/packages/daemon/__tests__/integration/balances.test.ts +++ b/packages/daemon/__tests__/integration/balances.test.ts @@ -47,7 +47,7 @@ jest.mock('../../src/config', () => { import getConfig from '../../src/config'; -// @ts-ignore +// @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -91,7 +91,7 @@ describe('unvoided transaction scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -112,10 +112,9 @@ describe('unvoided transaction scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, UNVOIDED_SCENARIO_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, unvoidedScenarioBalances)); }); }); @@ -126,7 +125,7 @@ describe('reorg scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -147,10 +146,9 @@ describe('reorg scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, REORG_SCENARIO_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, reorgScenarioBalances)); }); }); @@ -161,7 +159,7 @@ describe('single chain blocks and transactions scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -182,10 +180,9 @@ describe('single chain blocks and transactions scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, SINGLE_CHAIN_BLOCKS_AND_TRANSACTIONS_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, singleChainBlocksAndTransactionsBalances)); }); }); @@ -196,7 +193,7 @@ describe('invalid mempool transactions scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -217,10 +214,9 @@ describe('invalid mempool transactions scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, INVALID_MEMPOOL_TRANSACTION_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, invalidMempoolBalances)); }); }); @@ -231,7 +227,7 @@ describe('custom script scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -252,10 +248,9 @@ describe('custom script scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, CUSTOM_SCRIPT_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, customScriptBalances)); }); }); @@ -266,7 +261,7 @@ describe('empty script scenario', () => { }); it('should do a full sync and the balances should match', async () => { - // @ts-ignore + // @ts-expect-error getConfig.mockReturnValue({ NETWORK: 'testnet', SERVICE_NAME: 'daemon-test', @@ -287,11 +282,10 @@ describe('empty script scenario', () => { const machine = interpret(SyncMachine); - // @ts-ignore + // @ts-expect-error await transitionUntilEvent(mysql, machine, EMPTY_SCRIPT_LAST_EVENT); const addressBalances = await fetchAddressBalances(mysql); - // @ts-ignore expect(validateBalances(addressBalances, emptyScriptBalances)); }); }); diff --git a/packages/daemon/__tests__/integration/scripts/docker-compose.yml b/packages/daemon/__tests__/integration/scripts/docker-compose.yml index afa5b5d4..36900677 100644 --- a/packages/daemon/__tests__/integration/scripts/docker-compose.yml +++ b/packages/daemon/__tests__/integration/scripts/docker-compose.yml @@ -9,7 +9,7 @@ services: - "3380:3306" unvoided_transaction: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "UNVOIDED_TRANSACTION", @@ -18,7 +18,7 @@ services: ports: - "8081:8080" reorg: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "REORG", @@ -27,7 +27,7 @@ services: ports: - "8082:8080" single_chain_blocks_and_transactions: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "SINGLE_CHAIN_BLOCKS_AND_TRANSACTIONS", @@ -36,7 +36,7 @@ services: ports: - "8083:8080" invalid_mempool_transaction: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "INVALID_MEMPOOL_TRANSACTION", @@ -46,7 +46,7 @@ services: - "8085:8080" custom_scripts: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "CUSTOM_SCRIPT", @@ -56,7 +56,7 @@ services: - "8086:8080" empty_script: - image: hathornetwork/hathor-core:stable + image: hathornetwork/hathor-core:v0.63.1 command: [ "events_simulator", "--scenario", "EMPTY_SCRIPT", diff --git a/packages/daemon/__tests__/integration/utils/index.ts b/packages/daemon/__tests__/integration/utils/index.ts index 232669b8..360ee2f1 100644 --- a/packages/daemon/__tests__/integration/utils/index.ts +++ b/packages/daemon/__tests__/integration/utils/index.ts @@ -58,14 +58,13 @@ export const fetchAddressBalances = async ( export const validateBalances = async ( balancesA: AddressBalance[], - balancesB: { string: number }, + balancesB: Record, ): Promise => { const length = Math.max(balancesA.length, Object.keys(balancesB).length); for (let i = 0; i < length; i++) { const balanceA = balancesA[i]; const address = balanceA.address; - // @ts-ignore const balanceB = balancesB[address]; const totalBalanceA = balanceA.lockedBalance + balanceA.unlockedBalance; From 58fe2283cb54284d364b406a3dfd293eb6b603e6 Mon Sep 17 00:00:00 2001 From: Andre Carneiro Date: Wed, 16 Jul 2025 10:12:28 -0300 Subject: [PATCH 31/31] chore: review changes --- packages/daemon/src/actors/WebSocketActor.ts | 2 +- packages/wallet-service/src/db/index.ts | 2 +- .../wallet-service/tests/utils/pushnotification.utils.test.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/daemon/src/actors/WebSocketActor.ts b/packages/daemon/src/actors/WebSocketActor.ts index 1ce9cbf3..9e36c1bd 100644 --- a/packages/daemon/src/actors/WebSocketActor.ts +++ b/packages/daemon/src/actors/WebSocketActor.ts @@ -69,7 +69,7 @@ export default (callback: any, receive: any) => { }; socket.onmessage = (socketEvent) => { - let event = bigIntUtils.JSONBigInt.parse(socketEvent.data.toString()); + const event = bigIntUtils.JSONBigInt.parse(socketEvent.data.toString()); const type = get(event, 'event.type'); logger.debug(`Received ${type}: ${get(event, 'event.id')} from socket.`, event); diff --git a/packages/wallet-service/src/db/index.ts b/packages/wallet-service/src/db/index.ts index cd01d74e..e3ff5a29 100644 --- a/packages/wallet-service/src/db/index.ts +++ b/packages/wallet-service/src/db/index.ts @@ -2389,7 +2389,7 @@ export const filterTxOutputs = async ( authority: 0, ignoreLocked: false, skipSpent: true, - biggerThan: -1, + biggerThan: 0, smallerThan: constants.MAX_OUTPUT_VALUE + 1n, ...filters, }; diff --git a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts index dfb26ec8..16570e6b 100644 --- a/packages/wallet-service/tests/utils/pushnotification.utils.test.ts +++ b/packages/wallet-service/tests/utils/pushnotification.utils.test.ts @@ -11,7 +11,6 @@ import { Severity } from '@wallet-service/common/src/types'; import { sendMock, lambdaInvokeCommandMock } from '@tests/utils/aws-sdk.mock'; import { LambdaClient } from '@aws-sdk/client-lambda'; import { buildWalletBalanceValueMap } from '@tests/utils'; - import { bigIntUtils } from '@hathor/wallet-lib'; const isFirebaseInitializedMock = jest.spyOn(pushnotificationUtils, 'isFirebaseInitialized');