libitx / txforge

Modern Bitcoin transaction builder, capable of supporting any non-standard and custom script type.
Apache License 2.0
63 stars 21 forks source link

Can't run tests for the library #15

Closed bvqbao closed 2 years ago

bvqbao commented 3 years ago

Hi,

I would like to modify the txforge library but I cannot run any test. Here is the error:

npm run test

> txforge@0.2.5 test /home/baobui/txforge
> mocha "test/**/*.test.js" --require esm

/home/baobui/txforge/test/cast.test.js:1
TypeError: Cannot read property 'OpCode' of undefined
    at Object.<anonymous> (/home/baobui/txforge/test/cast.test.js:8:17)
    at Generator.next (<anonymous>)
    at Object.exports.requireOrImport (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/home/baobui/txforge/node_modules/mocha/lib/cli/run.js:362:11)
    at /home/baobui/txforge/node_modules/yargs/build/index.cjs:443:71
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! txforge@0.2.5 test: `mocha "test/**/*.test.js" --require esm`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the txforge@0.2.5 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/baobui/.npm/_logs/2021-07-06T18_57_31_462Z-debug.log

I tried to run the tests for txforge on both Ubuntu and Windows. Same error!

It seems that there are problems with the bsv library. Is there any special setup that I missed in order to run the tests?

Thanks,

libitx commented 3 years ago

Odd, not come across that before. No setup required other than npm install (or yarn install) to ensure the deps are there. I presume you've done that?

bvqbao commented 3 years ago

Yes. I have done npm install.

git clone ...
cd txforge
npm install
npm run test

Node version: 14.16.1 Npm version: 6.14.12

libitx commented 3 years ago

Can you check in you package-lock file what version of bsv is installed?

In my local repo which works I have version 2.0.4. Try specifying that version in package.json.

tbh I'd be surprised if this is the problem, but it's worth trying to rule it out.

bvqbao commented 3 years ago

package-lock.json says 2.0.10.

The error here seems to be: import bsv from 'bsv'. It doesn't work for some reasons, so bsv is undefined.

VSCode has a following notice: "Could not find a declaration file for module 'bsv'. bsv.cjs.js implicitly has an 'any' type".

Update: I have changed the import line to const bsv = require('bsv'), and the error disappears for cast.test.js (other files still have the error). txforge uses import syntax, so I don't think this is a good fix.

bvqbao commented 3 years ago

Ok. I changed import bsv from 'bsv' to import * as bsv from 'bsv' and it works! Not sure if you are ok with this change? I will submit a pull request if necessary.

Anyway, the main thing is I want to submit a pull request to fix a bug in p2ms.js. So if you are ok with the import changes, I will make two pull requests.

libitx commented 3 years ago

I guess the bsv maintainers have made a change that has removed the global export. This can only be recent - maybe specifically in 2.0.10.

Please dont do a PR for the bsv import as I want to ask them if it is intentional. They'll probably break all my libraries with this change so I would rather they revert the change.

However, happy to see the PR for any p2ms fixes 🙏