Skip to content

Commit

Permalink
Revise BCH VMs and VMB tests, rewrite VMB test tooling for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Sep 17, 2024
1 parent ffad3f6 commit cad78dd
Show file tree
Hide file tree
Showing 1,826 changed files with 274,519 additions and 51,519 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-brooms-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bitauth/libauth': minor
---

Add combinatorial VMB test sets for arithmetic, hashing, and signature checking
5 changes: 5 additions & 0 deletions .changeset/twelve-suns-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bitauth/libauth': patch
---

Refactor BCH VMs for correctness and clarity
5 changes: 5 additions & 0 deletions .changeset/two-peas-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bitauth/libauth': minor
---

Rewrite VMB test tooling for parallel and incremental generation, benchmarking
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"TOALTSTACK",
"tprv",
"tpub",
"trxhzt",
"tsdoc",
"txid",
"TXINPUTCOUNT",
Expand Down Expand Up @@ -221,7 +222,8 @@
"tsconfig.json",
"node_modules/**",
"src/**/*.base64.ts",
"src/**/script_tests.json"
"src/**/script_tests.json",
"src/lib/vmb-tests/generated"
],
"patterns": [
{
Expand Down
16 changes: 16 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
"functional/immutable-data": "off",
"functional/no-return-void": "off"
}
},
{
"files": ["src/lib/vmb-tests/sources/**.ts"],
"rules": {
"import/no-default-export": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": [
{ "allowTypeImports": true, "group": ["../../lib.js"] }
]
}
]
}
}
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ report.*.json
scratch
gitignore.*
*.cpuprofile
.aidigestignore
codebase.md
src/lib/vmb-tests/generated/.vmb-*
src/lib/vmb-tests/generated/**/*bench.csv
src/lib/vmb-tests/generated/bch_chip_*
src/lib/vmb-tests/generated/bch_2026_*

