benkeen / generatedata

A powerful, feature-rich, random test data generator.
https://generatedata.com
2.21k stars 610 forks source link

New Data Type: Bitcoin address #722

Open benkeen opened 2 years ago

benkeen commented 2 years ago

Suggested by someone at work. Quick & easy addition!

benkeen commented 2 years ago

Not so quick. Logic to generate valid ones is fiddly. Removing from 4.0.12.

benkeen commented 2 years ago

I gave this another stab tonight. No luck yet, but a few notes.

  1. First the rollup build needs to be altered to target IIFE instead of es. This allows generating actual bundles for the worker files rather than just dumb files as now. To this point, none of the Data Types needs importing external libraries other than the worker utils which are injected dynamically, so it hasn't been a problem.

I was able to get it going just fine with IIFE with only a small change to the source generator file: altering export const onmessage to self.onmessage. That then references the top-level WorkerGlobalScope from within the IIFE. That then breaks the tests, but should be easily solveable. Plus TBH the worker-related boilerplate will need to be separated from the actual generation code so down the road when this thing is a node package as well as a web app, the execution code can be called from both contexts.

  1. Bitcoin generation! This was the problem. I was using bitcoinjs-lib and followed their examples, but would consistently get ecc library invalid errors on the ECPairFactory creation step when running a test.

No-one else complains about this. I couldn't reproduce it on their own repo when checking out (node 14 too). I suspect it's something to do with the jest / TS/JS build target... not sure. I did try changing the tsconfig target to ES2020 like in their repo but got the same thing. Need to isolate it in a separate repo & if there's still problems open up a ticket.