-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rawtx): add decodeRawTransaction function #1963
Conversation
Code Climate has analyzed commit 50c1e3f and detected 0 issues on this pull request. View more on Code Climate. |
✅ Deploy Preview for jellyfishsdk ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov ReportBase: 90.62% // Head: 92.13% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1963 +/- ##
==========================================
+ Coverage 90.62% 92.13% +1.51%
==========================================
Files 365 367 +2
Lines 10757 10779 +22
Branches 1378 1377 -1
==========================================
+ Hits 9748 9931 +183
+ Misses 953 810 -143
+ Partials 56 38 -18
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Docker build preview for jellyfish/apps is ready! Built with commit 285b933
You can also get an immutable image with the commit hash
|
it('should decode a witness transaction', async () => { | ||
const encrawtx = '010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000' | ||
const decrawtx = await client.rawtx.decodeRawTransaction(encrawtx, true) | ||
expect(decrawtx.vout[0].value).toStrictEqual(1) | ||
}) | ||
|
||
it('should throw an error when for decode as non-witness a witness transaction', async () => { | ||
const encrawtx = '010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000' | ||
await expect(client.rawtx.decodeRawTransaction(encrawtx, false)).rejects.toThrow(RpcApiError) | ||
}) | ||
|
||
it('should decode a non-witness transaction', async () => { | ||
const encrawtx = '01000000010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f505000000000000000000' | ||
const decrawtx = await client.rawtx.decodeRawTransaction(encrawtx, true) | ||
expect(decrawtx.vout[0].value).toStrictEqual(1) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert everything, you need to assert how each rawtx get decoded into explicitly.
expect(decrawtx.txid).toStrictEqual('d006b4ece5d4adbd6f46b3a6f65f4a230caf6c44d8510e4340d0f26b7ceeb44a') | ||
expect(decrawtx.hash).toStrictEqual('23f0c1f68f0a43bb434494933a5a0f6f9636261f33b036b7700d96e264aceeda') | ||
expect(decrawtx.version).toStrictEqual(1) | ||
expect(decrawtx.size).toStrictEqual(66) | ||
expect(decrawtx.vsize).toStrictEqual(62) | ||
expect(decrawtx.weight).toStrictEqual(246) | ||
expect(decrawtx.locktime).toStrictEqual(0) | ||
expect(decrawtx.vin[0].txid).toStrictEqual('000000000019d6689c085ae165831e934ff763ae46a2a6c17200000000000000') | ||
expect(decrawtx.vin[0].vout).toStrictEqual(0) | ||
expect(decrawtx.vin[0].scriptSig.asm).toStrictEqual('') | ||
expect(decrawtx.vin[0].scriptSig.hex).toStrictEqual('') | ||
expect(decrawtx.vin[0].txinwitness).toStrictEqual(['6161']) | ||
expect(decrawtx.vin[0].sequence).toStrictEqual(4294967295) | ||
expect(decrawtx.vout[0].value).toStrictEqual(1) | ||
expect(decrawtx.vout[0].n).toStrictEqual(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(object).toStrictEqual({
pool: '',
ABC: expect.any(String),
txid: expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
})
Prefer we use an object matcher assertion, we started to deprecate the use of individual assertions.
expect.objectContaining({ | ||
txid: '000000000019d6689c085ae165831e934ff763ae46a2a6c17200000000000000', | ||
vout: 0, | ||
scriptSig: | ||
expect.objectContaining({ | ||
asm: '', | ||
hex: '' | ||
}), | ||
sequence: 4294967295 | ||
}) | ||
], | ||
vout: [ | ||
expect.objectContaining({ | ||
value: 1, | ||
n: 0, | ||
scriptPubKey: | ||
expect.objectContaining({ | ||
asm: '', | ||
hex: '', | ||
type: 'nonstandard' | ||
}) | ||
}) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be explicitly defined instead of expect.objectContaining()
? What was the reason for using expect.objectContaining()
?
packages/jellyfish-api-core/__tests__/category/rawtx/decodeRawTransaction.test.ts
Outdated
Show resolved
Hide resolved
packages/jellyfish-api-core/__tests__/category/rawtx/decodeRawTransaction.test.ts
Show resolved
Hide resolved
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '../../../src' | ||
|
||
describe('poolpair update', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong description
Co-authored-by: Fuxing Loh <[email protected]> Signed-off-by: DrPing <[email protected]>
Co-authored-by: Fuxing Loh <[email protected]> Signed-off-by: DrPing <[email protected]>
What this PR does / why we need it:
This PR adds the function decodeRawTransaction.