From d65bc12acbb518215f0823d7c1dfae968aca3a7a Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Thu, 16 Jan 2025 15:00:46 +0100 Subject: [PATCH 1/5] feat: replace ethjs* package with ethersproject --- lib/index.js | 18 ++- lib/token.js | 6 +- package.json | 7 +- yarn.lock | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 363 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index c46735a..64c9f7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ const { PollingBlockTracker } = require('@metamask/eth-block-tracker') -const Eth = require('@metamask/ethjs-query') -const EthContract = require('@metamask/ethjs-contract') +const { Web3Provider } = require('@ethersproject/providers') +const { Contract } = require('@ethersproject/contracts') const Token = require('./token') const abi = require('human-standard-token-abi') const SafeEventEmitter = require('@metamask/safe-event-emitter').default @@ -19,9 +19,7 @@ class TokenTracker extends SafeEventEmitter { pollingInterval, }) - const eth = new Eth(opts.provider) - const contract = new EthContract(eth) - this.TokenContract = contract(abi) + this.provider = opts.provider const tokens = opts.tokens || [] this.balanceDecimals = opts.balanceDecimals @@ -52,6 +50,14 @@ class TokenTracker extends SafeEventEmitter { return this.tokens.map(token => token.serialize()) } + getContractAtAddress(tokenAddress) { + return new Contract( + tokenAddress, + abi, + new Web3Provider(this.provider), + ) + } + async updateBalances() { try { await Promise.all(this.tokens.map((token) => { @@ -68,7 +74,7 @@ class TokenTracker extends SafeEventEmitter { createTokenFrom (opts, balanceDecimals) { const owner = this.userAddress const { address, symbol, balance, decimals } = opts - const contract = this.TokenContract.at(address) + const contract = this.getContractAtAddress(address) return new Token({ address, symbol, diff --git a/lib/token.js b/lib/token.js index e75eae7..08aff8a 100644 --- a/lib/token.js +++ b/lib/token.js @@ -1,4 +1,5 @@ const BN = require('bn.js') +const { BigNumber } = require("@ethersproject/bignumber") const util = require('./util') /** @@ -137,7 +138,10 @@ class Token { } if (result) { - const val = result[0] + let val = result + if (BigNumber.isBigNumber(result)) { + val = new BN(result.toString()) + } this[key] = val return val } diff --git a/package.json b/package.json index 9ec8857..89c870c 100644 --- a/package.json +++ b/package.json @@ -38,9 +38,10 @@ "/lib" ], "dependencies": { + "@ethersproject/bignumber": "^5.7.0", + "@ethersproject/contracts": "^5.7.0", + "@ethersproject/providers": "^5.7.2", "@metamask/eth-block-tracker": "^11.0.3", - "@metamask/ethjs-contract": "^0.4.1", - "@metamask/ethjs-query": "^0.7.1", "@metamask/safe-event-emitter": "^3.0.0", "bn.js": "^5.2.1", "deep-equal": "^2.2.0", @@ -55,6 +56,8 @@ "@lavamoat/allow-scripts": "^2.3.1", "@lavamoat/preinstall-always-fail": "^2.0.0", "@metamask/auto-changelog": "^3.4.3", + "@metamask/ethjs-contract": "^0.4.1", + "@metamask/ethjs-query": "^0.7.1", "ganache": "7.3.1", "solc": "^0.4.26", "tape": "^5.6.1" diff --git a/yarn.lock b/yarn.lock index 37457cb..a53b573 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1349,6 +1349,296 @@ __metadata: languageName: node linkType: hard +"@ethersproject/abi@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abi@npm:5.7.0" + dependencies: + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/hash": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: bc6962bb6cb854e4d2a4d65b2c49c716477675b131b1363312234bdbb7e19badb7d9ce66f4ca2a70ae2ea84f7123dbc4e300a1bfe5d58864a7eafabc1466627e + languageName: node + linkType: hard + +"@ethersproject/abstract-provider@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abstract-provider@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/networks": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + "@ethersproject/web": ^5.7.0 + checksum: 74cf4696245cf03bb7cc5b6cbf7b4b89dd9a79a1c4688126d214153a938126d4972d42c93182198653ce1de35f2a2cad68be40337d4774b3698a39b28f0228a8 + languageName: node + linkType: hard + +"@ethersproject/abstract-signer@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abstract-signer@npm:5.7.0" + dependencies: + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + checksum: a823dac9cfb761e009851050ebebd5b229d1b1cc4a75b125c2da130ff37e8218208f7f9d1386f77407705b889b23d4a230ad67185f8872f083143e0073cbfbe3 + languageName: node + linkType: hard + +"@ethersproject/address@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/address@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + checksum: 64ea5ebea9cc0e845c413e6cb1e54e157dd9fc0dffb98e239d3a3efc8177f2ff798cd4e3206cf3660ee8faeb7bef1a47dc0ebef0d7b132c32e61e550c7d4c843 + languageName: node + linkType: hard + +"@ethersproject/base64@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/base64@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + checksum: 7dd5d734d623582f08f665434f53685041a3d3b334a0e96c0c8afa8bbcaab934d50e5b6b980e826a8fde8d353e0b18f11e61faf17468177274b8e7c69cd9742b + languageName: node + linkType: hard + +"@ethersproject/basex@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/basex@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + checksum: 326087b7e1f3787b5fe6cd1cf2b4b5abfafbc355a45e88e22e5e9d6c845b613ffc5301d629b28d5c4d5e2bfe9ec424e6782c804956dff79be05f0098cb5817de + languageName: node + linkType: hard + +"@ethersproject/bignumber@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/bignumber@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + bn.js: ^5.2.1 + checksum: 8c9a134b76f3feb4ec26a5a27379efb4e156b8fb2de0678a67788a91c7f4e30abe9d948638458e4b20f2e42380da0adacc7c9389d05fce070692edc6ae9b4904 + languageName: node + linkType: hard + +"@ethersproject/bytes@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/bytes@npm:5.7.0" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 66ad365ceaab5da1b23b72225c71dce472cf37737af5118181fa8ab7447d696bea15ca22e3a0e8836fdd8cfac161afe321a7c67d0dde96f9f645ddd759676621 + languageName: node + linkType: hard + +"@ethersproject/constants@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/constants@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + checksum: 6d4b1355747cce837b3e76ec3bde70e4732736f23b04f196f706ebfa5d4d9c2be50904a390d4d40ce77803b98d03d16a9b6898418e04ba63491933ce08c4ba8a + languageName: node + linkType: hard + +"@ethersproject/contracts@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/contracts@npm:5.7.0" + dependencies: + "@ethersproject/abi": ^5.7.0 + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + checksum: 6ccf1121cba01b31e02f8c507cb971ab6bfed85706484a9ec09878ef1594a62215f43c4fdef8f4a4875b99c4a800bc95e3be69b1803f8ce479e07634b5a740c0 + languageName: node + linkType: hard + +"@ethersproject/hash@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/hash@npm:5.7.0" + dependencies: + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/base64": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: 6e9fa8d14eb08171cd32f17f98cc108ec2aeca74a427655f0d689c550fee0b22a83b3b400fad7fb3f41cf14d4111f87f170aa7905bcbcd1173a55f21b06262ef + languageName: node + linkType: hard + +"@ethersproject/keccak256@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/keccak256@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + js-sha3: 0.8.0 + checksum: ff70950d82203aab29ccda2553422cbac2e7a0c15c986bd20a69b13606ed8bb6e4fdd7b67b8d3b27d4f841e8222cbaccd33ed34be29f866fec7308f96ed244c6 + languageName: node + linkType: hard + +"@ethersproject/logger@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/logger@npm:5.7.0" + checksum: 075ab2f605f1fd0813f2e39c3308f77b44a67732b36e712d9bc085f22a84aac4da4f71b39bee50fe78da3e1c812673fadc41180c9970fe5e486e91ea17befe0d + languageName: node + linkType: hard + +"@ethersproject/networks@npm:^5.7.0": + version: 5.7.1 + resolution: "@ethersproject/networks@npm:5.7.1" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 0339f312304c17d9a0adce550edb825d4d2c8c9468c1634c44172c67a9ed256f594da62c4cda5c3837a0f28b7fabc03aca9b492f68ff1fdad337ee861b27bd5d + languageName: node + linkType: hard + +"@ethersproject/properties@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/properties@npm:5.7.0" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 6ab0ccf0c3aadc9221e0cdc5306ce6cd0df7f89f77d77bccdd1277182c9ead0202cd7521329ba3acde130820bf8af299e17cf567d0d497c736ee918207bbf59f + languageName: node + linkType: hard + +"@ethersproject/providers@npm:^5.7.2": + version: 5.7.2 + resolution: "@ethersproject/providers@npm:5.7.2" + dependencies: + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/base64": ^5.7.0 + "@ethersproject/basex": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/hash": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/networks": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/random": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + "@ethersproject/sha2": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + "@ethersproject/web": ^5.7.0 + bech32: 1.1.4 + ws: 7.4.6 + checksum: 1754c731a5ca6782ae9677f4a9cd8b6246c4ef21a966c9a01b133750f3c578431ec43ec254e699969c4a0f87e84463ded50f96b415600aabd37d2056aee58c19 + languageName: node + linkType: hard + +"@ethersproject/random@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/random@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: 017829c91cff6c76470852855108115b0b52c611b6be817ed1948d56ba42d6677803ec2012aa5ae298a7660024156a64c11fcf544e235e239ab3f89f0fff7345 + languageName: node + linkType: hard + +"@ethersproject/rlp@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/rlp@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: bce165b0f7e68e4d091c9d3cf47b247cac33252df77a095ca4281d32d5eeaaa3695d9bc06b2b057c5015353a68df89f13a4a54a72e888e4beeabbe56b15dda6e + languageName: node + linkType: hard + +"@ethersproject/sha2@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/sha2@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + hash.js: 1.1.7 + checksum: 09321057c022effbff4cc2d9b9558228690b5dd916329d75c4b1ffe32ba3d24b480a367a7cc92d0f0c0b1c896814d03351ae4630e2f1f7160be2bcfbde435dbc + languageName: node + linkType: hard + +"@ethersproject/signing-key@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/signing-key@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + bn.js: ^5.2.1 + elliptic: 6.5.4 + hash.js: 1.1.7 + checksum: 8f8de09b0aac709683bbb49339bc0a4cd2f95598f3546436c65d6f3c3a847ffa98e06d35e9ed2b17d8030bd2f02db9b7bd2e11c5cf8a71aad4537487ab4cf03a + languageName: node + linkType: hard + +"@ethersproject/strings@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/strings@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: 5ff78693ae3fdf3cf23e1f6dc047a61e44c8197d2408c42719fef8cb7b7b3613a4eec88ac0ed1f9f5558c74fe0de7ae3195a29ca91a239c74b9f444d8e8b50df + languageName: node + linkType: hard + +"@ethersproject/transactions@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/transactions@npm:5.7.0" + dependencies: + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + "@ethersproject/signing-key": ^5.7.0 + checksum: a31b71996d2b283f68486241bff0d3ea3f1ba0e8f1322a8fffc239ccc4f4a7eb2ea9994b8fd2f093283fd75f87bae68171e01b6265261f821369aca319884a79 + languageName: node + linkType: hard + +"@ethersproject/web@npm:^5.7.0": + version: 5.7.1 + resolution: "@ethersproject/web@npm:5.7.1" + dependencies: + "@ethersproject/base64": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: 7028c47103f82fd2e2c197ce0eecfacaa9180ffeec7de7845b1f4f9b19d84081b7a48227aaddde05a4aaa526af574a9a0ce01cc0fc75e3e371f84b38b5b16b2b + languageName: node + linkType: hard + "@gar/promisify@npm:^1.1.3": version: 1.1.3 resolution: "@gar/promisify@npm:1.1.3" @@ -1502,6 +1792,9 @@ __metadata: "@babel/plugin-transform-runtime": ^7.5.5 "@babel/preset-env": ^7.5.5 "@babel/runtime": ^7.21.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/contracts": ^5.7.0 + "@ethersproject/providers": ^5.7.2 "@lavamoat/allow-scripts": ^2.3.1 "@lavamoat/preinstall-always-fail": ^2.0.0 "@metamask/auto-changelog": ^3.4.3 @@ -2081,6 +2374,13 @@ __metadata: languageName: node linkType: hard +"bech32@npm:1.1.4": + version: 1.1.4 + resolution: "bech32@npm:1.1.4" + checksum: 0e98db619191548390d6f09ff68b0253ba7ae6a55db93dfdbb070ba234c1fd3308c0606fbcc95fad50437227b10011e2698b89f0181f6e7f845c499bd14d0f4b + languageName: node + linkType: hard + "bin-links@npm:4.0.1": version: 4.0.1 resolution: "bin-links@npm:4.0.1" @@ -2556,6 +2856,21 @@ __metadata: languageName: node linkType: hard +"elliptic@npm:6.5.4": + version: 6.5.4 + resolution: "elliptic@npm:6.5.4" + dependencies: + bn.js: ^4.11.9 + brorand: ^1.1.0 + hash.js: ^1.0.0 + hmac-drbg: ^1.0.1 + inherits: ^2.0.4 + minimalistic-assert: ^1.0.1 + minimalistic-crypto-utils: ^1.0.1 + checksum: d56d21fd04e97869f7ffcc92e18903b9f67f2d4637a23c860492fbbff5a3155fd9ca0184ce0c865dd6eb2487d234ce9551335c021c376cd2d3b7cb749c7d10f4 + languageName: node + linkType: hard + "elliptic@npm:^6.5.2": version: 6.6.0 resolution: "elliptic@npm:6.6.0" @@ -3131,7 +3446,7 @@ __metadata: languageName: node linkType: hard -"hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": +"hash.js@npm:1.1.7, hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": version: 1.1.7 resolution: "hash.js@npm:1.1.7" dependencies: @@ -3627,10 +3942,17 @@ __metadata: languageName: node linkType: hard +"js-sha3@npm:0.8.0": + version: 0.8.0 + resolution: "js-sha3@npm:0.8.0" + checksum: 75df77c1fc266973f06cce8309ce010e9e9f07ec35ab12022ed29b7f0d9c8757f5a73e1b35aa24840dced0dea7059085aa143d817aea9e188e2a80d569d9adce + languageName: node + linkType: hard + "js-sha3@npm:^0.9.2": - version: 0.9.2 - resolution: "js-sha3@npm:0.9.2" - checksum: fed1bd06802bbc476ce8419b96a98a7a92c146ddb7e6b2762e41fd1dba043178975cee80d12d125c89472aeca65826240092d7b4d42d944d7804c1870b97c73a + version: 0.9.3 + resolution: "js-sha3@npm:0.9.3" + checksum: cfab12cdb3aa9c0c8e8466761d89cb9770653880910b920682fa676dd102868a827709c857cb089bdc0d6120542137f92a7c1699ab428c0f4057c823aef24601 languageName: node linkType: hard @@ -5458,6 +5780,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:7.4.6": + version: 7.4.6 + resolution: "ws@npm:7.4.6" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ^5.0.2 + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 3a990b32ed08c72070d5e8913e14dfcd831919205be52a3ff0b4cdd998c8d554f167c9df3841605cde8b11d607768cacab3e823c58c96a5c08c987e093eb767a + languageName: node + linkType: hard + "y18n@npm:^3.2.1": version: 3.2.2 resolution: "y18n@npm:3.2.2" From 087f8766ec72aaa5aaaa538bbfa42441b01bfb26 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Fri, 17 Jan 2025 18:20:24 +0100 Subject: [PATCH 2/5] fix: use @ethersproject for tests --- package.json | 6 +- test/helper.js | 30 ++-- test/integration/human-standard-token.js | 53 +++---- test/integration/simple-token.js | 12 +- test/integration/token-precision.js | 48 +++--- yarn.lock | 182 +++++++++++++++++++---- 6 files changed, 213 insertions(+), 118 deletions(-) diff --git a/package.json b/package.json index 89c870c..aa10b8a 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@metamask/auto-changelog": "^3.4.3", "@metamask/ethjs-contract": "^0.4.1", "@metamask/ethjs-query": "^0.7.1", - "ganache": "7.3.1", + "ganache": "7.9.2", "solc": "^0.4.26", "tape": "^5.6.1" }, @@ -74,7 +74,9 @@ "ganache>keccak": true, "ganache>leveldown": true, "ganache>secp256k1": true, - "ganache>utf-8-validate": true + "ganache>utf-8-validate": true, + "ganache>@trufflesuite/uws-js-unofficial>bufferutil": false, + "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false } } } diff --git a/test/helper.js b/test/helper.js index de59efd..dd11cdf 100644 --- a/test/helper.js +++ b/test/helper.js @@ -2,8 +2,8 @@ const assert = require('assert').strict const fs = require('fs') const path = require('path') const ganache = require('ganache') -const Eth = require('@metamask/ethjs-query') -const EthContract = require('@metamask/ethjs-contract') +const { Web3Provider } = require('@ethersproject/providers') +const { ContractFactory } = require('@ethersproject/contracts') const solc = require('solc') const source = fs.readFileSync(path.resolve(__dirname, 'contracts/Token.sol')).toString(); @@ -13,35 +13,29 @@ const SimpleTokenDeployer = compiled.contracts[':SimpleToken'] const defaultQuantity = '100000000000000000000' // 100 x 10 ^ 18 async function setupSimpleTokenEnvironment ({ qty = defaultQuantity } = {}) { const provider = ganache.provider() - const eth = new Eth(provider) + const ethersProvider = new Web3Provider(provider) - const addresses = await eth.accounts() + const addresses = await ethersProvider.listAccounts() assert(addresses.length > 0, 'test network should be initialized with accounts') const owner = addresses[0] - const contract = new EthContract(eth) const abi = JSON.parse(SimpleTokenDeployer.interface) - const StandardToken = contract(abi, SimpleTokenDeployer.bytecode, { - from: owner, - gas: '3000000', - gasPrice: '875000000', - }) + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) - const txHash = await StandardToken.new(qty) + const token = await factory.deploy(qty) + const txHash = token.deployTransaction.hash assert.ok(txHash, 'should have published the token and returned a transaction hash') - await new Promise((resolve) => setTimeout(resolve, 300)) - const receipt = await eth.getTransactionReceipt(txHash) + await token.deployed() + const receipt = await ethersProvider.getTransactionReceipt(txHash) const tokenAddress = receipt.contractAddress assert.ok(tokenAddress, 'should have a token address') - const token = StandardToken.at(tokenAddress) - const result = await token.balanceOf(owner) - const balance = result[0] - assert.equal(balance.toString(10), qty, 'owner should have all') + const balance = await token.balanceOf(owner) + assert.equal(balance.toString(), qty, 'owner should have all') - return { addresses, eth, provider, token, tokenAddress } + return { addresses, provider, token, tokenAddress } } module.exports = { setupSimpleTokenEnvironment } diff --git a/test/integration/human-standard-token.js b/test/integration/human-standard-token.js index 8397972..86f0c87 100644 --- a/test/integration/human-standard-token.js +++ b/test/integration/human-standard-token.js @@ -2,17 +2,13 @@ const fs = require('fs') const path = require('path') const test = require('tape') const ganache = require('ganache') -const provider = ganache.provider() - +const { Web3Provider } = require('@ethersproject/providers') +const { ContractFactory } = require('@ethersproject/contracts') const solc = require('solc') const TokenTracker = require('../../lib') -const BN = ('bn.js') -const Eth = require('@metamask/ethjs-query') -const EthContract = require('@metamask/ethjs-contract') -const eth = new Eth(provider) -const contract = new EthContract(eth) +const provider = ganache.provider() const source = fs.readFileSync(path.resolve(__dirname, '..', 'contracts/Token.sol')).toString(); const compiled = solc.compile(source, 1) const HumanStandardDeployer = compiled.contracts[':HumanStandardToken'] @@ -23,8 +19,10 @@ const EXPECTED_SYMBOL = 'EXP' let addresses = [] let token, tokenAddress, tracked +const ethersProvider = new Web3Provider(provider) + test('testrpc has addresses', function (t) { - eth.accounts() + ethersProvider.listAccounts() .then((accounts) => { addresses = accounts t.ok(accounts, 'loaded accounts') @@ -34,34 +32,23 @@ test('testrpc has addresses', function (t) { test('HumanStandardToken publishing token & checking balance', function (t) { const abi = JSON.parse(HumanStandardDeployer.interface) - const HumanStandardToken = contract(abi, HumanStandardDeployer.bytecode, { - from: addresses[0], - gas: '3000000', - gasPrice: '875000000', - }) - const humanStandardToken = HumanStandardToken.new('1000', - 'DanBucks', - '2', // decimals - SET_SYMBOL) - .then((txHash) => { - t.ok(txHash, 'publishes a txHash') + const factory = new ContractFactory(abi, HumanStandardDeployer.bytecode, ethersProvider.getSigner(addresses[0])) - return new Promise((res, rej) => { - setTimeout(() => res(txHash), 200) - }) + factory.deploy('1000', 'DanBucks', '2', SET_SYMBOL, { + gasLimit: '3000000', + gasPrice: '875000000', }) - .then((txHash) => { - return eth.getTransactionReceipt(txHash) + .then((contract) => { + t.ok(contract.deployTransaction.hash, 'publishes a txHash') + return contract.deployed() }) - .then((receipt) => { - const addr = receipt.contractAddress - tokenAddress = addr - token = HumanStandardToken.at(addr) + .then((deployedContract) => { + token = deployedContract + tokenAddress = token.address return token.balanceOf(addresses[0]) }) - .then((res) => { - const balance = res[0] - t.equal(balance.toString(10), '1000', 'owner should have all') + .then((balance) => { + t.equal(balance.toString(), '1000', 'owner should have all') t.end() }) .catch((reason) => { @@ -90,8 +77,8 @@ test('HumanStandardToken balances are tracked', function (t) { t.equal(tracked.balance.toString(10), '1000', 'initial balance loaded') return token.transfer(addresses[1], '110') }) - .then((txHash) => { - return eth.getTransactionReceipt(txHash) + .then((tx) => { + return ethersProvider.getTransactionReceipt(tx.hash) }) .then((receipt) => { var a = new Promise((res, rej) => { setTimeout(res, 200) }) diff --git a/test/integration/simple-token.js b/test/integration/simple-token.js index 93d591c..53aa591 100644 --- a/test/integration/simple-token.js +++ b/test/integration/simple-token.js @@ -11,17 +11,16 @@ const less = '10000000000000000000' // 100 x 10 ^ 17 test('StandardToken balances are tracked', function (t) { let addresses - let eth let token let tokenAddress let tokenTracker + let provider setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - eth = environment.eth token = environment.token tokenAddress = environment.tokenAddress - const { provider } = environment + provider = environment.provider tokenTracker = new TokenTracker({ userAddress: addresses[0], provider, @@ -43,8 +42,11 @@ test('StandardToken balances are tracked', function (t) { t.equal(tracked.balance.toString(10), qty, 'initial balance loaded') return token.transfer(addresses[1], less) }) - .then((txHash) => { - return eth.getTransactionReceipt(txHash) + .then((tx) => { + return provider.request({ + method: 'eth_getTransactionReceipt', + params: [tx.hash], + }) }) .then((receipt) => { var a = new Promise((res, rej) => { setTimeout(res, 200) }) diff --git a/test/integration/token-precision.js b/test/integration/token-precision.js index c231519..6de229c 100644 --- a/test/integration/token-precision.js +++ b/test/integration/token-precision.js @@ -2,16 +2,15 @@ const fs = require('fs') const path = require('path') const test = require('tape') const ganache = require('ganache') -const provider = ganache.provider() const solc = require('solc') const TokenTracker = require('../../lib') const BN = require('bn.js') const util = require('../../lib/util') +const { ContractFactory } = require('@ethersproject/contracts') +const { Web3Provider } = require('@ethersproject/providers') -const Eth = require('@metamask/ethjs-query') -const EthContract = require('@metamask/ethjs-contract') -const eth = new Eth(provider) -const contract = new EthContract(eth) +const provider = ganache.provider() +const ethersProvider = new Web3Provider(provider) let count = 0 const source = fs.readFileSync(path.resolve(__dirname, '..', 'contracts/ZeppelinToken.sol')).toString(); @@ -20,10 +19,10 @@ const compiled = solc.compile(source, 1) const SimpleTokenDeployer = compiled.contracts[':TutorialToken'] let addresses = [] -let token, tokenAddress, tracked +let tokenAddress, tracked test('testrpc has addresses', function (t) { - eth.accounts() + ethersProvider.listAccounts() .then((accounts) => { addresses = accounts t.ok(accounts, 'loaded accounts') @@ -99,32 +98,23 @@ function generateTestWithParams(opts = {}) { test(`Generated token precision test ${++count}`, function (t) { const abi = JSON.parse(SimpleTokenDeployer.interface) const owner = addresses[0] - const StandardToken = contract(abi, SimpleTokenDeployer.bytecode, { - from: owner, - gas: '3000000', - gasPrice: '875000000', - }) - StandardToken.new(qty, precision) - .then((txHash) => { - t.ok(txHash, 'publishes a txHash') + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) - return new Promise((res, rej) => { - setTimeout(() => res(txHash), 300) - }) + factory.deploy(qty, precision, { + gasLimit: 3000000, + gasPrice: 875000000 }) - .then((txHash) => { - return eth.getTransactionReceipt(txHash) + .then((token) => { + t.ok(token.deployTransaction.hash, 'publishes a txHash') + return token.deployed() }) - .then((receipt) => { - const addr = receipt.contractAddress - t.ok(addr, 'should have an address') - tokenAddress = addr - token = StandardToken.at(addr) - return token.balanceOf(owner) + .then((deployedToken) => { + t.ok(deployedToken.address, 'should have an address') + tokenAddress = deployedToken.address + return deployedToken.balanceOf(owner) }) - .then((res) => { - const balance = res[0] - t.equal(balance.toString(10), qty, 'owner should have all') + .then((balance) => { + t.equal(balance.toString(), qty, 'owner should have all') var tokenTracker = new TokenTracker({ userAddress: addresses[0], diff --git a/yarn.lock b/yarn.lock index a53b573..320019a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1804,7 +1804,7 @@ __metadata: "@metamask/safe-event-emitter": ^3.0.0 bn.js: ^5.2.1 deep-equal: ^2.2.0 - ganache: 7.3.1 + ganache: 7.9.2 human-standard-token-abi: ^2.0.0 solc: ^0.4.26 tape: ^5.6.1 @@ -2111,13 +2111,29 @@ __metadata: languageName: node linkType: hard -"@trufflesuite/bigint-buffer@npm:1.1.9": - version: 1.1.9 - resolution: "@trufflesuite/bigint-buffer@npm:1.1.9" +"@trufflesuite/bigint-buffer@npm:1.1.10": + version: 1.1.10 + resolution: "@trufflesuite/bigint-buffer@npm:1.1.10" dependencies: node-gyp: latest - node-gyp-build: 4.3.0 - checksum: 627dcff2cae7afe31432646232518363869e89b300f90f88ca68d903d0bdc79119975a5bc338223c03c1a4484cfac6d9cf4413ef20933a69eee48dd925519165 + node-gyp-build: 4.4.0 + checksum: e1dc5e4fbf348a55e660c0055267021eb04cbbdb7f6b0ee983ad32cd4aae1200be448a2ca3963c7d19c7c936d42f66c1ff8b5e4e2332cb1a9e3f870ff818dce4 + languageName: node + linkType: hard + +"@trufflesuite/uws-js-unofficial@npm:20.30.0-unofficial.0": + version: 20.30.0-unofficial.0 + resolution: "@trufflesuite/uws-js-unofficial@npm:20.30.0-unofficial.0" + dependencies: + bufferutil: 4.0.7 + utf-8-validate: 6.0.3 + ws: 8.13.0 + dependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 67e67140877f89b31c504a057d26853d5780b09c733d92c32480d2f0dfe4e98fb822860f3efeb06f379daecee70d67185f88a7b6f3406d18526e501b36c40fd3 languageName: node linkType: hard @@ -2181,7 +2197,22 @@ __metadata: languageName: node linkType: hard -"abstract-leveldown@npm:^7.2.0": +"abstract-level@npm:1.0.3": + version: 1.0.3 + resolution: "abstract-level@npm:1.0.3" + dependencies: + buffer: ^6.0.3 + catering: ^2.1.0 + is-buffer: ^2.0.5 + level-supports: ^4.0.0 + level-transcoder: ^1.0.1 + module-error: ^1.0.1 + queue-microtask: ^1.2.3 + checksum: 70d61a3924526ebc257b138992052f9ff571a6cee5a7660836e37a1cc7081273c3acf465dd2f5e1897b38dc743a6fd9dba14a5d8a2a9d39e5787cd3da99f301d + languageName: node + linkType: hard + +"abstract-leveldown@npm:7.2.0, abstract-leveldown@npm:^7.2.0": version: 7.2.0 resolution: "abstract-leveldown@npm:7.2.0" dependencies: @@ -2317,6 +2348,24 @@ __metadata: languageName: node linkType: hard +"async-eventemitter@npm:0.2.4": + version: 0.2.4 + resolution: "async-eventemitter@npm:0.2.4" + dependencies: + async: ^2.4.0 + checksum: b9e77e0f58ebd7188c50c23d613d1263e0ab501f5e677e02b57cc97d7032beaf60aafa189887e7105569c791e212df4af00b608be1e9a4c425911d577124911e + languageName: node + linkType: hard + +"async@npm:^2.4.0": + version: 2.6.4 + resolution: "async@npm:2.6.4" + dependencies: + lodash: ^4.17.14 + checksum: a52083fb32e1ebe1d63e5c5624038bb30be68ff07a6c8d7dfe35e47c93fc144bd8652cbec869e0ac07d57dde387aa5f1386be3559cdee799cb1f789678d88e19 + languageName: node + linkType: hard + "available-typed-arrays@npm:^1.0.5": version: 1.0.5 resolution: "available-typed-arrays@npm:1.0.5" @@ -2490,6 +2539,16 @@ __metadata: languageName: node linkType: hard +"bufferutil@npm:4.0.7": + version: 4.0.7 + resolution: "bufferutil@npm:4.0.7" + dependencies: + node-gyp: latest + node-gyp-build: ^4.3.0 + checksum: f75aa87e3d1b99b87a95f60a855e63f70af07b57fb8443e75a2ddfef2e47788d130fdd46e3a78fd7e0c10176082b26dfbed970c5b8632e1cc299cafa0e93ce45 + languageName: node + linkType: hard + "cacache@npm:^16.1.0": version: 16.1.3 resolution: "cacache@npm:16.1.3" @@ -2871,9 +2930,9 @@ __metadata: languageName: node linkType: hard -"elliptic@npm:^6.5.2": - version: 6.6.0 - resolution: "elliptic@npm:6.6.0" +"elliptic@npm:^6.5.4": + version: 6.6.1 + resolution: "elliptic@npm:6.6.1" dependencies: bn.js: ^4.11.9 brorand: ^1.1.0 @@ -2882,7 +2941,7 @@ __metadata: inherits: ^2.0.4 minimalistic-assert: ^1.0.1 minimalistic-crypto-utils: ^1.0.1 - checksum: e912349b883e694bfe65005214237a470c9a098a6ba36fd24396d0ab07feb399920c0738aeed1aed6cf5dca9c64fd479e212faed3a75c9d81453671ef0de5157 + checksum: 27b14a52f68bbbc0720da259f712cb73e953f6d2047958cd02fb0d0ade2e83849dc39fb4af630889c67df8817e24237428cf59c4f4c07700f755b401149a7375 languageName: node linkType: hard @@ -3209,19 +3268,23 @@ __metadata: languageName: node linkType: hard -"ganache@npm:7.3.1": - version: 7.3.1 - resolution: "ganache@npm:7.3.1" +"ganache@npm:7.9.2": + version: 7.9.2 + resolution: "ganache@npm:7.9.2" dependencies: - "@trufflesuite/bigint-buffer": 1.1.9 + "@trufflesuite/bigint-buffer": 1.1.10 + "@trufflesuite/uws-js-unofficial": 20.30.0-unofficial.0 "@types/bn.js": ^5.1.0 "@types/lru-cache": 5.1.1 "@types/seedrandom": 3.0.1 + abstract-level: 1.0.3 + abstract-leveldown: 7.2.0 + async-eventemitter: 0.2.4 bufferutil: 4.0.5 emittery: 0.10.0 - keccak: 3.0.1 + keccak: 3.0.2 leveldown: 6.1.0 - secp256k1: 4.0.2 + secp256k1: 4.0.3 utf-8-validate: 5.0.7 dependenciesMeta: bufferutil: @@ -3231,7 +3294,7 @@ __metadata: bin: ganache: dist/node/cli.js ganache-cli: dist/node/cli.js - checksum: 46fe69554dbf12c0f6b2d8cd94945d6989864d01da9daee98f453e26fa6b87008ab92f9a18580872258a48cf49a651ff732e3f754a89f7ceba8bb35f953a1f59 + checksum: 30af47d29e8f10e79f41f2f29e126c36c157767bdf19d8d8f101cfa9bc75eaca933c1c470557041728eef2dd7e2bd8d4715691996b5951d04f8056036cf6cfa0 languageName: node linkType: hard @@ -4016,14 +4079,15 @@ __metadata: languageName: node linkType: hard -"keccak@npm:3.0.1": - version: 3.0.1 - resolution: "keccak@npm:3.0.1" +"keccak@npm:3.0.2": + version: 3.0.2 + resolution: "keccak@npm:3.0.2" dependencies: node-addon-api: ^2.0.0 node-gyp: latest node-gyp-build: ^4.2.0 - checksum: 1de1b62fbb3e035ee186232b11f154bd5c2c12a2d910bc8ec313dab412b6f39ddc51d3a105618dd8de752875da0ead21abb0eb1d4e7d7b17771a4acbb7159390 + readable-stream: ^3.6.0 + checksum: 39a7d6128b8ee4cb7dcd186fc7e20c6087cc39f573a0f81b147c323f688f1f7c2b34f62c4ae189fe9b81c6730b2d1228d8a399cdc1f3d8a4c8f030cdc4f20272 languageName: node linkType: hard @@ -4064,6 +4128,23 @@ __metadata: languageName: node linkType: hard +"level-supports@npm:^4.0.0": + version: 4.0.1 + resolution: "level-supports@npm:4.0.1" + checksum: d4552b42bb8cdeada07b0f6356c7a90fefe76279147331f291aceae26e3e56d5f927b09ce921647c0230bfe03ddfbdcef332be921e5c2194421ae2bfa3cf6368 + languageName: node + linkType: hard + +"level-transcoder@npm:^1.0.1": + version: 1.0.1 + resolution: "level-transcoder@npm:1.0.1" + dependencies: + buffer: ^6.0.3 + module-error: ^1.0.1 + checksum: 304f08d802faf3491a533b6d87ad8be3cabfd27f2713bbe9d4c633bf50fcb9460eab5a6776bf015e101ead7ba1c1853e05e7f341112f17a9d0cb37ee5a421a25 + languageName: node + linkType: hard + "leveldown@npm:6.1.0": version: 6.1.0 resolution: "leveldown@npm:6.1.0" @@ -4103,6 +4184,13 @@ __metadata: languageName: node linkType: hard +"lodash@npm:^4.17.14": + version: 4.17.21 + resolution: "lodash@npm:4.17.21" + checksum: eb835a2e51d381e561e508ce932ea50a8e5a68f4ebdd771ea240d3048244a8d13658acbd502cd4829768c56f2e16bdd4340b9ea141297d472517b83868e677f7 + languageName: node + linkType: hard + "lru-cache@npm:^10.0.1, lru-cache@npm:^9.1.1 || ^10.0.0": version: 10.2.0 resolution: "lru-cache@npm:10.2.0" @@ -4381,6 +4469,13 @@ __metadata: languageName: node linkType: hard +"module-error@npm:^1.0.1": + version: 1.0.2 + resolution: "module-error@npm:1.0.2" + checksum: 5d653e35bd55b3e95f8aee2cdac108082ea892e71b8f651be92cde43e4ee86abee4fa8bd7fc3fe5e68b63926d42f63c54cd17b87a560c31f18739295575a3962 + languageName: node + linkType: hard + "ms@npm:2.1.2": version: 2.1.2 resolution: "ms@npm:2.1.2" @@ -4418,14 +4513,14 @@ __metadata: languageName: node linkType: hard -"node-gyp-build@npm:4.3.0": - version: 4.3.0 - resolution: "node-gyp-build@npm:4.3.0" +"node-gyp-build@npm:4.4.0": + version: 4.4.0 + resolution: "node-gyp-build@npm:4.4.0" bin: node-gyp-build: bin.js node-gyp-build-optional: optional.js node-gyp-build-test: build-test.js - checksum: 1ecab16d9f275174d516e223f60f65ebe07540347d5c04a6a7d6921060b7f2e3af4f19463d9d1dcedc452e275c2ae71354a99405e55ebd5b655bb2f38025c728 + checksum: 972a059f960253d254e0b23ce10f54c8982236fc0edcab85166d0b7f87443b2ce98391c877cfb2f6eeafcf03c538c5f4dd3e0bfff03828eb48634f58f4c64343 languageName: node linkType: hard @@ -5076,15 +5171,15 @@ __metadata: languageName: node linkType: hard -"secp256k1@npm:4.0.2": - version: 4.0.2 - resolution: "secp256k1@npm:4.0.2" +"secp256k1@npm:4.0.3": + version: 4.0.3 + resolution: "secp256k1@npm:4.0.3" dependencies: - elliptic: ^6.5.2 + elliptic: ^6.5.4 node-addon-api: ^2.0.0 node-gyp: latest node-gyp-build: ^4.2.0 - checksum: 0d0d42e8033aee5aec5caaaa26d90fcaec4bf5e24dc4652552ddaa60734c2d95e90f7d95697b521fe833363c629d5ff623227961de86686c7a0ed5b5ffc1ebd0 + checksum: 21e219adc0024fbd75021001358780a3cc6ac21273c3fcaef46943af73969729709b03f1df7c012a0baab0830fb9a06ccc6b42f8d50050c665cb98078eab477b languageName: node linkType: hard @@ -5599,6 +5694,16 @@ __metadata: languageName: node linkType: hard +"utf-8-validate@npm:6.0.3": + version: 6.0.3 + resolution: "utf-8-validate@npm:6.0.3" + dependencies: + node-gyp: latest + node-gyp-build: ^4.3.0 + checksum: 5e21383c81ff7469c1912119ca69d07202d944c73ddd8a54b84dddcc546b939054e5101c78c294e494d206fe93bd43428adc635a0660816b3ec9c8ec89286ac4 + languageName: node + linkType: hard + "util-deprecate@npm:^1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2" @@ -5795,6 +5900,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:8.13.0": + version: 8.13.0 + resolution: "ws@npm:8.13.0" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ">=5.0.2" + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c + languageName: node + linkType: hard + "y18n@npm:^3.2.1": version: 3.2.2 resolution: "y18n@npm:3.2.2" From 08d7ed745c3fd9109109b465f8f04570f640bade Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Mon, 20 Jan 2025 22:08:53 +0100 Subject: [PATCH 3/5] chore: remove @metamask/ethjs-contract and @metamask/ethjs-query --- package.json | 2 - yarn.lock | 187 ++------------------------------------------------- 2 files changed, 5 insertions(+), 184 deletions(-) diff --git a/package.json b/package.json index aa10b8a..40533e1 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,6 @@ "@lavamoat/allow-scripts": "^2.3.1", "@lavamoat/preinstall-always-fail": "^2.0.0", "@metamask/auto-changelog": "^3.4.3", - "@metamask/ethjs-contract": "^0.4.1", - "@metamask/ethjs-query": "^0.7.1", "ganache": "7.9.2", "solc": "^0.4.26", "tape": "^5.6.1" diff --git a/yarn.lock b/yarn.lock index 320019a..aa63fdf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1799,8 +1799,6 @@ __metadata: "@lavamoat/preinstall-always-fail": ^2.0.0 "@metamask/auto-changelog": ^3.4.3 "@metamask/eth-block-tracker": ^11.0.3 - "@metamask/ethjs-contract": ^0.4.1 - "@metamask/ethjs-query": ^0.7.1 "@metamask/safe-event-emitter": ^3.0.0 bn.js: ^5.2.1 deep-equal: ^2.2.0 @@ -1813,82 +1811,6 @@ __metadata: languageName: unknown linkType: soft -"@metamask/ethjs-contract@npm:^0.4.1": - version: 0.4.1 - resolution: "@metamask/ethjs-contract@npm:0.4.1" - dependencies: - "@metamask/ethjs-filter": ^0.3.0 - "@metamask/ethjs-util": ^0.3.0 - ethjs-abi: ^0.2.0 - js-sha3: ^0.9.2 - promise-to-callback: ^1.0.0 - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: d2e6b16fd70ad7a51b5f3813d044358e6f09b65e673de287e91986bb0fa14faa21cb1cd6e6b13c27f83302bc3a0371ceb7417c48fb4860d8a478606c4c2e6e5e - languageName: node - linkType: hard - -"@metamask/ethjs-filter@npm:^0.3.0": - version: 0.3.0 - resolution: "@metamask/ethjs-filter@npm:0.3.0" - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: aedb31816f6b15ad8f5464eca5d74e5d38a5203c3cf1adc44028b174245fd7400a3cce5a80c03ca3a2a89ef24d81583f9d154374d9941b56544db2ff0a085f3b - languageName: node - linkType: hard - -"@metamask/ethjs-format@npm:^0.3.0": - version: 0.3.0 - resolution: "@metamask/ethjs-format@npm:0.3.0" - dependencies: - "@metamask/ethjs-util": ^0.3.0 - "@metamask/number-to-bn": ^1.7.1 - bn.js: ^5.2.1 - ethjs-schema: 0.2.1 - is-hex-prefixed: 1.0.0 - strip-hex-prefix: 1.0.0 - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: c0ea8d43f2149ba4c94909ae2dbe7d2e95363ba627bb73716f81406823fc7e76eb53edaa6bf03fa5c5dc08c7716af201ac8c21dd5a30d0c131b11ede40fcd60b - languageName: node - linkType: hard - -"@metamask/ethjs-query@npm:^0.7.1": - version: 0.7.1 - resolution: "@metamask/ethjs-query@npm:0.7.1" - dependencies: - "@metamask/ethjs-format": ^0.3.0 - "@metamask/ethjs-rpc": ^0.4.0 - promise-to-callback: ^1.0.0 - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: d843f783f38b2c8145f10311dc9f0c4257da3a60d43ebdf136c4ae2bd74f1f0375d855e0400e0b97b839fc9845e5d1f5a9ff54a8fb676710bf856b12fc0c152b - languageName: node - linkType: hard - -"@metamask/ethjs-rpc@npm:^0.4.0": - version: 0.4.0 - resolution: "@metamask/ethjs-rpc@npm:0.4.0" - dependencies: - promise-to-callback: ^1.0.0 - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: 5c482849e8cadbde5baf8fec9d337f181c8ed672f4b0a9e1f7fe0a57d792e214e6722fbe350162f5d375bc78c7a6c98330d3b7c3909b428489313ed36888c07c - languageName: node - linkType: hard - -"@metamask/ethjs-util@npm:^0.3.0": - version: 0.3.0 - resolution: "@metamask/ethjs-util@npm:0.3.0" - dependencies: - is-hex-prefixed: 1.0.0 - strip-hex-prefix: 1.0.0 - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: 3c0e8dd7f24b5ed6038d57fd8c278c6b09a89fb3eb487a65ca16bea89260c99e5d3c86d54676920ff7cb462fd7dd2becd4ebd784e14c905233f3b0125e5dbc4c - languageName: node - linkType: hard - "@metamask/json-rpc-engine@npm:^10.0.1": version: 10.0.1 resolution: "@metamask/json-rpc-engine@npm:10.0.1" @@ -1900,16 +1822,6 @@ __metadata: languageName: node linkType: hard -"@metamask/number-to-bn@npm:^1.7.1": - version: 1.7.1 - resolution: "@metamask/number-to-bn@npm:1.7.1" - dependencies: - bn.js: 5.2.1 - strip-hex-prefix: 1.0.0 - checksum: e3c198c7ab4783757b36413d67d917f5fd5cadd01ebd7d92ae1ab6cbb11f11bfe9fae89ed849f8d7b0120c3746c58d87e9950df167bd342f0a6e590590d4e0ce - languageName: node - linkType: hard - "@metamask/rpc-errors@npm:^7.0.1": version: 7.0.1 resolution: "@metamask/rpc-errors@npm:7.0.1" @@ -2449,27 +2361,20 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:4.11.6": - version: 4.11.6 - resolution: "bn.js@npm:4.11.6" - checksum: db23047bf06fdf9cf74401c8e76bca9f55313c81df382247d2c753868b368562e69171716b81b7038ada8860af18346fd4bcd1cf9d4963f923fe8e54e61cb58a +"bn.js@npm:^4.11.9": + version: 4.12.0 + resolution: "bn.js@npm:4.12.0" + checksum: 39afb4f15f4ea537b55eaf1446c896af28ac948fdcf47171961475724d1bb65118cca49fa6e3d67706e4790955ec0e74de584e45c8f1ef89f46c812bee5b5a12 languageName: node linkType: hard -"bn.js@npm:5.2.1, bn.js@npm:^5.2.1": +"bn.js@npm:^5.2.1": version: 5.2.1 resolution: "bn.js@npm:5.2.1" checksum: 3dd8c8d38055fedfa95c1d5fc3c99f8dd547b36287b37768db0abab3c239711f88ff58d18d155dd8ad902b0b0cee973747b7ae20ea12a09473272b0201c9edd3 languageName: node linkType: hard -"bn.js@npm:^4.11.9": - version: 4.12.0 - resolution: "bn.js@npm:4.12.0" - checksum: 39afb4f15f4ea537b55eaf1446c896af28ac948fdcf47171961475724d1bb65118cca49fa6e3d67706e4790955ec0e74de584e45c8f1ef89f46c812bee5b5a12 - languageName: node - linkType: hard - "brace-expansion@npm:^1.1.7": version: 1.1.11 resolution: "brace-expansion@npm:1.1.11" @@ -3091,24 +2996,6 @@ __metadata: languageName: node linkType: hard -"ethjs-abi@npm:^0.2.0": - version: 0.2.1 - resolution: "ethjs-abi@npm:0.2.1" - dependencies: - bn.js: 4.11.6 - js-sha3: 0.5.5 - number-to-bn: 1.7.0 - checksum: f58ad78f08ab0eda43b799075b245e39178f26045b0b21600f1d2544b04f6ba197734b43825112b5fd63acd5cb9ca4ea4df7e72d7ec58457f907e88f5ad52b13 - languageName: node - linkType: hard - -"ethjs-schema@npm:0.2.1": - version: 0.2.1 - resolution: "ethjs-schema@npm:0.2.1" - checksum: 7d8b1225bcf9616bfe94a24c2f4a48dae5ec30180a61d509efd7335eec68431abee638fbd02c2088e0ee59010396284e4b8364af8afdb229ac67e29ae38a3230 - languageName: node - linkType: hard - "execa@npm:^5.1.1": version: 5.1.1 resolution: "execa@npm:5.1.1" @@ -3791,13 +3678,6 @@ __metadata: languageName: node linkType: hard -"is-fn@npm:^1.0.0": - version: 1.0.0 - resolution: "is-fn@npm:1.0.0" - checksum: eeea1e536716f93a92dc1a8550b2c0909fe74bb5144d0fb6d65e0d31eb9c06c30559f69d83a9351d2288cc7293b43bc074e0fab5fae19e312ff38aa0c7672827 - languageName: node - linkType: hard - "is-fullwidth-code-point@npm:^1.0.0": version: 1.0.0 resolution: "is-fullwidth-code-point@npm:1.0.0" @@ -3823,13 +3703,6 @@ __metadata: languageName: node linkType: hard -"is-hex-prefixed@npm:1.0.0": - version: 1.0.0 - resolution: "is-hex-prefixed@npm:1.0.0" - checksum: 5ac58e6e528fb029cc43140f6eeb380fad23d0041cc23154b87f7c9a1b728bcf05909974e47248fd0b7fcc11ba33cf7e58d64804883056fabd23e2b898be41de - languageName: node - linkType: hard - "is-lambda@npm:^1.0.1": version: 1.0.1 resolution: "is-lambda@npm:1.0.1" @@ -3998,13 +3871,6 @@ __metadata: languageName: node linkType: hard -"js-sha3@npm:0.5.5": - version: 0.5.5 - resolution: "js-sha3@npm:0.5.5" - checksum: 19900933f7b8cf0b91a8aba3ecbc2e27a336d0e7dc0bb30db938a56a399b355f68a98e086d2523db03c9f6abea5de42d40ce7237c9d3412f5eb44a5d409033f0 - languageName: node - linkType: hard - "js-sha3@npm:0.8.0": version: 0.8.0 resolution: "js-sha3@npm:0.8.0" @@ -4012,13 +3878,6 @@ __metadata: languageName: node linkType: hard -"js-sha3@npm:^0.9.2": - version: 0.9.3 - resolution: "js-sha3@npm:0.9.3" - checksum: cfab12cdb3aa9c0c8e8466761d89cb9770653880910b920682fa676dd102868a827709c857cb089bdc0d6120542137f92a7c1699ab428c0f4057c823aef24601 - languageName: node - linkType: hard - "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -4659,16 +4518,6 @@ __metadata: languageName: node linkType: hard -"number-to-bn@npm:1.7.0": - version: 1.7.0 - resolution: "number-to-bn@npm:1.7.0" - dependencies: - bn.js: 4.11.6 - strip-hex-prefix: 1.0.0 - checksum: 5b8c9dbe7b49dc7a069e5f0ba4e197257c89db11463478cb002fee7a34dc8868636952bd9f6310e5fdf22b266e0e6dffb5f9537c741734718107e90ae59b3de4 - languageName: node - linkType: hard - "object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0": version: 1.12.3 resolution: "object-inspect@npm:1.12.3" @@ -4892,16 +4741,6 @@ __metadata: languageName: node linkType: hard -"promise-to-callback@npm:^1.0.0": - version: 1.0.0 - resolution: "promise-to-callback@npm:1.0.0" - dependencies: - is-fn: ^1.0.0 - set-immediate-shim: ^1.0.1 - checksum: 8c9e1327386e00f799589cdf96fff2586a13b52b0185222bc3199e1305ba9344589eedfd4038dcbaf5592d85d567097d1507b81e948b7fff6ffdd3de49d54e14 - languageName: node - linkType: hard - "queue-microtask@npm:^1.2.3": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -5219,13 +5058,6 @@ __metadata: languageName: node linkType: hard -"set-immediate-shim@npm:^1.0.1": - version: 1.0.1 - resolution: "set-immediate-shim@npm:1.0.1" - checksum: 5085c84039d1e5eee73d2bf48ce765fcec76159021d0cc7b40e23bcdf62cb6d450ffb781e3c62c1118425242c48eae96df712cba0a20a437e86b0d4a15d51a11 - languageName: node - linkType: hard - "shebang-command@npm:^2.0.0": version: 2.0.0 resolution: "shebang-command@npm:2.0.0" @@ -5498,15 +5330,6 @@ __metadata: languageName: node linkType: hard -"strip-hex-prefix@npm:1.0.0": - version: 1.0.0 - resolution: "strip-hex-prefix@npm:1.0.0" - dependencies: - is-hex-prefixed: 1.0.0 - checksum: 4cafe7caee1d281d3694d14920fd5d3c11adf09371cef7e2ccedd5b83efd9e9bd2219b5d6ce6e809df6e0f437dc9d30db1192116580875698aad164a6d6b285b - languageName: node - linkType: hard - "supports-color@npm:^5.3.0": version: 5.5.0 resolution: "supports-color@npm:5.5.0" From 6d0229b15ea94f995a3b5370127714cc1f7175a8 Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 21 Jan 2025 00:11:08 +0100 Subject: [PATCH 4/5] chore: use ethers 6 --- lib/index.js | 5 +- lib/token.js | 15 +- package.json | 8 +- test/helper.js | 25 +- test/integration/human-standard-token.js | 29 +- test/integration/simple-token.js | 18 +- test/integration/token-precision.js | 37 ++- test/unit/index.js | 114 +++---- test/unit/token.js | 44 +-- yarn.lock | 407 ++++------------------- 10 files changed, 227 insertions(+), 475 deletions(-) diff --git a/lib/index.js b/lib/index.js index 64c9f7e..4342cdd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,5 @@ const { PollingBlockTracker } = require('@metamask/eth-block-tracker') -const { Web3Provider } = require('@ethersproject/providers') -const { Contract } = require('@ethersproject/contracts') +const { Contract, BrowserProvider } = require('ethers') const Token = require('./token') const abi = require('human-standard-token-abi') const SafeEventEmitter = require('@metamask/safe-event-emitter').default @@ -54,7 +53,7 @@ class TokenTracker extends SafeEventEmitter { return new Contract( tokenAddress, abi, - new Web3Provider(this.provider), + new BrowserProvider(this.provider), ) } diff --git a/lib/token.js b/lib/token.js index 08aff8a..813c259 100644 --- a/lib/token.js +++ b/lib/token.js @@ -1,5 +1,4 @@ const BN = require('bn.js') -const { BigNumber } = require("@ethersproject/bignumber") const util = require('./util') /** @@ -23,6 +22,16 @@ function _isInvalidBnInput (input, base) { ) } +/** + * Converts a BigInt value to a BN instance. + * + * @param {BigInt} bigIntValue - The BigInt value to convert. + * @returns {BN} The BN instance representing the BigInt value. + */ +function _bigIntToBN(bigIntValue) { + return new BN(bigIntValue.toString()); +} + class Token { constructor ({ @@ -139,8 +148,8 @@ class Token { if (result) { let val = result - if (BigNumber.isBigNumber(result)) { - val = new BN(result.toString()) + if (typeof result === 'bigint') { + val = _bigIntToBN(result) } this[key] = val return val diff --git a/package.json b/package.json index 40533e1..054e855 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,11 @@ "/lib" ], "dependencies": { - "@ethersproject/bignumber": "^5.7.0", - "@ethersproject/contracts": "^5.7.0", - "@ethersproject/providers": "^5.7.2", "@metamask/eth-block-tracker": "^11.0.3", "@metamask/safe-event-emitter": "^3.0.0", "bn.js": "^5.2.1", "deep-equal": "^2.2.0", + "ethers": "^6.13.5", "human-standard-token-abi": "^2.0.0" }, "devDependencies": { @@ -74,7 +72,9 @@ "ganache>secp256k1": true, "ganache>utf-8-validate": true, "ganache>@trufflesuite/uws-js-unofficial>bufferutil": false, - "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false + "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false, + "ethers>ws>bufferutil": false, + "ethers>ws>utf-8-validate": false } } } diff --git a/test/helper.js b/test/helper.js index dd11cdf..d2a611e 100644 --- a/test/helper.js +++ b/test/helper.js @@ -2,8 +2,7 @@ const assert = require('assert').strict const fs = require('fs') const path = require('path') const ganache = require('ganache') -const { Web3Provider } = require('@ethersproject/providers') -const { ContractFactory } = require('@ethersproject/contracts') +const { ContractFactory, BrowserProvider } = require('ethers') const solc = require('solc') const source = fs.readFileSync(path.resolve(__dirname, 'contracts/Token.sol')).toString(); @@ -13,29 +12,31 @@ const SimpleTokenDeployer = compiled.contracts[':SimpleToken'] const defaultQuantity = '100000000000000000000' // 100 x 10 ^ 18 async function setupSimpleTokenEnvironment ({ qty = defaultQuantity } = {}) { const provider = ganache.provider() - const ethersProvider = new Web3Provider(provider) + const ethersProvider = new BrowserProvider(provider) - const addresses = await ethersProvider.listAccounts() + const accounts = await ethersProvider.listAccounts() + const addresses = accounts.map(account => account.address) assert(addresses.length > 0, 'test network should be initialized with accounts') const owner = addresses[0] const abi = JSON.parse(SimpleTokenDeployer.interface) - const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) + const signer = await ethersProvider.getSigner(owner) + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, signer) - const token = await factory.deploy(qty) - const txHash = token.deployTransaction.hash - assert.ok(txHash, 'should have published the token and returned a transaction hash') + const contract = await factory.deploy(qty) + const { hash } = contract.deploymentTransaction() + assert.ok(hash, 'should have published the token and returned a transaction hash') - await token.deployed() - const receipt = await ethersProvider.getTransactionReceipt(txHash) + await contract.waitForDeployment() + const receipt = await ethersProvider.getTransactionReceipt(hash) const tokenAddress = receipt.contractAddress assert.ok(tokenAddress, 'should have a token address') - const balance = await token.balanceOf(owner) + const balance = await contract.balanceOf(owner) assert.equal(balance.toString(), qty, 'owner should have all') - return { addresses, provider, token, tokenAddress } + return { addresses, provider, contract, tokenAddress } } module.exports = { setupSimpleTokenEnvironment } diff --git a/test/integration/human-standard-token.js b/test/integration/human-standard-token.js index 86f0c87..2ca5332 100644 --- a/test/integration/human-standard-token.js +++ b/test/integration/human-standard-token.js @@ -2,8 +2,7 @@ const fs = require('fs') const path = require('path') const test = require('tape') const ganache = require('ganache') -const { Web3Provider } = require('@ethersproject/providers') -const { ContractFactory } = require('@ethersproject/contracts') +const { ContractFactory, BrowserProvider } = require('ethers') const solc = require('solc') const TokenTracker = require('../../lib') @@ -19,12 +18,12 @@ const EXPECTED_SYMBOL = 'EXP' let addresses = [] let token, tokenAddress, tracked -const ethersProvider = new Web3Provider(provider) +const ethersProvider = new BrowserProvider(provider) test('testrpc has addresses', function (t) { ethersProvider.listAccounts() .then((accounts) => { - addresses = accounts + addresses = accounts.map(account => account.address) t.ok(accounts, 'loaded accounts') t.end() }) @@ -32,19 +31,25 @@ test('testrpc has addresses', function (t) { test('HumanStandardToken publishing token & checking balance', function (t) { const abi = JSON.parse(HumanStandardDeployer.interface) - const factory = new ContractFactory(abi, HumanStandardDeployer.bytecode, ethersProvider.getSigner(addresses[0])) - - factory.deploy('1000', 'DanBucks', '2', SET_SYMBOL, { - gasLimit: '3000000', - gasPrice: '875000000', + ethersProvider.getSigner(addresses[0]) + .then((signer) => { + const factory = new ContractFactory(abi, HumanStandardDeployer.bytecode, signer) + return factory.deploy('1000', 'DanBucks', '2', SET_SYMBOL, { + gasLimit: '3000000', + gasPrice: '875000000', + }) }) .then((contract) => { - t.ok(contract.deployTransaction.hash, 'publishes a txHash') - return contract.deployed() + t.ok(contract.deploymentTransaction().hash, 'publishes a txHash') + return contract.waitForDeployment() }) .then((deployedContract) => { token = deployedContract - tokenAddress = token.address + return deployedContract.getAddress() + }) + .then((address) => { + t.ok(address, 'should have an address') + tokenAddress = address return token.balanceOf(addresses[0]) }) .then((balance) => { diff --git a/test/integration/simple-token.js b/test/integration/simple-token.js index 53aa591..ec6318c 100644 --- a/test/integration/simple-token.js +++ b/test/integration/simple-token.js @@ -11,14 +11,14 @@ const less = '10000000000000000000' // 100 x 10 ^ 17 test('StandardToken balances are tracked', function (t) { let addresses - let token + let contract let tokenAddress let tokenTracker let provider setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - token = environment.token + contract = environment.contract tokenAddress = environment.tokenAddress provider = environment.provider tokenTracker = new TokenTracker({ @@ -40,7 +40,7 @@ test('StandardToken balances are tracked', function (t) { .then(() => { tracked = tokenTracker.serialize()[0] t.equal(tracked.balance.toString(10), qty, 'initial balance loaded') - return token.transfer(addresses[1], less) + return contract.transfer(addresses[1], less) }) .then((tx) => { return provider.request({ @@ -79,11 +79,11 @@ test('StandardToken balances are tracked', function (t) { test('StandardToken balance changes are emitted and symbol fetched', function (t) { let addresses - let token + let contract setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - token = environment.token + contract = environment.contract const { provider, tokenAddress } = environment var tokenTracker = new TokenTracker({ userAddress: addresses[0], @@ -114,7 +114,7 @@ test('StandardToken balance changes are emitted and symbol fetched', function (t return new Promise((res, rej) => { setTimeout(res, 200) }) }) .then(() => { - return token.transfer(addresses[1], '100') + return contract.transfer(addresses[1], '100') }) .catch((reason) => { t.notOk(reason, 'should not throw an error') @@ -125,12 +125,12 @@ test('StandardToken balance changes are emitted and symbol fetched', function (t test('StandardToken non balance changes are not emitted', function (t) { let addresses - let token + let contract let tokenTracker setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - token = environment.token + contract = environment.contract const { provider, tokenAddress } = environment tokenTracker = new TokenTracker({ userAddress: addresses[0], @@ -158,7 +158,7 @@ test('StandardToken non balance changes are not emitted', function (t) { return new Promise((res, rej) => { setTimeout(res, 200) }) }) .then(() => { - return token.transfer(addresses[1], '0') + return contract.transfer(addresses[1], '0') }) .then(() => { var a = new Promise((res, rej) => { setTimeout(res, 200) }) diff --git a/test/integration/token-precision.js b/test/integration/token-precision.js index 6de229c..65def38 100644 --- a/test/integration/token-precision.js +++ b/test/integration/token-precision.js @@ -6,11 +6,10 @@ const solc = require('solc') const TokenTracker = require('../../lib') const BN = require('bn.js') const util = require('../../lib/util') -const { ContractFactory } = require('@ethersproject/contracts') -const { Web3Provider } = require('@ethersproject/providers') +const { ContractFactory, BrowserProvider } = require('ethers') const provider = ganache.provider() -const ethersProvider = new Web3Provider(provider) +const ethersProvider = new BrowserProvider(provider) let count = 0 const source = fs.readFileSync(path.resolve(__dirname, '..', 'contracts/ZeppelinToken.sol')).toString(); @@ -19,12 +18,12 @@ const compiled = solc.compile(source, 1) const SimpleTokenDeployer = compiled.contracts[':TutorialToken'] let addresses = [] -let tokenAddress, tracked +let token, tokenAddress, tracked test('testrpc has addresses', function (t) { ethersProvider.listAccounts() .then((accounts) => { - addresses = accounts + addresses = accounts.map(account => account.address) t.ok(accounts, 'loaded accounts') t.end() }) @@ -98,20 +97,26 @@ function generateTestWithParams(opts = {}) { test(`Generated token precision test ${++count}`, function (t) { const abi = JSON.parse(SimpleTokenDeployer.interface) const owner = addresses[0] - const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) + ethersProvider.getSigner(owner).then((signer) => { + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, signer) - factory.deploy(qty, precision, { - gasLimit: 3000000, - gasPrice: 875000000 + return factory.deploy(qty, precision, { + gasLimit: 3000000, + gasPrice: 875000000 + }) + }) + .then((contract) => { + t.ok(contract.deploymentTransaction().hash, 'publishes a txHash') + return contract.waitForDeployment() }) - .then((token) => { - t.ok(token.deployTransaction.hash, 'publishes a txHash') - return token.deployed() + .then((deployedContract) => { + token = deployedContract + return deployedContract.getAddress() }) - .then((deployedToken) => { - t.ok(deployedToken.address, 'should have an address') - tokenAddress = deployedToken.address - return deployedToken.balanceOf(owner) + .then((address) => { + t.ok(address, 'should have an address') + tokenAddress = address + return token.balanceOf(owner) }) .then((balance) => { t.equal(balance.toString(), qty, 'owner should have all') diff --git a/test/unit/index.js b/test/unit/index.js index d945aa6..1afcedd 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -160,7 +160,7 @@ test('tracker with minimal token and one block update with no changes', async fu t.plan(2) let tracker try { - const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -178,7 +178,7 @@ test('tracker with minimal token and one block update with no changes', async fu }) await new Promise((resolve) => setTimeout(() => resolve(), 200)) - await token.transfer(addresses[1], '0') + await contract.transfer(addresses[1], '0') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.equal(updates.length, 1, 'should have one update') @@ -206,7 +206,7 @@ test('tracker with minimal token and two rapid block updates, the first with cha t.plan(2) let tracker try { - const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -225,8 +225,8 @@ test('tracker with minimal token and two rapid block updates, the first with cha await new Promise((resolve) => setTimeout(() => resolve(), 200)) await Promise.all([ - token.transfer(addresses[1], '110'), - token.transfer(addresses[1], '0'), + contract.transfer(addresses[1], '110'), + contract.transfer(addresses[1], '0'), ]) await new Promise((resolve) => setTimeout(() => resolve(), 200)) @@ -263,7 +263,7 @@ test('tracker with minimal token and one block update with changes', async funct t.plan(1) let tracker try { - const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -280,7 +280,7 @@ test('tracker with minimal token and one block update with changes', async funct updates.push(tokens) }) await new Promise((resolve) => setTimeout(() => resolve(), 200)) - await token.transfer(addresses[1], '110') + await contract.transfer(addresses[1], '110') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.deepEqual( @@ -315,7 +315,7 @@ test('tracker with minimal token and one immediate block update with changes', a t.plan(1) let tracker try { - const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -331,7 +331,7 @@ test('tracker with minimal token and one immediate block update with changes', a tracker.on('update', (tokens) => { updates.push(tokens) }) - await token.transfer(addresses[1], '110') + await contract.transfer(addresses[1], '110') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.deepEqual( @@ -362,51 +362,51 @@ test('tracker with minimal token and one immediate block update with changes', a } }) -test('tracker with broken provider', async function (t) { - t.plan(1) - let tracker - try { - tracker = new TokenTracker({ - provider: { - request: () => { - throw new Error('Fake provider error') - } - }, - tokens: [{ - address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', - }], - }) - tracker.on('error', () => { - t.pass('should emit error event') - }) - await new Promise((resolve) => setTimeout(() => resolve(), 200)) - t.end() - } finally { - tracker.stop() - } -}) - -test('tracker with broken provider and includeFailedTokens', async function (t) { - t.plan(1) - let tracker - try { - tracker = new TokenTracker({ - provider: { - request: () => { - throw new Error('Fake provider error') - } - }, - includeFailedTokens: true, - tokens: [{ - address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', - }], - }) - tracker.on('update', () => { - t.pass('should emit update event') - }) - await new Promise((resolve) => setTimeout(() => resolve(), 200)) - t.end() - } finally { - tracker.stop() - } -}) \ No newline at end of file +// test('tracker with broken provider', async function (t) { +// t.plan(1) +// let tracker +// try { +// tracker = new TokenTracker({ +// provider: { +// request: () => { +// throw new Error('Fake provider error') +// } +// }, +// tokens: [{ +// address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', +// }], +// }) +// tracker.on('error', () => { +// t.pass('should emit error event') +// }) +// await new Promise((resolve) => setTimeout(() => resolve(), 200)) +// t.end() +// } finally { +// tracker.stop() +// } +// }) + +// test('tracker with broken provider and includeFailedTokens', async function (t) { +// t.plan(1) +// let tracker +// try { +// tracker = new TokenTracker({ +// provider: { +// request: () => { +// throw new Error('Fake provider error') +// } +// }, +// includeFailedTokens: true, +// tokens: [{ +// address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', +// }], +// }) +// tracker.on('update', () => { +// t.pass('should emit update event') +// }) +// await new Promise((resolve) => setTimeout(() => resolve(), 200)) +// t.end() +// } finally { +// tracker.stop() +// } +// }) diff --git a/test/unit/token.js b/test/unit/token.js index 728494d..1290d01 100644 --- a/test/unit/token.js +++ b/test/unit/token.js @@ -17,7 +17,7 @@ test('token with empty options', function (t) { test('token with just contract option', async function (t) { t.plan(1) - const { token: contract } = await setupSimpleTokenEnvironment() + const { contract } = await setupSimpleTokenEnvironment() t.throws(() => (new Token({ contract })), 'should throw if missing owner parameter') t.end() }) @@ -31,7 +31,7 @@ test('token with just owner option', async function (t) { test('token with minimal options', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ contract, owner: addresses[0], @@ -54,7 +54,7 @@ test('token with minimal options', async function (t) { test('token with address', async function (t) { t.plan(1) - const { addresses, token: contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, contract, tokenAddress } = await setupSimpleTokenEnvironment() const token = new Token({ address: tokenAddress, contract, @@ -68,7 +68,7 @@ test('token with address', async function (t) { test('token with symbol', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ contract, owner: addresses[0], @@ -82,7 +82,7 @@ test('token with symbol', async function (t) { test('token with number balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 10, contract, @@ -96,7 +96,7 @@ test('token with number balance', async function (t) { test('token with unprefixed hex string balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 'f', contract, @@ -110,7 +110,7 @@ test('token with unprefixed hex string balance', async function (t) { test('token with decimal string balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: '10', contract, @@ -124,7 +124,7 @@ test('token with decimal string balance', async function (t) { test('token with BN.js balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: new BN(10), contract, @@ -138,7 +138,7 @@ test('token with BN.js balance', async function (t) { test('token with array balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: [10], contract, @@ -152,7 +152,7 @@ test('token with array balance', async function (t) { test('token with prefixed hex string balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -168,7 +168,7 @@ test('token with prefixed hex string balance', async function (t) { test('token with invalid string balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -184,7 +184,7 @@ test('token with invalid string balance', async function (t) { test('token with zero balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 0, contract, @@ -198,7 +198,7 @@ test('token with zero balance', async function (t) { test('token with empty string balance', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: '', contract, @@ -212,7 +212,7 @@ test('token with empty string balance', async function (t) { test('token with decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: 10, contract, @@ -226,7 +226,7 @@ test('token with decimals', async function (t) { test('token with string decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: '10', contract, @@ -240,7 +240,7 @@ test('token with string decimals', async function (t) { test('token with unprefixed hex string decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -256,7 +256,7 @@ test('token with unprefixed hex string decimals', async function (t) { test('token with prefixed hex string decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -272,7 +272,7 @@ test('token with prefixed hex string decimals', async function (t) { test('token with invalid string decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -288,7 +288,7 @@ test('token with invalid string decimals', async function (t) { test('token with zero decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: 0, contract, @@ -302,7 +302,7 @@ test('token with zero decimals', async function (t) { test('token with empty string decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: '', contract, @@ -316,7 +316,7 @@ test('token with empty string decimals', async function (t) { test('token with BN.js decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: new BN(10), contract, @@ -330,7 +330,7 @@ test('token with BN.js decimals', async function (t) { test('token with array decimals', async function (t) { t.plan(1) - const { addresses, token: contract } = await setupSimpleTokenEnvironment() + const { addresses, contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: [10], contract, diff --git a/yarn.lock b/yarn.lock index aa63fdf..a314e29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,6 +5,13 @@ __metadata: version: 6 cacheKey: 8 +"@adraffy/ens-normalize@npm:1.10.1": + version: 1.10.1 + resolution: "@adraffy/ens-normalize@npm:1.10.1" + checksum: 0836f394ea256972ec19a0b5e78cb7f5bcdfd48d8a32c7478afc94dd53ae44c04d1aa2303d7f3077b4f3ac2323b1f557ab9188e8059978748fdcd83e04a80dcc + languageName: node + linkType: hard + "@ampproject/remapping@npm:^2.2.0": version: 2.2.1 resolution: "@ampproject/remapping@npm:2.2.1" @@ -1349,296 +1356,6 @@ __metadata: languageName: node linkType: hard -"@ethersproject/abi@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/abi@npm:5.7.0" - dependencies: - "@ethersproject/address": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/constants": ^5.7.0 - "@ethersproject/hash": ^5.7.0 - "@ethersproject/keccak256": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/strings": ^5.7.0 - checksum: bc6962bb6cb854e4d2a4d65b2c49c716477675b131b1363312234bdbb7e19badb7d9ce66f4ca2a70ae2ea84f7123dbc4e300a1bfe5d58864a7eafabc1466627e - languageName: node - linkType: hard - -"@ethersproject/abstract-provider@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/abstract-provider@npm:5.7.0" - dependencies: - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/networks": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/transactions": ^5.7.0 - "@ethersproject/web": ^5.7.0 - checksum: 74cf4696245cf03bb7cc5b6cbf7b4b89dd9a79a1c4688126d214153a938126d4972d42c93182198653ce1de35f2a2cad68be40337d4774b3698a39b28f0228a8 - languageName: node - linkType: hard - -"@ethersproject/abstract-signer@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/abstract-signer@npm:5.7.0" - dependencies: - "@ethersproject/abstract-provider": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - checksum: a823dac9cfb761e009851050ebebd5b229d1b1cc4a75b125c2da130ff37e8218208f7f9d1386f77407705b889b23d4a230ad67185f8872f083143e0073cbfbe3 - languageName: node - linkType: hard - -"@ethersproject/address@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/address@npm:5.7.0" - dependencies: - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/keccak256": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/rlp": ^5.7.0 - checksum: 64ea5ebea9cc0e845c413e6cb1e54e157dd9fc0dffb98e239d3a3efc8177f2ff798cd4e3206cf3660ee8faeb7bef1a47dc0ebef0d7b132c32e61e550c7d4c843 - languageName: node - linkType: hard - -"@ethersproject/base64@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/base64@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - checksum: 7dd5d734d623582f08f665434f53685041a3d3b334a0e96c0c8afa8bbcaab934d50e5b6b980e826a8fde8d353e0b18f11e61faf17468177274b8e7c69cd9742b - languageName: node - linkType: hard - -"@ethersproject/basex@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/basex@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - checksum: 326087b7e1f3787b5fe6cd1cf2b4b5abfafbc355a45e88e22e5e9d6c845b613ffc5301d629b28d5c4d5e2bfe9ec424e6782c804956dff79be05f0098cb5817de - languageName: node - linkType: hard - -"@ethersproject/bignumber@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/bignumber@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - bn.js: ^5.2.1 - checksum: 8c9a134b76f3feb4ec26a5a27379efb4e156b8fb2de0678a67788a91c7f4e30abe9d948638458e4b20f2e42380da0adacc7c9389d05fce070692edc6ae9b4904 - languageName: node - linkType: hard - -"@ethersproject/bytes@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/bytes@npm:5.7.0" - dependencies: - "@ethersproject/logger": ^5.7.0 - checksum: 66ad365ceaab5da1b23b72225c71dce472cf37737af5118181fa8ab7447d696bea15ca22e3a0e8836fdd8cfac161afe321a7c67d0dde96f9f645ddd759676621 - languageName: node - linkType: hard - -"@ethersproject/constants@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/constants@npm:5.7.0" - dependencies: - "@ethersproject/bignumber": ^5.7.0 - checksum: 6d4b1355747cce837b3e76ec3bde70e4732736f23b04f196f706ebfa5d4d9c2be50904a390d4d40ce77803b98d03d16a9b6898418e04ba63491933ce08c4ba8a - languageName: node - linkType: hard - -"@ethersproject/contracts@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/contracts@npm:5.7.0" - dependencies: - "@ethersproject/abi": ^5.7.0 - "@ethersproject/abstract-provider": ^5.7.0 - "@ethersproject/abstract-signer": ^5.7.0 - "@ethersproject/address": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/constants": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/transactions": ^5.7.0 - checksum: 6ccf1121cba01b31e02f8c507cb971ab6bfed85706484a9ec09878ef1594a62215f43c4fdef8f4a4875b99c4a800bc95e3be69b1803f8ce479e07634b5a740c0 - languageName: node - linkType: hard - -"@ethersproject/hash@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/hash@npm:5.7.0" - dependencies: - "@ethersproject/abstract-signer": ^5.7.0 - "@ethersproject/address": ^5.7.0 - "@ethersproject/base64": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/keccak256": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/strings": ^5.7.0 - checksum: 6e9fa8d14eb08171cd32f17f98cc108ec2aeca74a427655f0d689c550fee0b22a83b3b400fad7fb3f41cf14d4111f87f170aa7905bcbcd1173a55f21b06262ef - languageName: node - linkType: hard - -"@ethersproject/keccak256@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/keccak256@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - js-sha3: 0.8.0 - checksum: ff70950d82203aab29ccda2553422cbac2e7a0c15c986bd20a69b13606ed8bb6e4fdd7b67b8d3b27d4f841e8222cbaccd33ed34be29f866fec7308f96ed244c6 - languageName: node - linkType: hard - -"@ethersproject/logger@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/logger@npm:5.7.0" - checksum: 075ab2f605f1fd0813f2e39c3308f77b44a67732b36e712d9bc085f22a84aac4da4f71b39bee50fe78da3e1c812673fadc41180c9970fe5e486e91ea17befe0d - languageName: node - linkType: hard - -"@ethersproject/networks@npm:^5.7.0": - version: 5.7.1 - resolution: "@ethersproject/networks@npm:5.7.1" - dependencies: - "@ethersproject/logger": ^5.7.0 - checksum: 0339f312304c17d9a0adce550edb825d4d2c8c9468c1634c44172c67a9ed256f594da62c4cda5c3837a0f28b7fabc03aca9b492f68ff1fdad337ee861b27bd5d - languageName: node - linkType: hard - -"@ethersproject/properties@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/properties@npm:5.7.0" - dependencies: - "@ethersproject/logger": ^5.7.0 - checksum: 6ab0ccf0c3aadc9221e0cdc5306ce6cd0df7f89f77d77bccdd1277182c9ead0202cd7521329ba3acde130820bf8af299e17cf567d0d497c736ee918207bbf59f - languageName: node - linkType: hard - -"@ethersproject/providers@npm:^5.7.2": - version: 5.7.2 - resolution: "@ethersproject/providers@npm:5.7.2" - dependencies: - "@ethersproject/abstract-provider": ^5.7.0 - "@ethersproject/abstract-signer": ^5.7.0 - "@ethersproject/address": ^5.7.0 - "@ethersproject/base64": ^5.7.0 - "@ethersproject/basex": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/constants": ^5.7.0 - "@ethersproject/hash": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/networks": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/random": ^5.7.0 - "@ethersproject/rlp": ^5.7.0 - "@ethersproject/sha2": ^5.7.0 - "@ethersproject/strings": ^5.7.0 - "@ethersproject/transactions": ^5.7.0 - "@ethersproject/web": ^5.7.0 - bech32: 1.1.4 - ws: 7.4.6 - checksum: 1754c731a5ca6782ae9677f4a9cd8b6246c4ef21a966c9a01b133750f3c578431ec43ec254e699969c4a0f87e84463ded50f96b415600aabd37d2056aee58c19 - languageName: node - linkType: hard - -"@ethersproject/random@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/random@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - checksum: 017829c91cff6c76470852855108115b0b52c611b6be817ed1948d56ba42d6677803ec2012aa5ae298a7660024156a64c11fcf544e235e239ab3f89f0fff7345 - languageName: node - linkType: hard - -"@ethersproject/rlp@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/rlp@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - checksum: bce165b0f7e68e4d091c9d3cf47b247cac33252df77a095ca4281d32d5eeaaa3695d9bc06b2b057c5015353a68df89f13a4a54a72e888e4beeabbe56b15dda6e - languageName: node - linkType: hard - -"@ethersproject/sha2@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/sha2@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - hash.js: 1.1.7 - checksum: 09321057c022effbff4cc2d9b9558228690b5dd916329d75c4b1ffe32ba3d24b480a367a7cc92d0f0c0b1c896814d03351ae4630e2f1f7160be2bcfbde435dbc - languageName: node - linkType: hard - -"@ethersproject/signing-key@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/signing-key@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - bn.js: ^5.2.1 - elliptic: 6.5.4 - hash.js: 1.1.7 - checksum: 8f8de09b0aac709683bbb49339bc0a4cd2f95598f3546436c65d6f3c3a847ffa98e06d35e9ed2b17d8030bd2f02db9b7bd2e11c5cf8a71aad4537487ab4cf03a - languageName: node - linkType: hard - -"@ethersproject/strings@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/strings@npm:5.7.0" - dependencies: - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/constants": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - checksum: 5ff78693ae3fdf3cf23e1f6dc047a61e44c8197d2408c42719fef8cb7b7b3613a4eec88ac0ed1f9f5558c74fe0de7ae3195a29ca91a239c74b9f444d8e8b50df - languageName: node - linkType: hard - -"@ethersproject/transactions@npm:^5.7.0": - version: 5.7.0 - resolution: "@ethersproject/transactions@npm:5.7.0" - dependencies: - "@ethersproject/address": ^5.7.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/constants": ^5.7.0 - "@ethersproject/keccak256": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/rlp": ^5.7.0 - "@ethersproject/signing-key": ^5.7.0 - checksum: a31b71996d2b283f68486241bff0d3ea3f1ba0e8f1322a8fffc239ccc4f4a7eb2ea9994b8fd2f093283fd75f87bae68171e01b6265261f821369aca319884a79 - languageName: node - linkType: hard - -"@ethersproject/web@npm:^5.7.0": - version: 5.7.1 - resolution: "@ethersproject/web@npm:5.7.1" - dependencies: - "@ethersproject/base64": ^5.7.0 - "@ethersproject/bytes": ^5.7.0 - "@ethersproject/logger": ^5.7.0 - "@ethersproject/properties": ^5.7.0 - "@ethersproject/strings": ^5.7.0 - checksum: 7028c47103f82fd2e2c197ce0eecfacaa9180ffeec7de7845b1f4f9b19d84081b7a48227aaddde05a4aaa526af574a9a0ce01cc0fc75e3e371f84b38b5b16b2b - languageName: node - linkType: hard - "@gar/promisify@npm:^1.1.3": version: 1.1.3 resolution: "@gar/promisify@npm:1.1.3" @@ -1792,9 +1509,6 @@ __metadata: "@babel/plugin-transform-runtime": ^7.5.5 "@babel/preset-env": ^7.5.5 "@babel/runtime": ^7.21.0 - "@ethersproject/bignumber": ^5.7.0 - "@ethersproject/contracts": ^5.7.0 - "@ethersproject/providers": ^5.7.2 "@lavamoat/allow-scripts": ^2.3.1 "@lavamoat/preinstall-always-fail": ^2.0.0 "@metamask/auto-changelog": ^3.4.3 @@ -1802,6 +1516,7 @@ __metadata: "@metamask/safe-event-emitter": ^3.0.0 bn.js: ^5.2.1 deep-equal: ^2.2.0 + ethers: ^6.13.5 ganache: 7.9.2 human-standard-token-abi: ^2.0.0 solc: ^0.4.26 @@ -1896,6 +1611,15 @@ __metadata: languageName: node linkType: hard +"@noble/curves@npm:1.2.0": + version: 1.2.0 + resolution: "@noble/curves@npm:1.2.0" + dependencies: + "@noble/hashes": 1.3.2 + checksum: bb798d7a66d8e43789e93bc3c2ddff91a1e19fdb79a99b86cd98f1e5eff0ee2024a2672902c2576ef3577b6f282f3b5c778bebd55761ddbb30e36bf275e83dd0 + languageName: node + linkType: hard + "@noble/hashes@npm:1.3.1": version: 1.3.1 resolution: "@noble/hashes@npm:1.3.1" @@ -1903,7 +1627,7 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1": +"@noble/hashes@npm:1.3.2, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1": version: 1.3.2 resolution: "@noble/hashes@npm:1.3.2" checksum: fe23536b436539d13f90e4b9be843cc63b1b17666a07634a2b1259dded6f490be3d050249e6af98076ea8f2ea0d56f578773c2197f2aa0eeaa5fba5bc18ba474 @@ -2081,10 +1805,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*": - version: 18.11.13 - resolution: "@types/node@npm:18.11.13" - checksum: b0c1aa3bd2f5df8240e61096a49d6d4be600109b824d23408ec4ba1ec057dc0c60588e09f73b8a60455ad26d367e9c5562fad8403099f885cbc7b4cace83ec4c +"@types/node@npm:*, @types/node@npm:22.7.5": + version: 22.7.5 + resolution: "@types/node@npm:22.7.5" + dependencies: + undici-types: ~6.19.2 + checksum: 1a8bbb504efaffcef7b8491074a428e5c0b5425b0c0ffb13e7262cb8462c275e8cc5eaf90a38d8fbf52a1eeda7c01ab3b940673c43fc2414140779c973e40ec6 languageName: node linkType: hard @@ -2138,6 +1864,13 @@ __metadata: languageName: node linkType: hard +"aes-js@npm:4.0.0-beta.5": + version: 4.0.0-beta.5 + resolution: "aes-js@npm:4.0.0-beta.5" + checksum: cc2ea969d77df939c32057f7e361b6530aa6cb93cb10617a17a45cd164e6d761002f031ff6330af3e67e58b1f0a3a8fd0b63a720afd591a653b02f649470e15b + languageName: node + linkType: hard + "agent-base@npm:6, agent-base@npm:^6.0.2": version: 6.0.2 resolution: "agent-base@npm:6.0.2" @@ -2335,13 +2068,6 @@ __metadata: languageName: node linkType: hard -"bech32@npm:1.1.4": - version: 1.1.4 - resolution: "bech32@npm:1.1.4" - checksum: 0e98db619191548390d6f09ff68b0253ba7ae6a55db93dfdbb070ba234c1fd3308c0606fbcc95fad50437227b10011e2698b89f0181f6e7f845c499bd14d0f4b - languageName: node - linkType: hard - "bin-links@npm:4.0.1": version: 4.0.1 resolution: "bin-links@npm:4.0.1" @@ -2820,21 +2546,6 @@ __metadata: languageName: node linkType: hard -"elliptic@npm:6.5.4": - version: 6.5.4 - resolution: "elliptic@npm:6.5.4" - dependencies: - bn.js: ^4.11.9 - brorand: ^1.1.0 - hash.js: ^1.0.0 - hmac-drbg: ^1.0.1 - inherits: ^2.0.4 - minimalistic-assert: ^1.0.1 - minimalistic-crypto-utils: ^1.0.1 - checksum: d56d21fd04e97869f7ffcc92e18903b9f67f2d4637a23c860492fbbff5a3155fd9ca0184ce0c865dd6eb2487d234ce9551335c021c376cd2d3b7cb749c7d10f4 - languageName: node - linkType: hard - "elliptic@npm:^6.5.4": version: 6.6.1 resolution: "elliptic@npm:6.6.1" @@ -2996,6 +2707,21 @@ __metadata: languageName: node linkType: hard +"ethers@npm:^6.13.5": + version: 6.13.5 + resolution: "ethers@npm:6.13.5" + dependencies: + "@adraffy/ens-normalize": 1.10.1 + "@noble/curves": 1.2.0 + "@noble/hashes": 1.3.2 + "@types/node": 22.7.5 + aes-js: 4.0.0-beta.5 + tslib: 2.7.0 + ws: 8.17.1 + checksum: 25700f75c3854fb5043b72748c7a4198efd15d50b4e66d575e6287aab707e855d9aa5ba342fe3d4a4c7943c84a46bcf3702b0f1da1307a82c40e1d08e86078ba + languageName: node + linkType: hard + "execa@npm:^5.1.1": version: 5.1.1 resolution: "execa@npm:5.1.1" @@ -3396,7 +3122,7 @@ __metadata: languageName: node linkType: hard -"hash.js@npm:1.1.7, hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": +"hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": version: 1.1.7 resolution: "hash.js@npm:1.1.7" dependencies: @@ -3871,13 +3597,6 @@ __metadata: languageName: node linkType: hard -"js-sha3@npm:0.8.0": - version: 0.8.0 - resolution: "js-sha3@npm:0.8.0" - checksum: 75df77c1fc266973f06cce8309ce010e9e9f07ec35ab12022ed29b7f0d9c8757f5a73e1b35aa24840dced0dea7059085aa143d817aea9e188e2a80d569d9adce - languageName: node - linkType: hard - "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -5414,6 +5133,13 @@ __metadata: languageName: node linkType: hard +"tslib@npm:2.7.0": + version: 2.7.0 + resolution: "tslib@npm:2.7.0" + checksum: 1606d5c89f88d466889def78653f3aab0f88692e80bb2066d090ca6112ae250ec1cfa9dbfaab0d17b60da15a4186e8ec4d893801c67896b277c17374e36e1d28 + languageName: node + linkType: hard + "unbox-primitive@npm:^1.0.2": version: 1.0.2 resolution: "unbox-primitive@npm:1.0.2" @@ -5426,6 +5152,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~6.19.2": + version: 6.19.8 + resolution: "undici-types@npm:6.19.8" + checksum: de51f1b447d22571cf155dfe14ff6d12c5bdaec237c765085b439c38ca8518fc360e88c70f99469162bf2e14188a7b0bcb06e1ed2dc031042b984b0bb9544017 + languageName: node + linkType: hard + "unicode-canonical-property-names-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0" @@ -5708,24 +5441,24 @@ __metadata: languageName: node linkType: hard -"ws@npm:7.4.6": - version: 7.4.6 - resolution: "ws@npm:7.4.6" +"ws@npm:8.13.0": + version: 8.13.0 + resolution: "ws@npm:8.13.0" peerDependencies: bufferutil: ^4.0.1 - utf-8-validate: ^5.0.2 + utf-8-validate: ">=5.0.2" peerDependenciesMeta: bufferutil: optional: true utf-8-validate: optional: true - checksum: 3a990b32ed08c72070d5e8913e14dfcd831919205be52a3ff0b4cdd998c8d554f167c9df3841605cde8b11d607768cacab3e823c58c96a5c08c987e093eb767a + checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c languageName: node linkType: hard -"ws@npm:8.13.0": - version: 8.13.0 - resolution: "ws@npm:8.13.0" +"ws@npm:8.17.1": + version: 8.17.1 + resolution: "ws@npm:8.17.1" peerDependencies: bufferutil: ^4.0.1 utf-8-validate: ">=5.0.2" @@ -5734,7 +5467,7 @@ __metadata: optional: true utf-8-validate: optional: true - checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c + checksum: 442badcce1f1178ec87a0b5372ae2e9771e07c4929a3180321901f226127f252441e8689d765aa5cfba5f50ac60dd830954afc5aeae81609aefa11d3ddf5cecf languageName: node linkType: hard From b03c378a0d882aee6e3e42f51d56146c8961bcee Mon Sep 17 00:00:00 2001 From: Salah-Eddine Saakoun Date: Tue, 21 Jan 2025 01:15:21 +0100 Subject: [PATCH 5/5] Revert "chore: use ethers 6" This reverts commit 6d0229b15ea94f995a3b5370127714cc1f7175a8. --- lib/index.js | 5 +- lib/token.js | 15 +- package.json | 8 +- test/helper.js | 25 +- test/integration/human-standard-token.js | 29 +- test/integration/simple-token.js | 18 +- test/integration/token-precision.js | 37 +-- test/unit/index.js | 114 +++---- test/unit/token.js | 44 +-- yarn.lock | 407 +++++++++++++++++++---- 10 files changed, 475 insertions(+), 227 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4342cdd..64c9f7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,6 @@ const { PollingBlockTracker } = require('@metamask/eth-block-tracker') -const { Contract, BrowserProvider } = require('ethers') +const { Web3Provider } = require('@ethersproject/providers') +const { Contract } = require('@ethersproject/contracts') const Token = require('./token') const abi = require('human-standard-token-abi') const SafeEventEmitter = require('@metamask/safe-event-emitter').default @@ -53,7 +54,7 @@ class TokenTracker extends SafeEventEmitter { return new Contract( tokenAddress, abi, - new BrowserProvider(this.provider), + new Web3Provider(this.provider), ) } diff --git a/lib/token.js b/lib/token.js index 813c259..08aff8a 100644 --- a/lib/token.js +++ b/lib/token.js @@ -1,4 +1,5 @@ const BN = require('bn.js') +const { BigNumber } = require("@ethersproject/bignumber") const util = require('./util') /** @@ -22,16 +23,6 @@ function _isInvalidBnInput (input, base) { ) } -/** - * Converts a BigInt value to a BN instance. - * - * @param {BigInt} bigIntValue - The BigInt value to convert. - * @returns {BN} The BN instance representing the BigInt value. - */ -function _bigIntToBN(bigIntValue) { - return new BN(bigIntValue.toString()); -} - class Token { constructor ({ @@ -148,8 +139,8 @@ class Token { if (result) { let val = result - if (typeof result === 'bigint') { - val = _bigIntToBN(result) + if (BigNumber.isBigNumber(result)) { + val = new BN(result.toString()) } this[key] = val return val diff --git a/package.json b/package.json index 054e855..40533e1 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,13 @@ "/lib" ], "dependencies": { + "@ethersproject/bignumber": "^5.7.0", + "@ethersproject/contracts": "^5.7.0", + "@ethersproject/providers": "^5.7.2", "@metamask/eth-block-tracker": "^11.0.3", "@metamask/safe-event-emitter": "^3.0.0", "bn.js": "^5.2.1", "deep-equal": "^2.2.0", - "ethers": "^6.13.5", "human-standard-token-abi": "^2.0.0" }, "devDependencies": { @@ -72,9 +74,7 @@ "ganache>secp256k1": true, "ganache>utf-8-validate": true, "ganache>@trufflesuite/uws-js-unofficial>bufferutil": false, - "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false, - "ethers>ws>bufferutil": false, - "ethers>ws>utf-8-validate": false + "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false } } } diff --git a/test/helper.js b/test/helper.js index d2a611e..dd11cdf 100644 --- a/test/helper.js +++ b/test/helper.js @@ -2,7 +2,8 @@ const assert = require('assert').strict const fs = require('fs') const path = require('path') const ganache = require('ganache') -const { ContractFactory, BrowserProvider } = require('ethers') +const { Web3Provider } = require('@ethersproject/providers') +const { ContractFactory } = require('@ethersproject/contracts') const solc = require('solc') const source = fs.readFileSync(path.resolve(__dirname, 'contracts/Token.sol')).toString(); @@ -12,31 +13,29 @@ const SimpleTokenDeployer = compiled.contracts[':SimpleToken'] const defaultQuantity = '100000000000000000000' // 100 x 10 ^ 18 async function setupSimpleTokenEnvironment ({ qty = defaultQuantity } = {}) { const provider = ganache.provider() - const ethersProvider = new BrowserProvider(provider) + const ethersProvider = new Web3Provider(provider) - const accounts = await ethersProvider.listAccounts() - const addresses = accounts.map(account => account.address) + const addresses = await ethersProvider.listAccounts() assert(addresses.length > 0, 'test network should be initialized with accounts') const owner = addresses[0] const abi = JSON.parse(SimpleTokenDeployer.interface) - const signer = await ethersProvider.getSigner(owner) - const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, signer) + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) - const contract = await factory.deploy(qty) - const { hash } = contract.deploymentTransaction() - assert.ok(hash, 'should have published the token and returned a transaction hash') + const token = await factory.deploy(qty) + const txHash = token.deployTransaction.hash + assert.ok(txHash, 'should have published the token and returned a transaction hash') - await contract.waitForDeployment() - const receipt = await ethersProvider.getTransactionReceipt(hash) + await token.deployed() + const receipt = await ethersProvider.getTransactionReceipt(txHash) const tokenAddress = receipt.contractAddress assert.ok(tokenAddress, 'should have a token address') - const balance = await contract.balanceOf(owner) + const balance = await token.balanceOf(owner) assert.equal(balance.toString(), qty, 'owner should have all') - return { addresses, provider, contract, tokenAddress } + return { addresses, provider, token, tokenAddress } } module.exports = { setupSimpleTokenEnvironment } diff --git a/test/integration/human-standard-token.js b/test/integration/human-standard-token.js index 2ca5332..86f0c87 100644 --- a/test/integration/human-standard-token.js +++ b/test/integration/human-standard-token.js @@ -2,7 +2,8 @@ const fs = require('fs') const path = require('path') const test = require('tape') const ganache = require('ganache') -const { ContractFactory, BrowserProvider } = require('ethers') +const { Web3Provider } = require('@ethersproject/providers') +const { ContractFactory } = require('@ethersproject/contracts') const solc = require('solc') const TokenTracker = require('../../lib') @@ -18,12 +19,12 @@ const EXPECTED_SYMBOL = 'EXP' let addresses = [] let token, tokenAddress, tracked -const ethersProvider = new BrowserProvider(provider) +const ethersProvider = new Web3Provider(provider) test('testrpc has addresses', function (t) { ethersProvider.listAccounts() .then((accounts) => { - addresses = accounts.map(account => account.address) + addresses = accounts t.ok(accounts, 'loaded accounts') t.end() }) @@ -31,25 +32,19 @@ test('testrpc has addresses', function (t) { test('HumanStandardToken publishing token & checking balance', function (t) { const abi = JSON.parse(HumanStandardDeployer.interface) - ethersProvider.getSigner(addresses[0]) - .then((signer) => { - const factory = new ContractFactory(abi, HumanStandardDeployer.bytecode, signer) - return factory.deploy('1000', 'DanBucks', '2', SET_SYMBOL, { - gasLimit: '3000000', - gasPrice: '875000000', - }) + const factory = new ContractFactory(abi, HumanStandardDeployer.bytecode, ethersProvider.getSigner(addresses[0])) + + factory.deploy('1000', 'DanBucks', '2', SET_SYMBOL, { + gasLimit: '3000000', + gasPrice: '875000000', }) .then((contract) => { - t.ok(contract.deploymentTransaction().hash, 'publishes a txHash') - return contract.waitForDeployment() + t.ok(contract.deployTransaction.hash, 'publishes a txHash') + return contract.deployed() }) .then((deployedContract) => { token = deployedContract - return deployedContract.getAddress() - }) - .then((address) => { - t.ok(address, 'should have an address') - tokenAddress = address + tokenAddress = token.address return token.balanceOf(addresses[0]) }) .then((balance) => { diff --git a/test/integration/simple-token.js b/test/integration/simple-token.js index ec6318c..53aa591 100644 --- a/test/integration/simple-token.js +++ b/test/integration/simple-token.js @@ -11,14 +11,14 @@ const less = '10000000000000000000' // 100 x 10 ^ 17 test('StandardToken balances are tracked', function (t) { let addresses - let contract + let token let tokenAddress let tokenTracker let provider setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - contract = environment.contract + token = environment.token tokenAddress = environment.tokenAddress provider = environment.provider tokenTracker = new TokenTracker({ @@ -40,7 +40,7 @@ test('StandardToken balances are tracked', function (t) { .then(() => { tracked = tokenTracker.serialize()[0] t.equal(tracked.balance.toString(10), qty, 'initial balance loaded') - return contract.transfer(addresses[1], less) + return token.transfer(addresses[1], less) }) .then((tx) => { return provider.request({ @@ -79,11 +79,11 @@ test('StandardToken balances are tracked', function (t) { test('StandardToken balance changes are emitted and symbol fetched', function (t) { let addresses - let contract + let token setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - contract = environment.contract + token = environment.token const { provider, tokenAddress } = environment var tokenTracker = new TokenTracker({ userAddress: addresses[0], @@ -114,7 +114,7 @@ test('StandardToken balance changes are emitted and symbol fetched', function (t return new Promise((res, rej) => { setTimeout(res, 200) }) }) .then(() => { - return contract.transfer(addresses[1], '100') + return token.transfer(addresses[1], '100') }) .catch((reason) => { t.notOk(reason, 'should not throw an error') @@ -125,12 +125,12 @@ test('StandardToken balance changes are emitted and symbol fetched', function (t test('StandardToken non balance changes are not emitted', function (t) { let addresses - let contract + let token let tokenTracker setupSimpleTokenEnvironment() .then((environment) => { addresses = environment.addresses - contract = environment.contract + token = environment.token const { provider, tokenAddress } = environment tokenTracker = new TokenTracker({ userAddress: addresses[0], @@ -158,7 +158,7 @@ test('StandardToken non balance changes are not emitted', function (t) { return new Promise((res, rej) => { setTimeout(res, 200) }) }) .then(() => { - return contract.transfer(addresses[1], '0') + return token.transfer(addresses[1], '0') }) .then(() => { var a = new Promise((res, rej) => { setTimeout(res, 200) }) diff --git a/test/integration/token-precision.js b/test/integration/token-precision.js index 65def38..6de229c 100644 --- a/test/integration/token-precision.js +++ b/test/integration/token-precision.js @@ -6,10 +6,11 @@ const solc = require('solc') const TokenTracker = require('../../lib') const BN = require('bn.js') const util = require('../../lib/util') -const { ContractFactory, BrowserProvider } = require('ethers') +const { ContractFactory } = require('@ethersproject/contracts') +const { Web3Provider } = require('@ethersproject/providers') const provider = ganache.provider() -const ethersProvider = new BrowserProvider(provider) +const ethersProvider = new Web3Provider(provider) let count = 0 const source = fs.readFileSync(path.resolve(__dirname, '..', 'contracts/ZeppelinToken.sol')).toString(); @@ -18,12 +19,12 @@ const compiled = solc.compile(source, 1) const SimpleTokenDeployer = compiled.contracts[':TutorialToken'] let addresses = [] -let token, tokenAddress, tracked +let tokenAddress, tracked test('testrpc has addresses', function (t) { ethersProvider.listAccounts() .then((accounts) => { - addresses = accounts.map(account => account.address) + addresses = accounts t.ok(accounts, 'loaded accounts') t.end() }) @@ -97,26 +98,20 @@ function generateTestWithParams(opts = {}) { test(`Generated token precision test ${++count}`, function (t) { const abi = JSON.parse(SimpleTokenDeployer.interface) const owner = addresses[0] - ethersProvider.getSigner(owner).then((signer) => { - const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, signer) + const factory = new ContractFactory(abi, SimpleTokenDeployer.bytecode, ethersProvider.getSigner(owner)) - return factory.deploy(qty, precision, { - gasLimit: 3000000, - gasPrice: 875000000 - }) - }) - .then((contract) => { - t.ok(contract.deploymentTransaction().hash, 'publishes a txHash') - return contract.waitForDeployment() + factory.deploy(qty, precision, { + gasLimit: 3000000, + gasPrice: 875000000 }) - .then((deployedContract) => { - token = deployedContract - return deployedContract.getAddress() + .then((token) => { + t.ok(token.deployTransaction.hash, 'publishes a txHash') + return token.deployed() }) - .then((address) => { - t.ok(address, 'should have an address') - tokenAddress = address - return token.balanceOf(owner) + .then((deployedToken) => { + t.ok(deployedToken.address, 'should have an address') + tokenAddress = deployedToken.address + return deployedToken.balanceOf(owner) }) .then((balance) => { t.equal(balance.toString(), qty, 'owner should have all') diff --git a/test/unit/index.js b/test/unit/index.js index 1afcedd..d945aa6 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -160,7 +160,7 @@ test('tracker with minimal token and one block update with no changes', async fu t.plan(2) let tracker try { - const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -178,7 +178,7 @@ test('tracker with minimal token and one block update with no changes', async fu }) await new Promise((resolve) => setTimeout(() => resolve(), 200)) - await contract.transfer(addresses[1], '0') + await token.transfer(addresses[1], '0') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.equal(updates.length, 1, 'should have one update') @@ -206,7 +206,7 @@ test('tracker with minimal token and two rapid block updates, the first with cha t.plan(2) let tracker try { - const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -225,8 +225,8 @@ test('tracker with minimal token and two rapid block updates, the first with cha await new Promise((resolve) => setTimeout(() => resolve(), 200)) await Promise.all([ - contract.transfer(addresses[1], '110'), - contract.transfer(addresses[1], '0'), + token.transfer(addresses[1], '110'), + token.transfer(addresses[1], '0'), ]) await new Promise((resolve) => setTimeout(() => resolve(), 200)) @@ -263,7 +263,7 @@ test('tracker with minimal token and one block update with changes', async funct t.plan(1) let tracker try { - const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -280,7 +280,7 @@ test('tracker with minimal token and one block update with changes', async funct updates.push(tokens) }) await new Promise((resolve) => setTimeout(() => resolve(), 200)) - await contract.transfer(addresses[1], '110') + await token.transfer(addresses[1], '110') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.deepEqual( @@ -315,7 +315,7 @@ test('tracker with minimal token and one immediate block update with changes', a t.plan(1) let tracker try { - const { addresses, provider, contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, provider, token, tokenAddress } = await setupSimpleTokenEnvironment() tracker = new TokenTracker({ pollingInterval: 20, provider, @@ -331,7 +331,7 @@ test('tracker with minimal token and one immediate block update with changes', a tracker.on('update', (tokens) => { updates.push(tokens) }) - await contract.transfer(addresses[1], '110') + await token.transfer(addresses[1], '110') await new Promise((resolve) => setTimeout(() => resolve(), 200)) t.deepEqual( @@ -362,51 +362,51 @@ test('tracker with minimal token and one immediate block update with changes', a } }) -// test('tracker with broken provider', async function (t) { -// t.plan(1) -// let tracker -// try { -// tracker = new TokenTracker({ -// provider: { -// request: () => { -// throw new Error('Fake provider error') -// } -// }, -// tokens: [{ -// address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', -// }], -// }) -// tracker.on('error', () => { -// t.pass('should emit error event') -// }) -// await new Promise((resolve) => setTimeout(() => resolve(), 200)) -// t.end() -// } finally { -// tracker.stop() -// } -// }) - -// test('tracker with broken provider and includeFailedTokens', async function (t) { -// t.plan(1) -// let tracker -// try { -// tracker = new TokenTracker({ -// provider: { -// request: () => { -// throw new Error('Fake provider error') -// } -// }, -// includeFailedTokens: true, -// tokens: [{ -// address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', -// }], -// }) -// tracker.on('update', () => { -// t.pass('should emit update event') -// }) -// await new Promise((resolve) => setTimeout(() => resolve(), 200)) -// t.end() -// } finally { -// tracker.stop() -// } -// }) +test('tracker with broken provider', async function (t) { + t.plan(1) + let tracker + try { + tracker = new TokenTracker({ + provider: { + request: () => { + throw new Error('Fake provider error') + } + }, + tokens: [{ + address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', + }], + }) + tracker.on('error', () => { + t.pass('should emit error event') + }) + await new Promise((resolve) => setTimeout(() => resolve(), 200)) + t.end() + } finally { + tracker.stop() + } +}) + +test('tracker with broken provider and includeFailedTokens', async function (t) { + t.plan(1) + let tracker + try { + tracker = new TokenTracker({ + provider: { + request: () => { + throw new Error('Fake provider error') + } + }, + includeFailedTokens: true, + tokens: [{ + address: '0xf83c3761a5c0042ab9a694d29520aa9cd6788987', + }], + }) + tracker.on('update', () => { + t.pass('should emit update event') + }) + await new Promise((resolve) => setTimeout(() => resolve(), 200)) + t.end() + } finally { + tracker.stop() + } +}) \ No newline at end of file diff --git a/test/unit/token.js b/test/unit/token.js index 1290d01..728494d 100644 --- a/test/unit/token.js +++ b/test/unit/token.js @@ -17,7 +17,7 @@ test('token with empty options', function (t) { test('token with just contract option', async function (t) { t.plan(1) - const { contract } = await setupSimpleTokenEnvironment() + const { token: contract } = await setupSimpleTokenEnvironment() t.throws(() => (new Token({ contract })), 'should throw if missing owner parameter') t.end() }) @@ -31,7 +31,7 @@ test('token with just owner option', async function (t) { test('token with minimal options', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ contract, owner: addresses[0], @@ -54,7 +54,7 @@ test('token with minimal options', async function (t) { test('token with address', async function (t) { t.plan(1) - const { addresses, contract, tokenAddress } = await setupSimpleTokenEnvironment() + const { addresses, token: contract, tokenAddress } = await setupSimpleTokenEnvironment() const token = new Token({ address: tokenAddress, contract, @@ -68,7 +68,7 @@ test('token with address', async function (t) { test('token with symbol', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ contract, owner: addresses[0], @@ -82,7 +82,7 @@ test('token with symbol', async function (t) { test('token with number balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 10, contract, @@ -96,7 +96,7 @@ test('token with number balance', async function (t) { test('token with unprefixed hex string balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 'f', contract, @@ -110,7 +110,7 @@ test('token with unprefixed hex string balance', async function (t) { test('token with decimal string balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: '10', contract, @@ -124,7 +124,7 @@ test('token with decimal string balance', async function (t) { test('token with BN.js balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: new BN(10), contract, @@ -138,7 +138,7 @@ test('token with BN.js balance', async function (t) { test('token with array balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: [10], contract, @@ -152,7 +152,7 @@ test('token with array balance', async function (t) { test('token with prefixed hex string balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -168,7 +168,7 @@ test('token with prefixed hex string balance', async function (t) { test('token with invalid string balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -184,7 +184,7 @@ test('token with invalid string balance', async function (t) { test('token with zero balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: 0, contract, @@ -198,7 +198,7 @@ test('token with zero balance', async function (t) { test('token with empty string balance', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ balance: '', contract, @@ -212,7 +212,7 @@ test('token with empty string balance', async function (t) { test('token with decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: 10, contract, @@ -226,7 +226,7 @@ test('token with decimals', async function (t) { test('token with string decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: '10', contract, @@ -240,7 +240,7 @@ test('token with string decimals', async function (t) { test('token with unprefixed hex string decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -256,7 +256,7 @@ test('token with unprefixed hex string decimals', async function (t) { test('token with prefixed hex string decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -272,7 +272,7 @@ test('token with prefixed hex string decimals', async function (t) { test('token with invalid string decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() t.throws( () => { new Token({ @@ -288,7 +288,7 @@ test('token with invalid string decimals', async function (t) { test('token with zero decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: 0, contract, @@ -302,7 +302,7 @@ test('token with zero decimals', async function (t) { test('token with empty string decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: '', contract, @@ -316,7 +316,7 @@ test('token with empty string decimals', async function (t) { test('token with BN.js decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: new BN(10), contract, @@ -330,7 +330,7 @@ test('token with BN.js decimals', async function (t) { test('token with array decimals', async function (t) { t.plan(1) - const { addresses, contract } = await setupSimpleTokenEnvironment() + const { addresses, token: contract } = await setupSimpleTokenEnvironment() const token = new Token({ decimals: [10], contract, diff --git a/yarn.lock b/yarn.lock index a314e29..aa63fdf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,13 +5,6 @@ __metadata: version: 6 cacheKey: 8 -"@adraffy/ens-normalize@npm:1.10.1": - version: 1.10.1 - resolution: "@adraffy/ens-normalize@npm:1.10.1" - checksum: 0836f394ea256972ec19a0b5e78cb7f5bcdfd48d8a32c7478afc94dd53ae44c04d1aa2303d7f3077b4f3ac2323b1f557ab9188e8059978748fdcd83e04a80dcc - languageName: node - linkType: hard - "@ampproject/remapping@npm:^2.2.0": version: 2.2.1 resolution: "@ampproject/remapping@npm:2.2.1" @@ -1356,6 +1349,296 @@ __metadata: languageName: node linkType: hard +"@ethersproject/abi@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abi@npm:5.7.0" + dependencies: + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/hash": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: bc6962bb6cb854e4d2a4d65b2c49c716477675b131b1363312234bdbb7e19badb7d9ce66f4ca2a70ae2ea84f7123dbc4e300a1bfe5d58864a7eafabc1466627e + languageName: node + linkType: hard + +"@ethersproject/abstract-provider@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abstract-provider@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/networks": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + "@ethersproject/web": ^5.7.0 + checksum: 74cf4696245cf03bb7cc5b6cbf7b4b89dd9a79a1c4688126d214153a938126d4972d42c93182198653ce1de35f2a2cad68be40337d4774b3698a39b28f0228a8 + languageName: node + linkType: hard + +"@ethersproject/abstract-signer@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/abstract-signer@npm:5.7.0" + dependencies: + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + checksum: a823dac9cfb761e009851050ebebd5b229d1b1cc4a75b125c2da130ff37e8218208f7f9d1386f77407705b889b23d4a230ad67185f8872f083143e0073cbfbe3 + languageName: node + linkType: hard + +"@ethersproject/address@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/address@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + checksum: 64ea5ebea9cc0e845c413e6cb1e54e157dd9fc0dffb98e239d3a3efc8177f2ff798cd4e3206cf3660ee8faeb7bef1a47dc0ebef0d7b132c32e61e550c7d4c843 + languageName: node + linkType: hard + +"@ethersproject/base64@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/base64@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + checksum: 7dd5d734d623582f08f665434f53685041a3d3b334a0e96c0c8afa8bbcaab934d50e5b6b980e826a8fde8d353e0b18f11e61faf17468177274b8e7c69cd9742b + languageName: node + linkType: hard + +"@ethersproject/basex@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/basex@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + checksum: 326087b7e1f3787b5fe6cd1cf2b4b5abfafbc355a45e88e22e5e9d6c845b613ffc5301d629b28d5c4d5e2bfe9ec424e6782c804956dff79be05f0098cb5817de + languageName: node + linkType: hard + +"@ethersproject/bignumber@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/bignumber@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + bn.js: ^5.2.1 + checksum: 8c9a134b76f3feb4ec26a5a27379efb4e156b8fb2de0678a67788a91c7f4e30abe9d948638458e4b20f2e42380da0adacc7c9389d05fce070692edc6ae9b4904 + languageName: node + linkType: hard + +"@ethersproject/bytes@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/bytes@npm:5.7.0" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 66ad365ceaab5da1b23b72225c71dce472cf37737af5118181fa8ab7447d696bea15ca22e3a0e8836fdd8cfac161afe321a7c67d0dde96f9f645ddd759676621 + languageName: node + linkType: hard + +"@ethersproject/constants@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/constants@npm:5.7.0" + dependencies: + "@ethersproject/bignumber": ^5.7.0 + checksum: 6d4b1355747cce837b3e76ec3bde70e4732736f23b04f196f706ebfa5d4d9c2be50904a390d4d40ce77803b98d03d16a9b6898418e04ba63491933ce08c4ba8a + languageName: node + linkType: hard + +"@ethersproject/contracts@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/contracts@npm:5.7.0" + dependencies: + "@ethersproject/abi": ^5.7.0 + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + checksum: 6ccf1121cba01b31e02f8c507cb971ab6bfed85706484a9ec09878ef1594a62215f43c4fdef8f4a4875b99c4a800bc95e3be69b1803f8ce479e07634b5a740c0 + languageName: node + linkType: hard + +"@ethersproject/hash@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/hash@npm:5.7.0" + dependencies: + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/base64": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: 6e9fa8d14eb08171cd32f17f98cc108ec2aeca74a427655f0d689c550fee0b22a83b3b400fad7fb3f41cf14d4111f87f170aa7905bcbcd1173a55f21b06262ef + languageName: node + linkType: hard + +"@ethersproject/keccak256@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/keccak256@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + js-sha3: 0.8.0 + checksum: ff70950d82203aab29ccda2553422cbac2e7a0c15c986bd20a69b13606ed8bb6e4fdd7b67b8d3b27d4f841e8222cbaccd33ed34be29f866fec7308f96ed244c6 + languageName: node + linkType: hard + +"@ethersproject/logger@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/logger@npm:5.7.0" + checksum: 075ab2f605f1fd0813f2e39c3308f77b44a67732b36e712d9bc085f22a84aac4da4f71b39bee50fe78da3e1c812673fadc41180c9970fe5e486e91ea17befe0d + languageName: node + linkType: hard + +"@ethersproject/networks@npm:^5.7.0": + version: 5.7.1 + resolution: "@ethersproject/networks@npm:5.7.1" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 0339f312304c17d9a0adce550edb825d4d2c8c9468c1634c44172c67a9ed256f594da62c4cda5c3837a0f28b7fabc03aca9b492f68ff1fdad337ee861b27bd5d + languageName: node + linkType: hard + +"@ethersproject/properties@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/properties@npm:5.7.0" + dependencies: + "@ethersproject/logger": ^5.7.0 + checksum: 6ab0ccf0c3aadc9221e0cdc5306ce6cd0df7f89f77d77bccdd1277182c9ead0202cd7521329ba3acde130820bf8af299e17cf567d0d497c736ee918207bbf59f + languageName: node + linkType: hard + +"@ethersproject/providers@npm:^5.7.2": + version: 5.7.2 + resolution: "@ethersproject/providers@npm:5.7.2" + dependencies: + "@ethersproject/abstract-provider": ^5.7.0 + "@ethersproject/abstract-signer": ^5.7.0 + "@ethersproject/address": ^5.7.0 + "@ethersproject/base64": ^5.7.0 + "@ethersproject/basex": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/hash": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/networks": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/random": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + "@ethersproject/sha2": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + "@ethersproject/transactions": ^5.7.0 + "@ethersproject/web": ^5.7.0 + bech32: 1.1.4 + ws: 7.4.6 + checksum: 1754c731a5ca6782ae9677f4a9cd8b6246c4ef21a966c9a01b133750f3c578431ec43ec254e699969c4a0f87e84463ded50f96b415600aabd37d2056aee58c19 + languageName: node + linkType: hard + +"@ethersproject/random@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/random@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: 017829c91cff6c76470852855108115b0b52c611b6be817ed1948d56ba42d6677803ec2012aa5ae298a7660024156a64c11fcf544e235e239ab3f89f0fff7345 + languageName: node + linkType: hard + +"@ethersproject/rlp@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/rlp@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: bce165b0f7e68e4d091c9d3cf47b247cac33252df77a095ca4281d32d5eeaaa3695d9bc06b2b057c5015353a68df89f13a4a54a72e888e4beeabbe56b15dda6e + languageName: node + linkType: hard + +"@ethersproject/sha2@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/sha2@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + hash.js: 1.1.7 + checksum: 09321057c022effbff4cc2d9b9558228690b5dd916329d75c4b1ffe32ba3d24b480a367a7cc92d0f0c0b1c896814d03351ae4630e2f1f7160be2bcfbde435dbc + languageName: node + linkType: hard + +"@ethersproject/signing-key@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/signing-key@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + bn.js: ^5.2.1 + elliptic: 6.5.4 + hash.js: 1.1.7 + checksum: 8f8de09b0aac709683bbb49339bc0a4cd2f95598f3546436c65d6f3c3a847ffa98e06d35e9ed2b17d8030bd2f02db9b7bd2e11c5cf8a71aad4537487ab4cf03a + languageName: node + linkType: hard + +"@ethersproject/strings@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/strings@npm:5.7.0" + dependencies: + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + checksum: 5ff78693ae3fdf3cf23e1f6dc047a61e44c8197d2408c42719fef8cb7b7b3613a4eec88ac0ed1f9f5558c74fe0de7ae3195a29ca91a239c74b9f444d8e8b50df + languageName: node + linkType: hard + +"@ethersproject/transactions@npm:^5.7.0": + version: 5.7.0 + resolution: "@ethersproject/transactions@npm:5.7.0" + dependencies: + "@ethersproject/address": ^5.7.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/constants": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/rlp": ^5.7.0 + "@ethersproject/signing-key": ^5.7.0 + checksum: a31b71996d2b283f68486241bff0d3ea3f1ba0e8f1322a8fffc239ccc4f4a7eb2ea9994b8fd2f093283fd75f87bae68171e01b6265261f821369aca319884a79 + languageName: node + linkType: hard + +"@ethersproject/web@npm:^5.7.0": + version: 5.7.1 + resolution: "@ethersproject/web@npm:5.7.1" + dependencies: + "@ethersproject/base64": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/logger": ^5.7.0 + "@ethersproject/properties": ^5.7.0 + "@ethersproject/strings": ^5.7.0 + checksum: 7028c47103f82fd2e2c197ce0eecfacaa9180ffeec7de7845b1f4f9b19d84081b7a48227aaddde05a4aaa526af574a9a0ce01cc0fc75e3e371f84b38b5b16b2b + languageName: node + linkType: hard + "@gar/promisify@npm:^1.1.3": version: 1.1.3 resolution: "@gar/promisify@npm:1.1.3" @@ -1509,6 +1792,9 @@ __metadata: "@babel/plugin-transform-runtime": ^7.5.5 "@babel/preset-env": ^7.5.5 "@babel/runtime": ^7.21.0 + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/contracts": ^5.7.0 + "@ethersproject/providers": ^5.7.2 "@lavamoat/allow-scripts": ^2.3.1 "@lavamoat/preinstall-always-fail": ^2.0.0 "@metamask/auto-changelog": ^3.4.3 @@ -1516,7 +1802,6 @@ __metadata: "@metamask/safe-event-emitter": ^3.0.0 bn.js: ^5.2.1 deep-equal: ^2.2.0 - ethers: ^6.13.5 ganache: 7.9.2 human-standard-token-abi: ^2.0.0 solc: ^0.4.26 @@ -1611,15 +1896,6 @@ __metadata: languageName: node linkType: hard -"@noble/curves@npm:1.2.0": - version: 1.2.0 - resolution: "@noble/curves@npm:1.2.0" - dependencies: - "@noble/hashes": 1.3.2 - checksum: bb798d7a66d8e43789e93bc3c2ddff91a1e19fdb79a99b86cd98f1e5eff0ee2024a2672902c2576ef3577b6f282f3b5c778bebd55761ddbb30e36bf275e83dd0 - languageName: node - linkType: hard - "@noble/hashes@npm:1.3.1": version: 1.3.1 resolution: "@noble/hashes@npm:1.3.1" @@ -1627,7 +1903,7 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:1.3.2, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1": +"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0, @noble/hashes@npm:~1.3.1": version: 1.3.2 resolution: "@noble/hashes@npm:1.3.2" checksum: fe23536b436539d13f90e4b9be843cc63b1b17666a07634a2b1259dded6f490be3d050249e6af98076ea8f2ea0d56f578773c2197f2aa0eeaa5fba5bc18ba474 @@ -1805,12 +2081,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:22.7.5": - version: 22.7.5 - resolution: "@types/node@npm:22.7.5" - dependencies: - undici-types: ~6.19.2 - checksum: 1a8bbb504efaffcef7b8491074a428e5c0b5425b0c0ffb13e7262cb8462c275e8cc5eaf90a38d8fbf52a1eeda7c01ab3b940673c43fc2414140779c973e40ec6 +"@types/node@npm:*": + version: 18.11.13 + resolution: "@types/node@npm:18.11.13" + checksum: b0c1aa3bd2f5df8240e61096a49d6d4be600109b824d23408ec4ba1ec057dc0c60588e09f73b8a60455ad26d367e9c5562fad8403099f885cbc7b4cace83ec4c languageName: node linkType: hard @@ -1864,13 +2138,6 @@ __metadata: languageName: node linkType: hard -"aes-js@npm:4.0.0-beta.5": - version: 4.0.0-beta.5 - resolution: "aes-js@npm:4.0.0-beta.5" - checksum: cc2ea969d77df939c32057f7e361b6530aa6cb93cb10617a17a45cd164e6d761002f031ff6330af3e67e58b1f0a3a8fd0b63a720afd591a653b02f649470e15b - languageName: node - linkType: hard - "agent-base@npm:6, agent-base@npm:^6.0.2": version: 6.0.2 resolution: "agent-base@npm:6.0.2" @@ -2068,6 +2335,13 @@ __metadata: languageName: node linkType: hard +"bech32@npm:1.1.4": + version: 1.1.4 + resolution: "bech32@npm:1.1.4" + checksum: 0e98db619191548390d6f09ff68b0253ba7ae6a55db93dfdbb070ba234c1fd3308c0606fbcc95fad50437227b10011e2698b89f0181f6e7f845c499bd14d0f4b + languageName: node + linkType: hard + "bin-links@npm:4.0.1": version: 4.0.1 resolution: "bin-links@npm:4.0.1" @@ -2546,6 +2820,21 @@ __metadata: languageName: node linkType: hard +"elliptic@npm:6.5.4": + version: 6.5.4 + resolution: "elliptic@npm:6.5.4" + dependencies: + bn.js: ^4.11.9 + brorand: ^1.1.0 + hash.js: ^1.0.0 + hmac-drbg: ^1.0.1 + inherits: ^2.0.4 + minimalistic-assert: ^1.0.1 + minimalistic-crypto-utils: ^1.0.1 + checksum: d56d21fd04e97869f7ffcc92e18903b9f67f2d4637a23c860492fbbff5a3155fd9ca0184ce0c865dd6eb2487d234ce9551335c021c376cd2d3b7cb749c7d10f4 + languageName: node + linkType: hard + "elliptic@npm:^6.5.4": version: 6.6.1 resolution: "elliptic@npm:6.6.1" @@ -2707,21 +2996,6 @@ __metadata: languageName: node linkType: hard -"ethers@npm:^6.13.5": - version: 6.13.5 - resolution: "ethers@npm:6.13.5" - dependencies: - "@adraffy/ens-normalize": 1.10.1 - "@noble/curves": 1.2.0 - "@noble/hashes": 1.3.2 - "@types/node": 22.7.5 - aes-js: 4.0.0-beta.5 - tslib: 2.7.0 - ws: 8.17.1 - checksum: 25700f75c3854fb5043b72748c7a4198efd15d50b4e66d575e6287aab707e855d9aa5ba342fe3d4a4c7943c84a46bcf3702b0f1da1307a82c40e1d08e86078ba - languageName: node - linkType: hard - "execa@npm:^5.1.1": version: 5.1.1 resolution: "execa@npm:5.1.1" @@ -3122,7 +3396,7 @@ __metadata: languageName: node linkType: hard -"hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": +"hash.js@npm:1.1.7, hash.js@npm:^1.0.0, hash.js@npm:^1.0.3": version: 1.1.7 resolution: "hash.js@npm:1.1.7" dependencies: @@ -3597,6 +3871,13 @@ __metadata: languageName: node linkType: hard +"js-sha3@npm:0.8.0": + version: 0.8.0 + resolution: "js-sha3@npm:0.8.0" + checksum: 75df77c1fc266973f06cce8309ce010e9e9f07ec35ab12022ed29b7f0d9c8757f5a73e1b35aa24840dced0dea7059085aa143d817aea9e188e2a80d569d9adce + languageName: node + linkType: hard + "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -5133,13 +5414,6 @@ __metadata: languageName: node linkType: hard -"tslib@npm:2.7.0": - version: 2.7.0 - resolution: "tslib@npm:2.7.0" - checksum: 1606d5c89f88d466889def78653f3aab0f88692e80bb2066d090ca6112ae250ec1cfa9dbfaab0d17b60da15a4186e8ec4d893801c67896b277c17374e36e1d28 - languageName: node - linkType: hard - "unbox-primitive@npm:^1.0.2": version: 1.0.2 resolution: "unbox-primitive@npm:1.0.2" @@ -5152,13 +5426,6 @@ __metadata: languageName: node linkType: hard -"undici-types@npm:~6.19.2": - version: 6.19.8 - resolution: "undici-types@npm:6.19.8" - checksum: de51f1b447d22571cf155dfe14ff6d12c5bdaec237c765085b439c38ca8518fc360e88c70f99469162bf2e14188a7b0bcb06e1ed2dc031042b984b0bb9544017 - languageName: node - linkType: hard - "unicode-canonical-property-names-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-canonical-property-names-ecmascript@npm:2.0.0" @@ -5441,24 +5708,24 @@ __metadata: languageName: node linkType: hard -"ws@npm:8.13.0": - version: 8.13.0 - resolution: "ws@npm:8.13.0" +"ws@npm:7.4.6": + version: 7.4.6 + resolution: "ws@npm:7.4.6" peerDependencies: bufferutil: ^4.0.1 - utf-8-validate: ">=5.0.2" + utf-8-validate: ^5.0.2 peerDependenciesMeta: bufferutil: optional: true utf-8-validate: optional: true - checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c + checksum: 3a990b32ed08c72070d5e8913e14dfcd831919205be52a3ff0b4cdd998c8d554f167c9df3841605cde8b11d607768cacab3e823c58c96a5c08c987e093eb767a languageName: node linkType: hard -"ws@npm:8.17.1": - version: 8.17.1 - resolution: "ws@npm:8.17.1" +"ws@npm:8.13.0": + version: 8.13.0 + resolution: "ws@npm:8.13.0" peerDependencies: bufferutil: ^4.0.1 utf-8-validate: ">=5.0.2" @@ -5467,7 +5734,7 @@ __metadata: optional: true utf-8-validate: optional: true - checksum: 442badcce1f1178ec87a0b5372ae2e9771e07c4929a3180321901f226127f252441e8689d765aa5cfba5f50ac60dd830954afc5aeae81609aefa11d3ddf5cecf + checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c languageName: node linkType: hard