-
Notifications
You must be signed in to change notification settings - Fork 266
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
base: use-serializeAndDeserializeCompactV2-in-RepositoryBtcBlockStoreWithCache
Are you sure you want to change the base?
Conversation
…nce RSKIP454 is activated
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
BridgeSupport bridgeSupport = arrangeBridgeSupport(bridgeTestNetConstants, | ||
activationsBeforeForks); | ||
|
||
// Force instantiation of blockstore |
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.
why doing this?
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.
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
.
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.
my concern is: why is this needed? maybe an explanatory comment to add a bit more context
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.
Refactored
assertEquals(checkpoint.getHeight(), bridgeSupport.getBtcBlockchainBestChainHeight()); | ||
} | ||
|
||
private BridgeSupport arrangeBridgeSupport(BridgeConstants bridgeTestNetConstants, |
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.
not a big fan of this. Can't we set the bridgeSupport
in the general setup?
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.
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.
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.
Refactored
"12-byte-chainwork-mix-format.production.checkpoints" | ||
} | ||
) | ||
void testInitialChainHeadWithBtcCheckpoints_whenCheckpointsWith12BytesChainWork_before_RSKIP454_ok( |
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 we add the arrange, act, assert sections as we've been doing? I find the tests a bit hard to follow
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.
Done
- Put magical number into meaningful constant variable - Put assertion blocks into methods with meaningful names
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.
LGTM
|
||
@BeforeEach | ||
void setUpOnEachTest() { | ||
bridgeConstants = new BridgeRegTestConstants(); | ||
bridgeConstants = bridgeRegTestConstants; |
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.
this is weird, can't we use bridgeRegTestConstants directly?
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.
Updated
assertEquals(checkpoint.getHeight(), bridgeSupport.getBtcBlockchainBestChainHeight()); | ||
} | ||
|
||
private void arrangeBridgeSupport() { |
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.
private void arrangeBridgeSupport() { | |
private void arrangeBridgeSupport(bridgeConstants, activations) { |
wdyt? to avoid doing the
bridgeConstants = specificConstants
activations = specificActivations
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.
btw, i'd set the bridgeSupport in the general setup, and create it again when needed in specific tests.
In general we've been trying to avoid using these type of methods
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.
This whole class needs a refactor for the other methods that are not being touched. But this is out of the scope of this task.
Anyway, regarding using this approach for arrangement in a test, I think you may be referencing the name arrangeBridgeSupport,
which could be different. I accept that. But this is the same approach we've been using lately. I got inspired by changes in the svp
project. E.g., https://github.com/rsksmart/rskj/blob/add-federation-context/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java#L1148C18-L1148C49
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.
Added your suggestion
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.
LGTM.
* Time to use in CheckpointManager adjust checkpoint backwards by a week to account for possible clock drift in the block headers. | ||
* For more detail please see {@link CheckpointManager#checkpoint(NetworkParameters, InputStream, co.rsk.bitcoinj.store.BtcBlockStore, long)} | ||
*/ | ||
private static final long checkpointTimeAdjustmentForPossibleCLockDrift = weekInSeconds; |
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.
private static final long checkpointTimeAdjustmentForPossibleCLockDrift = weekInSeconds; | |
private static final long checkpointTimeAdjustmentForPossibleClockDrift = weekInSeconds; |
just a little typo
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.
btw, this variable is just being used here.
I'd remove it and use weekInSeconds directly, and move the explanatory comment to where its being used.
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.
done
@@ -155,88 +174,151 @@ void setUpOnEachTest() { | |||
LockingCapMainNetConstants.getInstance(), | |||
signatureCache | |||
); | |||
|
|||
track = createRepository().startTracking(); | |||
arrangeBridgeSupport(bridgeRegTestConstants, activations); |
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.
i insist, don't do this. we don't want a method for arranging the bridge support, that's why we created the bridge support builder.
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.
btw, let's use mainnet for general setup
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.
Mainnet doesn't work for the rest of the tests. Refactoring this test class is out of the scope.
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.
What's your proposal for avoid recreating the bridge support when we need an specific BridgeSupport on certain test cases?
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.
recreate it inside the test. Do not create an arrangeBridgeSupport method.
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.
Done. Got rid of arrangeBridgeSupport
.
.build(); | ||
// arrange | ||
activations = activationsBeforeForks; | ||
bridgeRegTestConstants = bridgeRegTestConstants; |
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.
?
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.
Updated
activations = activationsBeforeForks; | ||
bridgeRegTestConstants = bridgeRegTestConstants; | ||
arrangeBridgeSupport(bridgeRegTestConstants, activations); |
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.
activations = activationsBeforeForks; | |
bridgeRegTestConstants = bridgeRegTestConstants; | |
arrangeBridgeSupport(bridgeRegTestConstants, activations); | |
arrangeBridgeSupport(bridgeRegTestConstants, activationsBeforeForks); |
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.
Done
69feb2c
to
7db7156
Compare
7db7156
to
57b1a16
Compare
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
Checklist: