Skip to content
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

Add tests validating 32 byte chainwork checkpoints can be processed once RSKIP454 is activated #2865

Open
wants to merge 2 commits into
base: use-serializeAndDeserializeCompactV2-in-RepositoryBtcBlockStoreWithCache
Choose a base branch
from

Conversation

nathanieliov
Copy link
Contributor

Description

Add tests validating 32 byte chainwork checkpoints can be processed once RSKIP454 is activated

How Has This Been Tested?

Unit tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)

@nathanieliov nathanieliov requested a review from a team as a code owner November 27, 2024 03:28
Copy link

github-actions bot commented Nov 27, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files


InputStream checkpointsStream = bridgeSupport.getCheckPoints();
CheckpointManager manager = new CheckpointManager(bridgeTestNetConstants.getBtcParams(), checkpointsStream);
long time = bridgeSupport.getActiveFederation().getCreationTime().toEpochMilli() - 604800L; // The magic number is a substraction CheckpointManager does when getting the checkpoints.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
long time = bridgeSupport.getActiveFederation().getCreationTime().toEpochMilli() - 604800L; // The magic number is a substraction CheckpointManager does when getting the checkpoints.
long checkpointManagerSubstraction = 604800L;
long time = bridgeSupport.getActiveFederation().getCreationTime().toEpochMilli() - checkpointManagerSubstraction;

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

@@ -192,17 +199,114 @@ void testInitialChainHeadWithoutBtcCheckpoints() throws Exception {
void testInitialChainHeadWithBtcCheckpoints() throws Exception {
BridgeConstants bridgeTestNetConstants = BridgeTestNetConstants.getInstance();

BridgeSupport bridgeSupport = arrangeBridgeSupport(bridgeTestNetConstants,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add tests for mainnet, wdyt?

Copy link
Contributor Author

@nathanieliov nathanieliov Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one testing testnet. The rest of new tests are for mainnnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

BridgeSupport bridgeSupport = arrangeBridgeSupport(bridgeTestNetConstants,
activationsBeforeForks);

// Force instantiation of blockstore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing exactly what's being said. Check this:

private StoredBlock getBtcBlockchainChainHead() throws IOException, BlockStoreException {

Basically, we are testing how checkpoints are read and then store in the RepositoryBtcBlockStoreWithCache.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my concern is: why is this needed? maybe an explanatory comment to add a bit more context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

"12-byte-chainwork-mix-format.production.checkpoints"
}
)
void testInitialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_before_RSKIP454_ok(
Copy link
Contributor

@julia-zack julia-zack Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void testInitialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_before_RSKIP454_ok(
void initialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_beforeRSKIP454_ok(

no need to add test to name a test i think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assertEquals(checkpoint.getHeight(), bridgeSupport.getBtcBlockchainBestChainHeight());
}

private BridgeSupport arrangeBridgeSupport(BridgeConstants bridgeTestNetConstants,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of this. Can't we set the bridgeSupport in the general setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to build the bridgeSupport using different bridgeConstants and different activations depending on the use case. This is why I don't put it there, but I'm reorganizing the tests, and let's see if you find it easier to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

"12-byte-chainwork-mix-format.production.checkpoints"
}
)
void testInitialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_before_RSKIP454_ok(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add the arrange, act, assert sections as we've been doing? I find the tests a bit hard to follow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Put magical number into meaningful constant variable
- Put assertion blocks into methods with meaningful names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants