Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emjshrx committed Apr 12, 2024
1 parent 9a665c5 commit a0e726b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/core/test/fixtures/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const validTransactions = [
script: '76a914c42e7ef92fdb603af844d064faad95db9bcdfd3d88ac',
},
],
inPubkeys: [
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
],
},
},
{
Expand Down Expand Up @@ -54,6 +57,10 @@ export const validTransactions = [
script: 'a9147ccb85f0ab2d599bc17246c98babd5a20b1cdc7687',
},
],
inPubkeys: [
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
null,
],
},
},
{
Expand Down Expand Up @@ -247,6 +254,9 @@ export const validTransactions = [
script: '4effffffff01',
},
],
inPubkeys: [
'02d5ede09a8ae667d0f855ef90325e27f6ce35bbe60a1e6e87af7f5b3c652140fd',
],
},
},
{
Expand Down Expand Up @@ -293,6 +303,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'21038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac',
],
},
},
{
Expand All @@ -319,6 +332,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'21038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2bac',
],
},
},
{
Expand Down Expand Up @@ -368,6 +384,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b',
],
},
},
{
Expand Down Expand Up @@ -468,6 +487,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'3045022100d269531f120f377ed2f94f42bef893ff2fe6544ac97fb477fa291bc6cfb7647e02200983f6a5bbd4ce6cf97f571995634805a7324cc5d8353ed954fa62477b0fcd0901',
],
},
},
{
Expand Down Expand Up @@ -571,6 +593,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b',
],
},
},
{
Expand All @@ -597,6 +622,9 @@ export const validTransactions = [
script: '76a914851a33a5ef0d4279bd5854949174e2c65b1d450088ac',
},
],
inPubkeys: [
'038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b',
],
},
},
{
Expand Down
30 changes: 30 additions & 0 deletions packages/core/test/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,34 @@ describe('Transaction', () => {
expect(transaction.locktime).toBe(tx.raw.locktime);
},
);

const complexTransactions = [
'P2PK',
'P2SH P2PK',
'P2SH P2PKH',
'P2WSH P2PK',
'P2WSH P2PKH',
'P2SH P2WSH P2PKH',
'P2SH P2WSH P2PK',
'Standard transaction (14:2)',
'Multisig',
'P2WSH Multisig',
'P2SH P2WSH Multisig',
'Coinbase transaction w/ witness',
'P2SH Multisig',
'Coinbase transaction',
];

it.each(
validTransactions.filter(
(tx) => !complexTransactions.includes(tx.description),
),
)('gets the Public Key from Inputs of a $description', (tx) => {
const transaction = Transaction.fromHex(tx.hex);
const receivedInPubkeys = tx.raw.ins.map((_, index) => {
const PK = transaction.getPublicKeyFromInput(index);
return PK ? PK?.toString('hex') : PK;
});
expect(receivedInPubkeys).toStrictEqual(tx.raw.inPubkeys);
});
});

0 comments on commit a0e726b

Please sign in to comment.