From 2501fc92bcd8f2467e715c36b1be554186b35cee Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 4 Jul 2019 13:47:18 +0700 Subject: [PATCH] Test BIP174 creator check test cases --- test/fixtures/psbt.json | 25 +++++++++++++++++++++++++ test/psbt.js | 14 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/test/fixtures/psbt.json b/test/fixtures/psbt.json index d57894a..49d4f1f 100644 --- a/test/fixtures/psbt.json +++ b/test/fixtures/psbt.json @@ -143,6 +143,31 @@ "psbt": "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAEAuwIAAAABqtc5MQGL0l+ErkALaISL4J23BurCrBgpi6vucatlb4sAAAAASEcwRAIgWPb8fGoz4bMVSNSByCbAFb0wE1qtQs1neQ2rZtKtJDsCIEoc7SYExnNbY5PltBaR3XiwDwxZQvufdRhW+qk4FX26Af7///8CgPD6AgAAAAAXqRQPuUY0IWlrgsgzryQceMF9295JNIfQ8gonAQAAABepFCnKdPigj4GZlCgYXJe12FLkBj9hh2UAAAAiAgLath/0mhTban0CsM0fu3j8SxgxK1tOVNrk26L7/vU210gwRQIhAPYQOLMI3B2oZaNIUnRvAVdyk0IIxtJEVDk82ZvfIhd3AiAFbmdaZ1ptCgK4WxTl4pB02KJam1dgvqKBb2YZEKAG6gEBAwQBAAAAAQRHUiEClYO/Oa4KYJdHrRma3dY0+mEIVZ1sXNObTCGD8auW4H8hAtq2H/SaFNtqfQKwzR+7ePxLGDErW05U2uTbovv+9TbXUq4iBgKVg785rgpgl0etGZrd1jT6YQhVnWxc05tMIYPxq5bgfxDZDGpPAAAAgAAAAIAAAACAIgYC2rYf9JoU22p9ArDNH7t4/EsYMStbTlTa5Nui+/71NtcQ2QxqTwAAAIAAAACAAQAAgAABASAAwusLAAAAABepFLf1+vQOPUClpFmx2zU18rcvqSHohyICAjrdkE89bc9Z3bkGsN7iNSm3/7ntUOXoYVGSaGAiHw5zRzBEAiBl9FulmYtZon/+GnvtAWrx8fkNVLOqj3RQql9WolEDvQIgf3JHA60e25ZoCyhLVtT/y4j3+3Weq74IqjDym4UTg9IBAQMEAQAAAAEEIgAgjCNTFzdDtZXftKB7crqOQuN5fadOh/59nXSX47ICiQMBBUdSIQMIncEMesbbVPkTKa9hczPbOIzq0MIx9yM3nRuZAwsC3CECOt2QTz1tz1nduQaw3uI1Kbf/ue1Q5ehhUZJoYCIfDnNSrSIGAjrdkE89bc9Z3bkGsN7iNSm3/7ntUOXoYVGSaGAiHw5zENkMak8AAACAAAAAgAMAAIAiBgMIncEMesbbVPkTKa9hczPbOIzq0MIx9yM3nRuZAwsC3BDZDGpPAAAAgAAAAIACAACAACICA6mkw39ZltOqJdusa1cK8GUDlEkpQkYLNUdT7Z7spYdxENkMak8AAACAAAAAgAQAAIAAIgICf2OZdX0u/1WhNq0CxoSxg4tlVuXxtrNCgqlLa1AFEJYQ2QxqTwAAAIAAAACABQAAgAA=", "inputToCheck": 1 } + ], + "creator": [ + { + "inputs": [ + { + "hash": "75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858", + "index": 0 + }, + { + "hash": "1dea7cd05979072a3578cab271c02244ea8a090bbb46aa680a65ecd027048d83", + "index": 1 + } + ], + "outputs": [ + { + "script": "0014d85c2b71d0060b09c9886aeb815e50991dda124d", + "value": 149990000 + }, + { + "script": "001400aea9a2e5f0f876a588df5546e8742d1d87008f", + "value": 100000000 + } + ], + "result": "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAAAAAA=" + } ] }, "signInput": { diff --git a/test/psbt.js b/test/psbt.js index e99e592..98f407b 100644 --- a/test/psbt.js +++ b/test/psbt.js @@ -33,6 +33,20 @@ describe(`Psbt`, () => { }, {message: f.errorMessage}) }) }) + + fixtures.bip174.creator.forEach(f => { + it('Creates expected PSBT', () => { + const psbt = new Psbt() + for (const input of f.inputs) { + psbt.addInput(input) + } + for (const output of f.outputs) { + const script = Buffer.from(output.script, 'hex'); + psbt.addOutput({...output, script}) + } + assert.strictEqual(psbt.toBase64(), f.result) + }) + }) }) describe('signInput', () => {