-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
537942e
feat: add decodeRawTransaction function
fe783d3
chore: check all the properties of of decoded transation in test
8d4e5c1
chore: add doc for decodeRawTransaction
3f70535
chore: change individual assertion to object assertion for testing
ca79d06
chore: Use proper container for decodeRawTransaction test
DocteurPing 6edd7f0
chore: remove useless waitForWalletMaturity in decodeRawTransaction test
DocteurPing 6308818
chore: fix test name for decoderawtransaction
50c1e3f
chore: remove useless objectContaining for decoderawtransaction test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/jellyfish-api-core/__tests__/category/rawtx/decodeRawTransaction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers/dist/index' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '../../../src' | ||
|
||
describe('poolpair update', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
DocteurPing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForWalletCoinbaseMaturity() | ||
DocteurPing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should decode a witness transaction', async () => { | ||
const encrawtx = '010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000' | ||
const decrawtx = await client.rawtx.decodeRawTransaction(encrawtx, true) | ||
|
||
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 commentThe 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(decrawtx.vout[0].scriptPubKey.asm).toStrictEqual('') | ||
expect(decrawtx.vout[0].scriptPubKey.hex).toStrictEqual('') | ||
expect(decrawtx.vout[0].scriptPubKey.type).toStrictEqual('nonstandard') | ||
}) | ||
|
||
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.txid).toStrictEqual('d006b4ece5d4adbd6f46b3a6f65f4a230caf6c44d8510e4340d0f26b7ceeb44a') | ||
expect(decrawtx.hash).toStrictEqual('d006b4ece5d4adbd6f46b3a6f65f4a230caf6c44d8510e4340d0f26b7ceeb44a') | ||
expect(decrawtx.version).toStrictEqual(1) | ||
expect(decrawtx.size).toStrictEqual(60) | ||
expect(decrawtx.vsize).toStrictEqual(60) | ||
expect(decrawtx.weight).toStrictEqual(240) | ||
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].sequence).toStrictEqual(4294967295) | ||
expect(decrawtx.vout[0].value).toStrictEqual(1) | ||
expect(decrawtx.vout[0].n).toStrictEqual(0) | ||
expect(decrawtx.vout[0].scriptPubKey.asm).toStrictEqual('') | ||
expect(decrawtx.vout[0].scriptPubKey.hex).toStrictEqual('') | ||
expect(decrawtx.vout[0].scriptPubKey.type).toStrictEqual('nonstandard') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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