MC/website/tests/share-ledger.test.mjs
2026-11-27 23:43:05 +00:00

6 lines
1.3 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {shareLedgerSchema,validateShareClass,validateShareQuantity,validateShareIssuance,SHARE_TRADING_ENABLED} from '../node/share-ledger.mjs';
test('share ledger uses additive class, position and event tables',()=>{assert.equal(shareLedgerSchema.length,3);assert.ok(shareLedgerSchema.every(sql=>sql.startsWith('CREATE TABLE IF NOT EXISTS')));assert.match(shareLedgerSchema[2],/reference_id VARCHAR\(100\) NOT NULL UNIQUE/);});
test('valid share classes have bounded symbol and supply',()=>{assert.deepEqual(validateShareClass({symbol:'CRG',name:' Ordinary ',authorizedShares:10000}),{symbol:'CRG',name:'Ordinary',authorizedShares:10000});assert.throws(()=>validateShareClass({symbol:'<script>',name:'A',authorizedShares:10}),/Invalid/);});
test('share quantities reject negatives, fractions and overflow',()=>{for(const n of [-1,0,1.5,Number.MAX_SAFE_INTEGER+1])assert.throws(()=>validateShareQuantity(n));});
test('issuance never exceeds authorized shares',()=>{assert.equal(validateShareIssuance({authorizedShares:100,issuedShares:60,quantity:40}),100);assert.throws(()=>validateShareIssuance({authorizedShares:100,issuedShares:60,quantity:41}),/exceeds/);});
test('live trading remains disabled',()=>assert.equal(SHARE_TRADING_ENABLED,false));