-
Notifications
You must be signed in to change notification settings - Fork 123
fix: use burn_block_time in 2.x blocks and block_time after 3.x #2314
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b57d6b
fix: pre nakamoto block time
rafaelcr fd5f543
fix: always use block time
rafaelcr b9c94ca
test: behavior
rafaelcr 5eec64d
test: new suite
rafaelcr 2495537
fix: remove old tests
rafaelcr 1ba41fa
fix: throw when no time is present
rafaelcr 1388279
fix: block time falsy check
rafaelcr 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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,82 @@ | ||
import { ChainID } from '@stacks/transactions'; | ||
import { CoreNodeBlockMessage } from '../../src/event-stream/core-node-message'; | ||
import { parseNewBlockMessage } from '../../src/event-stream/event-server'; | ||
|
||
describe('block time tests', () => { | ||
test('takes block_time from block header', () => { | ||
const block: CoreNodeBlockMessage = { | ||
block_time: 1716238792, | ||
block_height: 1, | ||
block_hash: '0x1234', | ||
index_block_hash: '0x5678', | ||
parent_index_block_hash: '0x9abc', | ||
parent_block_hash: '0x1234', | ||
parent_microblock: '0x1234', | ||
parent_microblock_sequence: 0, | ||
parent_burn_block_hash: '0x1234', | ||
parent_burn_block_height: 0, | ||
parent_burn_block_timestamp: 0, | ||
burn_block_time: 1234567890, | ||
burn_block_hash: '0x1234', | ||
burn_block_height: 1, | ||
miner_txid: '0x1234', | ||
events: [], | ||
transactions: [], | ||
matured_miner_rewards: [], | ||
}; | ||
const { dbData: parsed } = parseNewBlockMessage(ChainID.Mainnet, block, false); | ||
expect(parsed.block.block_time).toEqual(1716238792); // Takes block_time from block header | ||
}); | ||
|
||
test('takes burn_block_time from block header when block_time is not present', () => { | ||
const block: CoreNodeBlockMessage = { | ||
block_time: null, | ||
block_height: 1, | ||
block_hash: '0x1234', | ||
index_block_hash: '0x5678', | ||
parent_index_block_hash: '0x9abc', | ||
parent_block_hash: '0x1234', | ||
parent_microblock: '0x1234', | ||
parent_microblock_sequence: 0, | ||
parent_burn_block_hash: '0x1234', | ||
parent_burn_block_height: 0, | ||
parent_burn_block_timestamp: 0, | ||
burn_block_time: 1234567890, | ||
burn_block_hash: '0x1234', | ||
burn_block_height: 1, | ||
miner_txid: '0x1234', | ||
events: [], | ||
transactions: [], | ||
matured_miner_rewards: [], | ||
}; | ||
const { dbData: parsed } = parseNewBlockMessage(ChainID.Mainnet, block, false); | ||
expect(parsed.block.block_time).toEqual(1234567890); // Takes burn_block_time from block header | ||
}); | ||
|
||
test('throws error if block_time and burn_block_time are not present', () => { | ||
// Use `any` to avoid type errors when setting `block_time` and `burn_block_time` to `null`. | ||
const block: any = { | ||
block_time: null, | ||
burn_block_time: null, | ||
block_height: 1, | ||
block_hash: '0x1234', | ||
index_block_hash: '0x5678', | ||
parent_index_block_hash: '0x9abc', | ||
parent_block_hash: '0x1234', | ||
parent_microblock: '0x1234', | ||
parent_microblock_sequence: 0, | ||
parent_burn_block_hash: '0x1234', | ||
parent_burn_block_height: 0, | ||
parent_burn_block_timestamp: 0, | ||
burn_block_hash: '0x1234', | ||
burn_block_height: 1, | ||
miner_txid: '0x1234', | ||
events: [], | ||
transactions: [], | ||
matured_miner_rewards: [], | ||
}; | ||
expect(() => parseNewBlockMessage(ChainID.Mainnet, block, false)).toThrow( | ||
'Block message has no block_time or burn_block_time' | ||
); | ||
}); | ||
}); |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.