Unit tests: nonstandard
This commit is contained in:
		
							parent
							
								
									2e893e0aea
								
							
						
					
					
						commit
						da1ad1c316
					
				@ -4,21 +4,37 @@ import { MempoolTransactionExtended } from '../../mempool.interfaces';
 | 
				
			|||||||
const randomTransactions = require('./test-data/transactions-random.json');
 | 
					const randomTransactions = require('./test-data/transactions-random.json');
 | 
				
			||||||
const replacedTransactions = require('./test-data/transactions-replaced.json');
 | 
					const replacedTransactions = require('./test-data/transactions-replaced.json');
 | 
				
			||||||
const rbfTransactions = require('./test-data/transactions-rbfs.json');
 | 
					const rbfTransactions = require('./test-data/transactions-rbfs.json');
 | 
				
			||||||
 | 
					const nonStandardTransactions = require('./test-data/non-standard-txs.json');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('Mempool Utils', () => {
 | 
					describe('Common', () => {
 | 
				
			||||||
  test('should detect RBF transactions with fast method', () => {
 | 
					  describe('RBF', () => {
 | 
				
			||||||
    const newTransactions = rbfTransactions.concat(randomTransactions);
 | 
					    const newTransactions = rbfTransactions.concat(randomTransactions);
 | 
				
			||||||
    const result: { [txid: string]: MempoolTransactionExtended[] } = Common.findRbfTransactions(newTransactions, replacedTransactions);
 | 
					    test('should detect RBF transactions with fast method', () => {
 | 
				
			||||||
    expect(Object.values(result).length).toEqual(2);
 | 
					      const result: { [txid: string]: MempoolTransactionExtended[] } = Common.findRbfTransactions(newTransactions, replacedTransactions);
 | 
				
			||||||
    expect(result).toHaveProperty('7219d95161f3718335991ac6d967d24eedec370908c9879bb1e192e6d797d0a6');
 | 
					      expect(Object.values(result).length).toEqual(2);
 | 
				
			||||||
    expect(result).toHaveProperty('5387881d695d4564d397026dc5f740f816f8390b4b2c5ec8c20309122712a875');
 | 
					      expect(result).toHaveProperty('7219d95161f3718335991ac6d967d24eedec370908c9879bb1e192e6d797d0a6');
 | 
				
			||||||
 | 
					      expect(result).toHaveProperty('5387881d695d4564d397026dc5f740f816f8390b4b2c5ec8c20309122712a875');
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test('should detect RBF transactions with scalable method', () => {
 | 
				
			||||||
 | 
					      const result: { [txid: string]: MempoolTransactionExtended[] } = Common.findRbfTransactions(newTransactions, replacedTransactions, true);
 | 
				
			||||||
 | 
					      expect(Object.values(result).length).toEqual(2);
 | 
				
			||||||
 | 
					      expect(result).toHaveProperty('7219d95161f3718335991ac6d967d24eedec370908c9879bb1e192e6d797d0a6');
 | 
				
			||||||
 | 
					      expect(result).toHaveProperty('5387881d695d4564d397026dc5f740f816f8390b4b2c5ec8c20309122712a875');
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test.only('should detect RBF transactions with scalable method', () => {
 | 
					  describe('Mempool Goggles', () => {
 | 
				
			||||||
    const newTransactions = rbfTransactions.concat(randomTransactions);
 | 
					    test('should detect nonstandard transactions', () => {
 | 
				
			||||||
    const result: { [txid: string]: MempoolTransactionExtended[] } = Common.findRbfTransactions(newTransactions, replacedTransactions, true);
 | 
					      nonStandardTransactions.forEach((tx) => {
 | 
				
			||||||
    expect(Object.values(result).length).toEqual(2);
 | 
					        expect(Common.isNonStandard(tx)).toEqual(true);
 | 
				
			||||||
    expect(result).toHaveProperty('7219d95161f3718335991ac6d967d24eedec370908c9879bb1e192e6d797d0a6');
 | 
					      });
 | 
				
			||||||
    expect(result).toHaveProperty('5387881d695d4564d397026dc5f740f816f8390b4b2c5ec8c20309122712a875');
 | 
					    });
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    test('should not misclassify as nonstandard transactions', () => {
 | 
				
			||||||
 | 
					      randomTransactions.forEach((tx) => {
 | 
				
			||||||
 | 
					        expect(Common.isNonStandard(tx)).toEqual(false);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										52
									
								
								backend/src/__tests__/api/test-data/non-standard-txs.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								backend/src/__tests__/api/test-data/non-standard-txs.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					[
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    "txid": "50136231cb7eeeffb17fc41d1cca213426abe5bf3760e3d6421cad0c0edad367",
 | 
				
			||||||
 | 
					    "version": 1,
 | 
				
			||||||
 | 
					    "locktime": 0,
 | 
				
			||||||
 | 
					    "vin": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "txid": "c7f86fb7b830124057475b282809f3474ef3565daa3de0b599980fb9e84ab019",
 | 
				
			||||||
 | 
					            "vout": 4217,
 | 
				
			||||||
 | 
					            "prevout": {
 | 
				
			||||||
 | 
					                "scriptpubkey": "001466197b5eadd8067ec194a457e1044b6d1fbdd3b3",
 | 
				
			||||||
 | 
					                "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 66197b5eadd8067ec194a457e1044b6d1fbdd3b3",
 | 
				
			||||||
 | 
					                "scriptpubkey_type": "v0_p2wpkh",
 | 
				
			||||||
 | 
					                "scriptpubkey_address": "bc1qvcvhkh4dmqr8asv553t7zpztd50mm5ang4na33",
 | 
				
			||||||
 | 
					                "value": 106
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            "scriptsig": "",
 | 
				
			||||||
 | 
					            "scriptsig_asm": "",
 | 
				
			||||||
 | 
					            "witness": [
 | 
				
			||||||
 | 
					                "3043021f2af6060a142c6cfd7428adad6a50745d2424813d7ced5c0bbcca85e70de1be022021440ca1c8c3ed49ecd1b64dca6911adcd430c5d3dd60d77ffe0072953999f5b01",
 | 
				
			||||||
 | 
					                "02ead5c34e3d2c506574b562f857576e11380b6ba15d9f0ad7b7303fdaa9c1513d"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "is_coinbase": false,
 | 
				
			||||||
 | 
					            "sequence": 4294967295
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "vout": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "scriptpubkey": "6a023a29",
 | 
				
			||||||
 | 
					            "scriptpubkey_asm": "OP_RETURN OP_PUSHBYTES_2 3a29",
 | 
				
			||||||
 | 
					            "scriptpubkey_type": "op_return",
 | 
				
			||||||
 | 
					            "value": 0
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "scriptpubkey": "6a036d7648",
 | 
				
			||||||
 | 
					            "scriptpubkey_asm": "OP_RETURN OP_PUSHBYTES_3 6d7648",
 | 
				
			||||||
 | 
					            "scriptpubkey_type": "op_return",
 | 
				
			||||||
 | 
					            "value": 0
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "size": 186,
 | 
				
			||||||
 | 
					    "weight": 420,
 | 
				
			||||||
 | 
					    "sigops": 1,
 | 
				
			||||||
 | 
					    "fee": 106,
 | 
				
			||||||
 | 
					    "status": {
 | 
				
			||||||
 | 
					        "confirmed": true,
 | 
				
			||||||
 | 
					        "block_height": 836361,
 | 
				
			||||||
 | 
					        "block_hash": "0000000000000000000341cc26cda4af82cd25f7063c448772228cbf2836915b",
 | 
				
			||||||
 | 
					        "block_time": 1711448028
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
@ -273,5 +273,63 @@
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
        "bestDescendant": null,
 | 
					        "bestDescendant": null,
 | 
				
			||||||
        "cpfpChecked": true
 | 
					        "cpfpChecked": true
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        "txid": "20b984492b5264162a4c92c9a34bc7fa08b67d669de7b4c5982ad3cb28aaecf6",
 | 
				
			||||||
 | 
					        "version": 2,
 | 
				
			||||||
 | 
					        "locktime": 0,
 | 
				
			||||||
 | 
					        "vin": [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "txid": "3adda6afd547193793c248e667c2b7dbf26d705003de65e3a25e5be698286aef",
 | 
				
			||||||
 | 
					                "vout": 2,
 | 
				
			||||||
 | 
					                "prevout": {
 | 
				
			||||||
 | 
					                    "scriptpubkey": "0014989cf12774fc705609610c7b9419f2d1c4807644",
 | 
				
			||||||
 | 
					                    "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 989cf12774fc705609610c7b9419f2d1c4807644",
 | 
				
			||||||
 | 
					                    "scriptpubkey_type": "v0_p2wpkh",
 | 
				
			||||||
 | 
					                    "scriptpubkey_address": "bc1qnzw0zfm5l3c9vztpp3aegx0j68zgqajyffr2r6",
 | 
				
			||||||
 | 
					                    "value": 27619
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                "scriptsig": "",
 | 
				
			||||||
 | 
					                "scriptsig_asm": "",
 | 
				
			||||||
 | 
					                "witness": [
 | 
				
			||||||
 | 
					                    "304402205d7f1e0d928982645c2bcc4c730c4545c382d6520c2a14eebc71594702cd06b302200511d452ce51c79017536f50acb115eefe7c04506ad12b9307d2b5d56b999beb01",
 | 
				
			||||||
 | 
					                    "03716cb4f0430fe69c596a12c6680c55803150645989b406772838d548cde7cca5"
 | 
				
			||||||
 | 
					                ],
 | 
				
			||||||
 | 
					                "is_coinbase": false,
 | 
				
			||||||
 | 
					                "sequence": 4294967295
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "vout": [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "scriptpubkey": "6a5d0614c0a2331441",
 | 
				
			||||||
 | 
					                "scriptpubkey_asm": "OP_RETURN OP_PUSHNUM_13 OP_PUSHBYTES_6 14c0a2331441",
 | 
				
			||||||
 | 
					                "scriptpubkey_type": "op_return",
 | 
				
			||||||
 | 
					                "value": 0
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "scriptpubkey": "5114d71c6c3ea7ba7e6ee477a0bfd82c20c78997882c",
 | 
				
			||||||
 | 
					                "scriptpubkey_asm": "OP_PUSHNUM_1 OP_PUSHBYTES_20 d71c6c3ea7ba7e6ee477a0bfd82c20c78997882c",
 | 
				
			||||||
 | 
					                "scriptpubkey_type": "unknown",
 | 
				
			||||||
 | 
					                "scriptpubkey_address": "bc1p6uwxc048hflxaerh5zlastpqc7ye0zpvq7gq2a",
 | 
				
			||||||
 | 
					                "value": 546
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "scriptpubkey": "0014989cf12774fc705609610c7b9419f2d1c4807644",
 | 
				
			||||||
 | 
					                "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 989cf12774fc705609610c7b9419f2d1c4807644",
 | 
				
			||||||
 | 
					                "scriptpubkey_type": "v0_p2wpkh",
 | 
				
			||||||
 | 
					                "scriptpubkey_address": "bc1qnzw0zfm5l3c9vztpp3aegx0j68zgqajyffr2r6",
 | 
				
			||||||
 | 
					                "value": 23073
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "size": 240,
 | 
				
			||||||
 | 
					        "weight": 633,
 | 
				
			||||||
 | 
					        "sigops": 1,
 | 
				
			||||||
 | 
					        "fee": 4000,
 | 
				
			||||||
 | 
					        "status": {
 | 
				
			||||||
 | 
					            "confirmed": true,
 | 
				
			||||||
 | 
					            "block_height": 848136,
 | 
				
			||||||
 | 
					            "block_hash": "00000000000000000002c69c7a3010fcd596c0c7451c23e7cd1f5e19ebf8ee6d",
 | 
				
			||||||
 | 
					            "block_time": 1718517071
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user