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

Create Federation Change Integration Test With Migration Phase #2935

Open
wants to merge 2 commits into
base: fix/powpeg-migration-tests-common-path
Choose a base branch
from

Conversation

apancorb
Copy link
Contributor

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

  • 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)
  • Other information:

Copy link

github-actions bot commented Jan 16, 2025

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@apancorb apancorb self-assigned this Jan 16, 2025
@apancorb apancorb marked this pull request as ready for review January 16, 2025 12:02
@apancorb apancorb requested a review from a team as a code owner January 16, 2025 12:02
@apancorb apancorb force-pushed the feat/migration_test branch from 9e7d495 to 0813889 Compare January 16, 2025 13:13
for (PegoutsWaitingForConfirmations.Entry pegoutEntry : bridgeStorageProvider.getPegoutsWaitingForConfirmations().getEntries()) {
var pegoutBtcTransaction = pegoutEntry.getBtcTransaction();
for (TransactionInput input : pegoutBtcTransaction.getInputs()) {
// Each input should contain the right scriptsig
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
// 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()) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

assertNull(bridgeSupport.getRetiringFederationAddress());
}

private void assertLastRetiredFederationP2SHMatchesWithOriginalFederation(FederationType federationType, Federation originalFederation, ActivationConfig.ForBlock activations) {
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
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 {
Copy link
Contributor

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?

Comment on lines +199 to +221
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();
Copy link
Contributor

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?

Comment on lines +439 to +442
// Migrate while there are still utxos to migrate
var remainingUTXOs = federationStorageProvider.getOldFederationBtcUTXOs();
while (!remainingUTXOs.isEmpty()) {
var updateCollectionsTx = buildUpdateCollectionsTx();
Copy link
Contributor

@julia-zack julia-zack Jan 17, 2025

Choose a reason for hiding this comment

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

Suggested change
// 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?

Comment on lines +673 to +677
if (activations.isActive(ConsensusRule.RSKIP379)) {
assertTrue(bridgeStorageProvider.hasPegoutTxSigHash(lastPegoutSigHash.get()));
} else {
assertFalse(bridgeStorageProvider.hasPegoutTxSigHash(lastPegoutSigHash.get()));
}
Copy link
Contributor

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?

Comment on lines +231 to +233
verifySigHashes(activations);
verifyPegoutTransactionCreatedEventWasEmitted(activations);
verifyPegouts(activations);
Copy link
Contributor

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?

Comment on lines +643 to +651
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");
}
Copy link
Contributor

@julia-zack julia-zack Jan 17, 2025

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?

Copy link
Contributor

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) {
Copy link
Contributor

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?

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.

3 participants