|
| 1 | +import { readBinaryFileAsUint8Array, readTransaction } from '../../testdata/test.helper'; |
| 2 | +import { CBOR } from '../lib/cbor'; |
| 3 | +import { AtomicalParserService } from './atomical-parser.service'; |
| 4 | +import { AtomicalOperation } from './atomical-parser.service.helper'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Real-mainnet coverage for the previously-untested Atomicals operations |
| 8 | + * `ft`, `dmt`, `dat`, `mod`, `sl`. Every fixture is a real on-chain tx |
| 9 | + * confirmed via the live ordpool indexer's ordpool_stats_atomical_op |
| 10 | + * satellite table; the row id where applicable is included in each |
| 11 | + * fixture's comment for cross-reference. |
| 12 | + * |
| 13 | + * Source-of-truth citations are the same as for the splat/split/custom-color |
| 14 | + * spec: atomicals-electrumx@8df2374 `electrumx/lib/util_atomicals.py` |
| 15 | + * (opcode dispatch) and `electrumx/server/block_processor.py` (recorded |
| 16 | + * labels). See atomical-parser.service.helper.ts for the full mapping. |
| 17 | + */ |
| 18 | + |
| 19 | +// dmt (distributed mint claim of an existing dft): the workhorse of |
| 20 | +// Atomicals -- 88% of all atomicals txs in our index. This is an early |
| 21 | +// claim of the "atom" ticker, block 808513. |
| 22 | +const DMT_ATOM_TXID = '5390e86df98982122175e18a7f24a1618d14e50e0b2242c7ca2c27730ffad700'; |
| 23 | + |
| 24 | +// ft (direct fungible-token mint with full supply to creator). Block 823349, |
| 25 | +// "coinbase" ticker; payload includes substantial `meta` (name, description, |
| 26 | +// legal terms). |
| 27 | +const FT_COINBASE_TXID = '99393a0d4e6dfce569593cc85a7313277a71045adca84f0fb1c9a3c91d5eefd1'; |
| 28 | + |
| 29 | +// dat (standalone on-chain data). Block 813535, payload carries a 144x144 |
| 30 | +// PNG attached via the {filename: bytes} CBOR shape. |
| 31 | +const DAT_PNG_TXID = 'b8a729cae5d63e512fc8dee2a1419babb27de6927ba45e126023055c672d42d2'; |
| 32 | + |
| 33 | +// mod (modify state on an existing atomical). Block 808768, sets |
| 34 | +// /subrealms minting rules with an attached sample-rules.json file. |
| 35 | +const MOD_SUBREALM_RULES_TXID = 'd6928b9db3fc5128e9bb78079761eb927e4a7ed9f888c54958e8cbde21e1d38f'; |
| 36 | + |
| 37 | +// sl (seal an atomical, locking it from further changes). Block 818965. |
| 38 | +// Payload is just `args` -- no rules or data attached because the seal is |
| 39 | +// itself the entire effect. |
| 40 | +const SL_TXID = '916a1cfdeb0aaae31a42f3ae3c6823977300881b2ecfb284638a2f89edee4f86'; |
| 41 | + |
| 42 | +describe('AtomicalParserService — ft / dmt / dat / mod / sl', () => { |
| 43 | + |
| 44 | + describe('dmt (distributed mint)', () => { |
| 45 | + it('parses an "atom" ticker dmt claim with bitwork-mined args', () => { |
| 46 | + const tx = readTransaction(DMT_ATOM_TXID); |
| 47 | + |
| 48 | + const parsed = AtomicalParserService.parse(tx); |
| 49 | + |
| 50 | + expect(parsed).not.toBeNull(); |
| 51 | + expect(parsed!.operation).toBe<AtomicalOperation>('dmt'); |
| 52 | + |
| 53 | + const payload = parsed!.getPayloadRaw(); |
| 54 | + expect(payload.length).toBe(59); |
| 55 | + |
| 56 | + // dmt payload always has an `args` map with the bitwork-mined fields |
| 57 | + // and the target ticker. No file attachment, no `meta`. |
| 58 | + expect(CBOR.decode(payload)).toEqual({ |
| 59 | + args: { |
| 60 | + bitworkc: '1618', |
| 61 | + mint_ticker: 'atom', |
| 62 | + nonce: 5446138, |
| 63 | + time: 1695180453, |
| 64 | + }, |
| 65 | + }); |
| 66 | + |
| 67 | + expect(parsed!.getArgs()).toEqual({ |
| 68 | + bitworkc: '1618', |
| 69 | + mint_ticker: 'atom', |
| 70 | + nonce: 5446138, |
| 71 | + time: 1695180453, |
| 72 | + }); |
| 73 | + expect(parsed!.getFiles()).toEqual([]); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + describe('ft (direct fungible-token mint)', () => { |
| 78 | + it('parses the "coinbase" ft mint with full meta block', () => { |
| 79 | + const tx = readTransaction(FT_COINBASE_TXID); |
| 80 | + |
| 81 | + const parsed = AtomicalParserService.parse(tx); |
| 82 | + |
| 83 | + expect(parsed).not.toBeNull(); |
| 84 | + expect(parsed!.operation).toBe<AtomicalOperation>('ft'); |
| 85 | + |
| 86 | + const payload = parsed!.getPayloadRaw(); |
| 87 | + expect(payload.length).toBe(1342); |
| 88 | + |
| 89 | + // ft mints carry args + a meta object. Args mirror the dft/dmt shape |
| 90 | + // (bitworkc, time, nonce, request_ticker). meta is free-form metadata |
| 91 | + // -- name, description, legal terms etc. Assert the args exactly; |
| 92 | + // assert key invariants on meta without pinning the full text (it |
| 93 | + // can run to thousands of bytes and is not the parser's concern). |
| 94 | + expect(parsed!.getArgs()).toEqual({ |
| 95 | + bitworkc: '0000', |
| 96 | + nonce: 598543, |
| 97 | + request_ticker: 'coinbase', |
| 98 | + time: 1703818220, |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + describe('dat (standalone data)', () => { |
| 104 | + it('parses a dat tx with a 144x144 PNG file attachment', () => { |
| 105 | + const tx = readTransaction(DAT_PNG_TXID); |
| 106 | + |
| 107 | + const parsed = AtomicalParserService.parse(tx); |
| 108 | + |
| 109 | + expect(parsed).not.toBeNull(); |
| 110 | + expect(parsed!.operation).toBe<AtomicalOperation>('dat'); |
| 111 | + |
| 112 | + const payload = parsed!.getPayloadRaw(); |
| 113 | + expect(payload.length).toBe(4805); |
| 114 | + |
| 115 | + // dat with no `args` map -- the entire payload is the {filename: bytes} |
| 116 | + // attachment. The file in this fixture decodes as a 144x144 PNG. |
| 117 | + const files = parsed!.getFiles(); |
| 118 | + expect(files.length).toBe(1); |
| 119 | + expect(files[0].name).toBe('.\\image.png'); |
| 120 | + expect(files[0].contentType).toBe('image/png'); |
| 121 | + expect(files[0].data.length).toBe(4789); |
| 122 | + |
| 123 | + // PNG signature (8 bytes) + IHDR chunk header. Width and height live |
| 124 | + // at byte offsets 16-19 and 20-23 respectively. |
| 125 | + const dv = new DataView(files[0].data.buffer, files[0].data.byteOffset, files[0].data.byteLength); |
| 126 | + expect(dv.getUint32(0)).toBe(0x89504e47); // PNG magic |
| 127 | + expect(dv.getUint32(4)).toBe(0x0d0a1a0a); // PNG signature continuation |
| 128 | + expect(dv.getUint32(16)).toBe(144); // width |
| 129 | + expect(dv.getUint32(20)).toBe(144); // height |
| 130 | + |
| 131 | + // Byte-for-byte parity with the reference file extracted on first run. |
| 132 | + const expected = readBinaryFileAsUint8Array('atomical_dat_b8a729ca_image.png'); |
| 133 | + expect(files[0].data).toEqual(expected); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + describe('mod (modify state)', () => { |
| 138 | + it('parses a mod tx that sets /subrealms minting rules', () => { |
| 139 | + const tx = readTransaction(MOD_SUBREALM_RULES_TXID); |
| 140 | + |
| 141 | + const parsed = AtomicalParserService.parse(tx); |
| 142 | + |
| 143 | + expect(parsed).not.toBeNull(); |
| 144 | + expect(parsed!.operation).toBe<AtomicalOperation>('mod'); |
| 145 | + |
| 146 | + const payload = parsed!.getPayloadRaw(); |
| 147 | + expect(payload.length).toBe(425); |
| 148 | + |
| 149 | + // mod payload here has no top-level `args` (so getArgs returns null); |
| 150 | + // instead it carries `$path: "/subrealms"`, a `rules` array, and an |
| 151 | + // attached sample-rules.json file demonstrating the rule shape. |
| 152 | + const files = parsed!.getFiles(); |
| 153 | + expect(files.length).toBe(1); |
| 154 | + expect(files[0].name).toBe('.\\sample-rules.json'); |
| 155 | + expect(files[0].contentType).toBe('application/json; charset=utf-8'); |
| 156 | + expect(files[0].data.length).toBe(244); |
| 157 | + |
| 158 | + const fileText = new TextDecoder().decode(files[0].data); |
| 159 | + const parsedFile = JSON.parse(fileText); |
| 160 | + expect(parsedFile).toEqual({ |
| 161 | + $path: '/subrealms', |
| 162 | + rules: [ |
| 163 | + { |
| 164 | + p: '[a-z0-9]{4, 63}', |
| 165 | + o: { |
| 166 | + '51208e390be104ac99a048dbdd9faf86afd8e4599a55f9a40884eb96416e2340a9f0': 1, |
| 167 | + }, |
| 168 | + }, |
| 169 | + ], |
| 170 | + }); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + describe('sl (seal)', () => { |
| 175 | + it('parses a seal tx with bitwork-mined args and no payload extras', () => { |
| 176 | + const tx = readTransaction(SL_TXID); |
| 177 | + |
| 178 | + const parsed = AtomicalParserService.parse(tx); |
| 179 | + |
| 180 | + expect(parsed).not.toBeNull(); |
| 181 | + expect(parsed!.operation).toBe<AtomicalOperation>('sl'); |
| 182 | + |
| 183 | + const payload = parsed!.getPayloadRaw(); |
| 184 | + expect(payload.length).toBe(39); |
| 185 | + |
| 186 | + // sl is the simplest "modify" op -- the seal action is the entire |
| 187 | + // effect, no rules or data needed. Payload is just `args` with the |
| 188 | + // bitwork-mined fields. |
| 189 | + expect(CBOR.decode(payload)).toEqual({ |
| 190 | + args: { |
| 191 | + bitworkc: '1', |
| 192 | + nonce: 3326816, |
| 193 | + time: 1701242965, |
| 194 | + }, |
| 195 | + }); |
| 196 | + |
| 197 | + expect(parsed!.getArgs()).toEqual({ |
| 198 | + bitworkc: '1', |
| 199 | + nonce: 3326816, |
| 200 | + time: 1701242965, |
| 201 | + }); |
| 202 | + expect(parsed!.getFiles()).toEqual([]); |
| 203 | + }); |
| 204 | + }); |
| 205 | +}); |
0 commit comments