Move nonWitnessUtxo cache tests out into own test
This commit is contained in:
parent
75f5e8f03c
commit
0d9fa87943
2 changed files with 31 additions and 11 deletions
9
test/fixtures/psbt.json
vendored
9
test/fixtures/psbt.json
vendored
|
@ -428,5 +428,12 @@
|
||||||
"transaction": "020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000",
|
"transaction": "020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000",
|
||||||
"result": "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAAAAAA="
|
"result": "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAAAAAA="
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"cache": {
|
||||||
|
"nonWitnessUtxo": {
|
||||||
|
"psbt": "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAEER1IhApWDvzmuCmCXR60Zmt3WNPphCFWdbFzTm0whg/GrluB/IQLath/0mhTban0CsM0fu3j8SxgxK1tOVNrk26L7/vU211KuIgYClYO/Oa4KYJdHrRma3dY0+mEIVZ1sXNObTCGD8auW4H8Q2QxqTwAAAIAAAACAAAAAgCIGAtq2H/SaFNtqfQKwzR+7ePxLGDErW05U2uTbovv+9TbXENkMak8AAACAAAAAgAEAAIAAAQEgAMLrCwAAAAAXqRS39fr0Dj1ApaRZsds1NfK3L6kh6IcBBCIAIIwjUxc3Q7WV37Sge3K6jkLjeX2nTof+fZ10l+OyAokDAQVHUiEDCJ3BDHrG21T5EymvYXMz2ziM6tDCMfcjN50bmQMLAtwhAjrdkE89bc9Z3bkGsN7iNSm3/7ntUOXoYVGSaGAiHw5zUq4iBgI63ZBPPW3PWd25BrDe4jUpt/+57VDl6GFRkmhgIh8OcxDZDGpPAAAAgAAAAIADAACAIgYDCJ3BDHrG21T5EymvYXMz2ziM6tDCMfcjN50bmQMLAtwQ2QxqTwAAAIAAAACAAgAAgAAiAgOppMN/WZbTqiXbrGtXCvBlA5RJKUJGCzVHU+2e7KWHcRDZDGpPAAAAgAAAAIAEAACAACICAn9jmXV9Lv9VoTatAsaEsYOLZVbl8bazQoKpS2tQBRCWENkMak8AAACAAAAAgAUAAIAA",
|
||||||
|
"nonWitnessUtxo": "Buffer.from('0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000', 'hex')",
|
||||||
|
"inputIndex": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
test/psbt.js
33
test/psbt.js
|
@ -83,16 +83,6 @@ describe(`Psbt`, () => {
|
||||||
arg.forEach(a => adder(i, a))
|
arg.forEach(a => adder(i, a))
|
||||||
} else {
|
} else {
|
||||||
adder(i, arg)
|
adder(i, arg)
|
||||||
if (attr === 'nonWitnessUtxo') {
|
|
||||||
const first = psbt.inputs[i].nonWitnessUtxo
|
|
||||||
psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[i] = undefined
|
|
||||||
const second = psbt.inputs[i].nonWitnessUtxo
|
|
||||||
psbt.inputs[i].nonWitnessUtxo = Buffer.from([1,2,3])
|
|
||||||
psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[i] = undefined
|
|
||||||
const third = psbt.inputs[i].nonWitnessUtxo
|
|
||||||
assert.ok(first.equals(second))
|
|
||||||
assert.ok(first.equals(third))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,4 +463,27 @@ describe(`Psbt`, () => {
|
||||||
assert.ok(psbt.__CACHE.__TX);
|
assert.ok(psbt.__CACHE.__TX);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('Cache', () => {
|
||||||
|
it('non-witness UTXOs are cached', () => {
|
||||||
|
const f = fixtures.cache.nonWitnessUtxo;
|
||||||
|
const psbt = Psbt.fromBase64(f.psbt)
|
||||||
|
const index = f.inputIndex;
|
||||||
|
|
||||||
|
// Cache is empty
|
||||||
|
assert.strictEqual(psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index], undefined)
|
||||||
|
|
||||||
|
// Cache is populated
|
||||||
|
psbt.addNonWitnessUtxoToInput(index, f.nonWitnessUtxo)
|
||||||
|
const value = psbt.inputs[index].nonWitnessUtxo
|
||||||
|
assert.ok(psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index].equals(value))
|
||||||
|
assert.ok(psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index].equals(f.nonWitnessUtxo))
|
||||||
|
|
||||||
|
// Cache is rebuilt from internal transaction object when cleared
|
||||||
|
psbt.inputs[index].nonWitnessUtxo = Buffer.from([1,2,3])
|
||||||
|
psbt.__CACHE.__NON_WITNESS_UTXO_BUF_CACHE[index] = undefined
|
||||||
|
assert.ok(psbt.inputs[index].nonWitnessUtxo.equals(value))
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue