Skip to content

Commit

Permalink
fix NULL comparison is query
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Jan 31, 2024
1 parent 5aac91b commit 35913bc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> {
r"
SELECT COALESCE(MIN(block_height), 0), COALESCE(MAX(block_height), 0)
FROM ml_blocks
WHERE block_timestamp BETWEEN $1 AND $2 AND block_height != NULL
WHERE block_timestamp BETWEEN $1 AND $2 AND block_height IS NOT NULL
;",
&[&from, &to],
)
Expand Down
62 changes: 61 additions & 1 deletion api-server/storage-test-suite/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ where
// Create a test framework and blocks

let genesis_id = chain_config.genesis_block_id();
test_framework.create_chain(&genesis_id, 10, &mut rng).unwrap();
let num_blocks = rng.gen_range(10..20);
test_framework.create_chain(&genesis_id, num_blocks, &mut rng).unwrap();

let block_id1 =
test_framework.block_id(1).classify(&chain_config).chain_block_id().unwrap();
Expand Down Expand Up @@ -155,6 +156,65 @@ where
assert_eq!(block.unwrap(), block1);
}

{
for block_height in 1..num_blocks {
let block_height = block_height as u64;
let block_id = test_framework
.block_id(block_height)
.classify(&chain_config)
.chain_block_id()
.unwrap();
let block = test_framework.block(block_id);
db_tx
.set_mainchain_block(block_id, BlockHeight::new(block_height), &block)
.await
.unwrap();
db_tx
.set_block_aux_data(
block_id,
&BlockAuxData::new(
block_id,
BlockHeight::new(block_height),
block.timestamp(),
),
)
.await
.unwrap();
}

let random_height = rng.gen_range(1..3);
let block_id = test_framework
.block_id(random_height)
.classify(&chain_config)
.chain_block_id()
.unwrap();
let block1 = test_framework.block(block_id);
let random_height2 = rng.gen_range(3..10);
let block_id2 = test_framework
.block_id(random_height2)
.classify(&chain_config)
.chain_block_id()
.unwrap();
let block2 = test_framework.block(block_id2);

let block1_timestamp = block1.timestamp();
let block2_timestamp = block2.timestamp();

let (h1, h2) = db_tx
.get_block_range_from_time_range((block1_timestamp, block2_timestamp))
.await
.unwrap();

assert_eq!(h1, BlockHeight::new(random_height));
assert_eq!(h2, BlockHeight::new(random_height2));

// delete the main chain block
db_tx
.del_main_chain_blocks_above_height(block_height.prev_height().unwrap())
.await
.unwrap();
}

db_tx.commit().await.unwrap();

{
Expand Down
2 changes: 2 additions & 0 deletions chainstate/test-framework/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ impl TestFramework {
let mut prev_block_id = *parent_block;
let result = || -> Result<Vec<Id<GenBlock>>, ChainstateError> {
let mut ids = Vec::new();
let target_block_time = self.chain_config().target_block_spacing();
for _ in 0..blocks_count {
self.progress_time_seconds_since_epoch(target_block_time.as_secs());
let block = self
.make_block_builder()
.add_test_transaction_with_parent(prev_block_id, rng)
Expand Down

0 comments on commit 35913bc

Please sign in to comment.