-
Notifications
You must be signed in to change notification settings - Fork 267
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
Create Federation Change Integration Test With Migration Phase #2935
base: fix/powpeg-migration-tests-common-path
Are you sure you want to change the base?
Create Federation Change Integration Test With Migration Phase #2935
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
…hase of a federation change
9e7d495
to
0813889
Compare
for (PegoutsWaitingForConfirmations.Entry pegoutEntry : bridgeStorageProvider.getPegoutsWaitingForConfirmations().getEntries()) { | ||
var pegoutBtcTransaction = pegoutEntry.getBtcTransaction(); | ||
for (TransactionInput input : pegoutBtcTransaction.getInputs()) { | ||
// Each input should contain the right scriptsig |
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.
// Each input should contain the right scriptsig | |
// Each input should contain the right scriptSig |
var retiringFederation = federationStorageProvider.getOldFederation( | ||
BRIDGE_CONSTANTS.getFederationConstants(), activations); | ||
|
||
for (PegoutsWaitingForConfirmations.Entry pegoutEntry : bridgeStorageProvider.getPegoutsWaitingForConfirmations().getEntries()) { |
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 sure about this. I think we should assert against constant values. I mean, for example, based on the initial conditions of the test, we should know the number of migration pegouts that should be created and assert that that number of pegouts is precisely what gets created. Then, check each one was created as expected. Wdyt?
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.
The UTXOs for the original federation are randomly generated. So the size may vary per test. It was already done in the legacy tests here: https://github.com/rsksmart/rskj/blob/feature/powpeg_validation_protocol-phase4/rskj-core/src/test/java/co/rsk/peg/federation/PowpegMigrationTest.java
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.
We've been removing/getting away from random behavior from tests. I think, we should discuss if we should keep this being random or make it deterministic.
Quality Gate passedIssues Measures |
assertNull(bridgeSupport.getRetiringFederationAddress()); | ||
} | ||
|
||
private void assertLastRetiredFederationP2SHMatchesWithOriginalFederation(FederationType federationType, Federation originalFederation, ActivationConfig.ForBlock 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.
private void assertLastRetiredFederationP2SHMatchesWithOriginalFederation(FederationType federationType, Federation originalFederation, ActivationConfig.ForBlock activations) { | |
private void assertLastRetiredFederationP2SHScriptMatchesWithOriginalFederationOne(FederationType federationType, Federation originalFederation, ActivationConfig.ForBlock activations) { |
wdyt?
@@ -414,8 +556,130 @@ private void assertNewAndOldFederationsHaveExpectedAddress( | |||
assertEquals(expectedOldFederationAddress, bridgeSupport.getRetiringFederationAddress()); | |||
} | |||
|
|||
private void assertFundsWereNotMigrated() throws Exception { | |||
private void assertMigrationHasNotStarted() throws Exception { |
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 think this method is missing some assertion to match what the method's name means about what it is doing. I think, to assert the migration has not started, it should check:
- Current block is behind
fedActivationAge + fundsMigrationAgeBegin
- No existing retiring fed utxos has been transferred to the new fed. For this, it should check retiring fed utxos still the same, and there is no active fed utxo.
Wdyt?
var activations = ActivationConfigsForTest.all().forBlock(0); | ||
setUpFederationChange(activations); | ||
// Create a default original federation using the list of UTXOs | ||
var originalFederation = createOriginalFederation( | ||
FederationType.P2SH_ERP, ORIGINAL_FEDERATION_KEYS, activations); | ||
var originalUTXOs = federationStorageProvider.getNewFederationBtcUTXOs( | ||
BRIDGE_CONSTANTS.getBtcParams(), activations); | ||
|
||
// Act & Assert | ||
|
||
// Create pending federation using the new federation keys | ||
var newFederation = createPendingFederation(NEW_FEDERATION_KEYS, activations); | ||
commitPendingFederation(); | ||
// Since Lovell is activated we will commit the proposed federation | ||
commitProposedFederation(activations); | ||
// Move blockchain until the activation phase | ||
activateNewFederation(activations); | ||
|
||
assertUTXOsReferenceMovedFromNewToOldFederation( | ||
originalUTXOs, activations); | ||
assertNewAndOldFederationsHaveExpectedAddress( | ||
newFederation.getAddress(), originalFederation.getAddress()); | ||
assertMigrationHasNotStarted(); |
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.
all this part is basically the first test right? maybe we should keep just this one, that tests the whole process. Wdyt?
// Migrate while there are still utxos to migrate | ||
var remainingUTXOs = federationStorageProvider.getOldFederationBtcUTXOs(); | ||
while (!remainingUTXOs.isEmpty()) { | ||
var updateCollectionsTx = buildUpdateCollectionsTx(); |
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.
// Migrate while there are still utxos to migrate | |
var remainingUTXOs = federationStorageProvider.getOldFederationBtcUTXOs(); | |
while (!remainingUTXOs.isEmpty()) { | |
var updateCollectionsTx = buildUpdateCollectionsTx(); | |
// Migrate while there are still utxos to migrate | |
var remainingUTXOs = federationStorageProvider.getOldFederationBtcUTXOs(); | |
var updateCollectionsTx = buildUpdateCollectionsTx(); | |
while (!remainingUTXOs.isEmpty()) { |
it always creates the same tx right?
if (activations.isActive(ConsensusRule.RSKIP379)) { | ||
assertTrue(bridgeStorageProvider.hasPegoutTxSigHash(lastPegoutSigHash.get())); | ||
} else { | ||
assertFalse(bridgeStorageProvider.hasPegoutTxSigHash(lastPegoutSigHash.get())); | ||
} |
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'd try to avoid booleans in tests. I think its better to have both assertPegoutTxSigHashesAreSaved
and assertPegoutTxSigHashesAreNotSaved
, wdyt?
verifySigHashes(activations); | ||
verifyPegoutTransactionCreatedEventWasEmitted(activations); | ||
verifyPegouts(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.
wdyt about having the calls for these three methods inside the assertMigrationHasStarted
?
Optional<Federation> spendingFederationOptional = Optional.empty(); | ||
if (inputStandardRedeemScript.equals(getFederationDefaultRedeemScript(activeFederation))) { | ||
spendingFederationOptional = Optional.of(activeFederation); | ||
} else if (retiringFederation != null && | ||
inputStandardRedeemScript.equals(getFederationDefaultRedeemScript(retiringFederation))) { | ||
spendingFederationOptional = Optional.of(retiringFederation); | ||
} else { | ||
fail("Pegout scriptsig does not match any Federation"); | ||
} |
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.
the migration shouldn't always be from the retiring to the active fed? I mean, at this point the only pegouts expected are from the migration right?
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.
also, i find this really hard to follow. Lets try to avoid booleans in tests logic and have different methods for different expected behavior
} | ||
|
||
int index = spendingFederation.getNumberOfSignaturesRequired() + 1; | ||
if (spendingFederation instanceof ErpFederation) { |
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.
we could filter for federation type here also, right?
Description
This new integration test will validate that when a federation changes, the UTXOs will be moved and migrated as expected after Lovell is activated.
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist: