Skip to content

Commit

Permalink
Vin.txid to be decoded in BE order (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored May 19, 2021
1 parent 355a30b commit cfbed46
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export class MockPrevoutProvider implements PrevoutProvider {

static mapPrevout (utxo: any, pubKey: Buffer): Prevout {
return {
// utxo.id from defid is reversed, we uses non reversed order in txid
// TODO(fuxingloh): we need consistency for this. https://github.com/DeFiCh/jellyfish/issues/231
txid: Buffer.from(utxo.txid, 'hex').reverse().toString('hex'),
txid: utxo.txid,
vout: utxo.vout,
value: new BigNumber(utxo.amount),
script: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ it('should craft, sign and broadcast a txn from scratch', async () => {
script: { stack: [] },
sequence: 0xffffffff,
// container.fundAddress returns in BE
txid: Buffer.from(txid, 'hex').reverse().toString('hex')
txid: txid
}
],
vout: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ComposableBuffer deep implementation', () => {
return [
ComposableBuffer.uInt16(() => data.ver, v => data.ver = v),
ComposableBuffer.uInt32(() => data.val, v => data.val = v),
ComposableBuffer.hexLE(8, () => data.hex, v => data.hex = v)
ComposableBuffer.hex(8, () => data.hex, v => data.hex = v)
]
}

Expand Down Expand Up @@ -183,7 +183,7 @@ describe('ComposableBuffer.varUIntArray', () => {
composers (data: VarItem): BufferComposer[] {
return [
ComposableBuffer.uInt16(() => data.val, v => data.val = v),
ComposableBuffer.hexLE(12, () => data.hex, v => data.hex = v)
ComposableBuffer.hex(12, () => data.hex, v => data.hex = v)
]
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('ComposableBuffer.varUIntArray', () => {

expect(() => {
composer.toBuffer(new SmartBuffer())
}).toThrow('ComposableBuffer.hexLE.toBuffer invalid as length != getter().length')
}).toThrow('ComposableBuffer.hex.toBuffer invalid as length != getter().length')
})

it('should fail toBuffer deeply due to value out of range', () => {
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('ComposableBuffer.array', () => {
composers (data: Item): BufferComposer[] {
return [
ComposableBuffer.bigNumberUInt64(() => data.value, v => data.value = v),
ComposableBuffer.hexLE(32, () => data.txid, v => data.txid = v)
ComposableBuffer.hex(32, () => data.txid, v => data.txid = v)
]
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('ComposableBuffer.array', () => {

expect(() => {
composer.toBuffer(new SmartBuffer())
}).toThrow('ComposableBuffer.hexLE.toBuffer invalid as length != getter().length')
}).toThrow('ComposableBuffer.hex.toBuffer invalid as length != getter().length')
})

it('should fail toBuffer deeply due to value out of range', () => {
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('ComposableBuffer.single', () => {
class CSingle extends ComposableBuffer<Single> {
composers (data: Single): BufferComposer[] {
return [
ComposableBuffer.hexLE(16, () => data.id, v => data.id = v),
ComposableBuffer.hex(16, () => data.id, v => data.id = v),
ComposableBuffer.uInt16(() => data.value, v => data.value = v)
]
}
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('ComposableBuffer.single', () => {

expect(() => {
composer.toBuffer(new SmartBuffer())
}).toThrow('ComposableBuffer.hexLE.toBuffer invalid as length != getter().length')
}).toThrow('ComposableBuffer.hex.toBuffer invalid as length != getter().length')
})

it('should fail toBuffer deeply due to value out of range', () => {
Expand All @@ -401,8 +401,8 @@ describe('ComposableBuffer.single', () => {
})
})

describe('ComposableBuffer.hexLE', () => {
const composer = ComposableBuffer.hexLE(16, () => value, (v: string) => value = v)
describe('ComposableBuffer.hex', () => {
const composer = ComposableBuffer.hex(16, () => value, (v: string) => value = v)
const expectedBuffer = Buffer.from('9ea83a5c6579d282d189cc04b8e151ef', 'hex')
let value = ''

Expand Down Expand Up @@ -435,12 +435,12 @@ describe('ComposableBuffer.hexLE', () => {

expect(() => {
composer.toBuffer(new SmartBuffer())
}).toThrow('ComposableBuffer.hexLE.toBuffer invalid as length != getter().length')
}).toThrow('ComposableBuffer.hex.toBuffer invalid as length != getter().length')
})
})

describe('ComposableBuffer.hexBE', () => {
const composer = ComposableBuffer.hexBE(16, () => value, (v: string) => value = v)
const composer = ComposableBuffer.hexBEBufferLE(16, () => value, (v: string) => value = v)
const expectedBuffer = Buffer.from('9ea83a5c6579d282d189cc04b8e151ef', 'hex')
let value = ''

Expand Down Expand Up @@ -473,7 +473,7 @@ describe('ComposableBuffer.hexBE', () => {

expect(() => {
composer.toBuffer(new SmartBuffer())
}).toThrow('ComposableBuffer.hexBE.toBuffer invalid as length != getter().length')
}).toThrow('ComposableBuffer.hexBEBufferLE.toBuffer invalid as length != getter().length')
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/jellyfish-transaction/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('should be able to use DeFiTransactionConstants constants to craft Transactio
stack: []
},
sequence: 0xffffffff,
txid: 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a'
txid: '8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'
}
],
vout: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('CTransaction', () => {
stack: []
},
sequence: 4294967278,
txid: 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f'
txid: '9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'
},
{
index: 1,
script: {
stack: []
},
sequence: 4294967295,
txid: 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a'
txid: '8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'
}
],
vout: [
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('CTransaction', () => {
})

describe('P2SH-P2WPKH (UNSIGNED)', () => {
const hex = '0400000001db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac000008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac0092040000'
const hex = '040000000177541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb0100000000feffffff02b8b4eb0b000000001976a914a457b684d7f0d539a46a45bbc043f35b59d0d96388ac000008af2f000000001976a914fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c88ac0092040000'
const data: Transaction = {
version: 0x00000004,
vin: [
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('CTransaction', () => {
})

describe('P2WSH (UNSIGNED)', () => {
const hex = '0400000002fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e0000000000ffffffff0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f80000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac0000000000'
const hex = '04000000026eb316926b1c5d567cd6f5e6a84fec606fc53d7b474526d1fff3948020c93dfe0000000000fffffffff825690aee1b3dc247da796cacb12687a5e802429fd291cfd63e010f02cf15080000000000ffffffff0100f2052a010000001976a914a30741f8145e5acadf23f751864167f32e0963f788ac0000000000'
const data: Transaction = {
version: 0x00000004,
vin: [
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('CTransaction', () => {
})

describe('P2SH-P2WSH (UNSIGNED)', () => {
const hex = '040000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688ac00c0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac0000000000'
const hex = '04000000016eb98797a21c6c10aa74edf29d618be109f48a8e94c694f3701e08ca691864360100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688ac00c0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac0000000000'
const data: Transaction = {
version: 0x00000004,
vin: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ describe('CTransactionSegWit', () => {
]
},
sequence: 4294967278,
txid: 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f'
txid: '9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'
},
{
index: 1,
script: {
stack: []
},
sequence: 4294967295,
txid: 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a'
txid: '8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'
}
],
vout: [
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('CTransactionSegWit', () => {
]
},
sequence: 4294967294,
txid: 'db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477'
txid: '77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb'
}
],
vout: [
Expand Down Expand Up @@ -236,15 +236,15 @@ describe('CTransactionSegWit', () => {
]
},
sequence: 4294967295,
txid: 'fe3dc9208094f3ffd12645477b3dc56f60ec4fa8e6f5d67c565d1c6b9216b36e'
txid: '6eb316926b1c5d567cd6f5e6a84fec606fc53d7b474526d1fff3948020c93dfe'
},
{
index: 0,
script: {
stack: []
},
sequence: 4294967295,
txid: '0815cf020f013ed6cf91d29f4202e8a58726b1ac6c79da47c23d1bee0a6925f8'
txid: 'f825690aee1b3dc247da796cacb12687a5e802429fd291cfd63e010f02cf1508'
}
],
vout: [
Expand Down Expand Up @@ -307,7 +307,7 @@ describe('CTransactionSegWit', () => {
]
},
sequence: 4294967295,
txid: '36641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e'
txid: '6eb98797a21c6c10aa74edf29d618be109f48a8e94c694f3701e08ca69186436'
}
],
vout: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('CVin', () => {
describe('P2KH (UNSIGNED)', () => {
const hex = 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f0000000000eeffffff'
const data: Vin = {
txid: 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f',
txid: '9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff',
index: 0x00000000,
script: {
stack: []
Expand All @@ -25,7 +25,7 @@ describe('CVin', () => {
describe('P2KH (SIGNED)', () => {
const hex = 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000494830450221008b9d1dc26ba6a9cb62127b02742fa9d754cd3bebf337f7a55d114c8e5cdd30be022040529b194ba3f9281a99f2b1c0a19c0489bc22ede944ccf4ecbab4cc618ef3ed01eeffffff'
const data: Vin = {
txid: 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f',
txid: '9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff',
index: 0x00000000,
script: {
stack: [
Expand All @@ -47,7 +47,7 @@ describe('CVin', () => {
describe('P2WPKH (SEGWIT)', () => {
const hex = 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a0100000000ffffffff'
const data: Vin = {
txid: 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a',
txid: '8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef',
index: 0x00000001,
script: {
stack: []
Expand All @@ -67,7 +67,7 @@ describe('CVin', () => {
describe('P2SH-P2WPKH (UNSIGNED)', () => {
const hex = 'db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a54770100000000feffffff'
const data: Vin = {
txid: 'db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477',
txid: '77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb',
index: 0x00000001,
script: {
stack: []
Expand All @@ -87,7 +87,7 @@ describe('CVin', () => {
describe('P2SH-P2WPKH (SIGNED-SEGWIT)', () => {
const hex = 'db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477010000001716001479091972186c449eb1ded22b78e40d009bdf0089feffffff'
const data: Vin = {
txid: 'db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477',
txid: '77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb',
index: 0x00000001,
script: {
stack: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe('sign single input', () => {
stack: []
},
sequence: 4294967278,
txid: 'fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f'
txid: '9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'
},
{
index: 1,
script: {
stack: []
},
sequence: 4294967295,
txid: 'ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a'
txid: '8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'
}
],
vout: [
Expand Down
Loading

0 comments on commit cfbed46

Please sign in to comment.