src/lib/bin/**/*.html
src/lib/bin/**/*.js
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ wasm
.pnp.*
package.json
src/lib/address/fixtures/key_io_*.json
src/lib/vm/instruction-sets/xec/fixtures/satoshi-client/*.json
src/lib/vm/instruction-sets/xec/fixtures/satoshi-client/*.json
src/lib/vmb-tests/generated
9 changes: 0 additions & 9 deletions config/.ava.vmb_bench.config.js

This file was deleted.

38 changes: 8 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
"fix": "yarn fix:eslint && yarn fix:prettier",
"fix:prettier": "prettier . --write",
"fix:eslint": "yarn test:eslint --fix",
"gen:vmb_tests": "yarn build && yarn gen:vmb_tests:bch && yarn gen:vmb_tests-prettier",
"gen:vmb_tests-prettier": "prettier 'src/lib/vmb-tests/generated/**/*.json' --write",
"gen:vmb_tests:bch": "node --enable-source-maps 'build/lib/vmb-tests/write-bch-vmb-tests.spec.helper.js' 'src/lib/vmb-tests/generated' && yarn run gen:vmb_tests:bch:reasons",
"gen:vmb_tests:bch:reasons": "node --enable-source-maps 'build/lib/vmb-tests/write-reasons-bch-vmb-tests.spec.helper.js'",
"wallet": "node --enable-source-maps 'build/lib/vmb-tests/run-live-bch-vmb-test.spec.helper.js'",
"gen:schema": "yarn gen:schema:wallet-template && yarn gen:schema:bcmr",
"gen:schema:wallet-template": "ts-json-schema-generator --no-ref-encode --path 'src/lib/engine/types/template-types.ts' --type 'WalletTemplate' > src/lib/schema/wallet-template.schema.json && prettier 'src/lib/schema/wallet-template.schema.json' --write && ajv compile -s src/lib/schema/wallet-template.schema.json --allowUnionTypes -o src/lib/schema/ajv/validate-wallet-template.js && prettier 'src/lib/schema/ajv/validate-wallet-template.js' --write && node -e \"const fs = require('fs'), path = 'src/lib/schema/ajv/validate-wallet-template.js'; fs.writeFileSync(path, fs.readFileSync(path, 'utf8').replace(/'use strict'[\\s\\S]*module.exports.default =/, 'export default'), 'utf8')\"",
Expand All @@ -66,18 +62,19 @@
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
"test:cycles": "madge --circular build/index.js",
"test:unit": "c8 ava",
"test:fast": "echo '\n\nUsage:\n yarn test:fast src/lib/key/bip39.spec.ts # run a single test file \n yarn test:fast --match=\"!*crypto*\" --match=\"!*vmb_tests*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v",
"test:fast": "echo '\n\nUsage:\n yarn test:fast src/lib/key/bip39.spec.ts # run a single test file \n yarn test:fast --match=\"!*crypto*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v",
"test:unit:script_tests": "c8 ava --match='*[script_tests]*' --serial",
"test:unit:vmb_tests": "c8 ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial",
"test:unit:vmb_test": "node --enable-source-maps 'build/lib/vmb-tests/run-bch-vmb-test.spec.helper.js'",
"dev:vmb_tests": "yarn gen:vmb_tests && yarn build:tsc && ava src/lib/vmb-tests/bch-vmb-tests.spec.ts --serial --fail-fast",
"dev:vmb_tests:info": "echo 'example: export FILTER_VMB_TESTS=benchmark; export FILTER_VMB_TEST_VM=2025; yarn dev:vmb_tests && say sucess || say failure",
"bench:vmb_tests": "ava --config config/.ava.vmb_bench.config.js src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts --serial",
"gen:vmb_tests": "node --enable-source-maps 'build/lib/vmb-tests/dev-vmb-tests.spec.helper.js'",
"bench:vmb_tests": "node --enable-source-maps 'build/lib/vmb-tests/dev-vmb-tests.spec.helper.js' -b",
"dev:vmb_tests": "node --enable-source-maps 'build/lib/vmb-tests/dev-vmb-tests.spec.helper.js' -wb",
"dev:vmb_tests:no-bench": "node --enable-source-maps 'build/lib/vmb-tests/dev-vmb-tests.spec.helper.js' -w",
"bench": "yarn build && yarn bench:browser-deps && yarn bench:vmb_tests && yarn bench:test",
"bench:test": "ava --config config/.ava.bench.config.js --serial --timeout=2m 2>&1 | tee bench.log",
"bench:browser-deps": "cpy '.yarn/artifacts/*.js' build/bench",
"watch": "yarn build -w",
"watch:test": "echo '\n\nUsage:\n yarn watch:test src/lib/key/bip39.spec.ts # watch a single test file \n yarn watch:test --match=\"!*crypto*\" --match=\"!*vmb_tests*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v --watch",
"watch:test": "echo '\n\nUsage:\n yarn watch:test src/lib/key/bip39.spec.ts # watch a single test file \n yarn watch:test --match=\"!*crypto*\" # include/exclude tests with names matching pattern(s) \n\n' && ava -v --watch",
"cov": "yarn build && yarn test:unit && yarn cov:html && yarn cov:lcov && open-cli coverage/index.html",
"cov:html": "c8 report --reporter=html",
"cov:lcov": "c8 report --reporter=lcov",
Expand All @@ -88,6 +85,7 @@
"doc:extract": "mkdir -p build/api && api-extractor run --local --typescript-compiler-folder node_modules/typescript",
"doc:generate": "api-documenter markdown -i temp -o build/api/markdown",
"doc:check-api": "api-extractor run --typescript-compiler-folder node_modules/typescript",
"digest": "ai-digest",
"changeset:version": "yarn changeset version && yarn fix:prettier",
"release": "yarn build && yarn changeset publish"
},
Expand Down Expand Up @@ -148,7 +146,6 @@
"files": [
"build",
"!build/.tsbuildinfo",
"!build/**/*.map",
"!**/*.spec.*",
"!**/*.json",
"CHANGELOG.md",
Expand All @@ -167,9 +164,6 @@
"nodeArguments": [
"--experimental-json-modules",
"--experimental-global-webcrypto"
],
"files": [
"!src/lib/vmb-tests/benchmark-bch-vmb-tests.spec.ts"
]
},
"config": {
Expand All @@ -182,27 +176,11 @@
"overrides": [
{
"files": [
"src/lib/vmb-tests/**/*bch-vmb-tests*.ts"
"src/lib/vmb-tests/sources/**/*.ts"
],
"options": {
"printWidth": 400
}
},
{
"files": [
"src/lib/vmb-tests/*bch-vmb-tests*.spec.*ts"
],
"options": {
"printWidth": 80
}
},
{
"files": [
"src/lib/vmb-tests/generated/**/*.json"
],
"options": {
"printWidth": 10000
}
}
]
},
Expand Down
5 changes: 0 additions & 5 deletions src/lib/compiler/compiler-bch/compiler-bch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
},
signedMessages: [],
stack: [],
transactionLengthBytes: 60,
},
{
alternateStack: [],
Expand Down Expand Up @@ -476,7 +475,6 @@ test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
},
signedMessages: [],
stack: [],
transactionLengthBytes: 60,
},
{
alternateStack: [],
Expand Down Expand Up @@ -536,7 +534,6 @@ test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
'0376ea9e36a75d2ecf9c93a0be76885e36f822529db22acfdc761c9b5b4544f5c5',
),
],
transactionLengthBytes: 60,
},
{
alternateStack: [],
Expand Down Expand Up @@ -594,7 +591,6 @@ test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
stack: [
hexToBin('15d16c84669ab46059313bf0747e781f1d13936d'),
],
transactionLengthBytes: 60,
},
{
alternateStack: [],
Expand Down Expand Up @@ -652,7 +648,6 @@ test.failing('[BCH compiler] createCompilerBch: debug', (t) => {
stack: [
hexToBin('15d16c84669ab46059313bf0747e781f1d13936d'),
],
transactionLengthBytes: 60,
},
],
},
Expand Down
11 changes: 11 additions & 0 deletions src/lib/format/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ export const assertSuccess = <T>(
if (typeof result === 'string') throw new Error(`${expectation}${result}`);
return result;
};

export const assertNonNull = <T>(
value: T | null | undefined,
expectation = 'Expected a non-null value, but encountered: ',
) => {
if (value === null || value === undefined) {
// eslint-disable-next-line functional/no-throw-statements
throw new Error(`${expectation}${String(value)}`);
}
return value;
};

Check warning on line 103 in src/lib/format/error.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/format/error.ts#L95-L103

Added lines #L95 - L103 were not covered by tests
Loading

0 comments on commit cad78dd

Please sign in to comment.