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

Refactor Federation Watcher Tests #314

Conversation

apancorb
Copy link
Contributor

@apancorb apancorb commented Sep 30, 2024

Summary

Refactor existing Federation Watcher Tests so that when we introduce the new logic for signing the svp spend transaction on proposed federation change we are ready.

Motivation

https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP419.md

@apancorb apancorb self-assigned this Sep 30, 2024
@apancorb apancorb force-pushed the refactor/federation_watcher_tests branch from 471a59e to 96b6861 Compare September 30, 2024 10:49
@apancorb apancorb marked this pull request as ready for review September 30, 2024 10:54
@apancorb apancorb requested a review from a team as a code owner September 30, 2024 10:54
Comment on lines +95 to +107
federationWatcher.addListener(new FederationWatcher.Listener() {
@Override
public void onActiveFederationChange(Optional<Federation> oldFederation, Federation newFederation) {
assertEquals(Optional.empty(), oldFederation);
assertEquals(FIRST_FEDERATION, newFederation);
activeCalls.incrementAndGet();
}

@Override
public void onRetiringFederationChange(Optional<Federation> oldFederation, Optional<Federation> newFederation) {
retiringCalls.incrementAndGet();
}
});
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 extracting this to a method? I see it duplicated a couple of times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For each test the anoymous class implementation is a bit different if you notice


when(federationProvider.getActiveFederationAddress()).thenReturn(federation1.getAddress());
when(federationProvider.getRetiringFederationAddress()).thenReturn(Optional.empty());
void whenNoActiveFederationChange_shouldNotTriggerActiveOrRetiringFederationChange() throws Exception {
Copy link
Contributor

@julia-zack julia-zack Sep 30, 2024

Choose a reason for hiding this comment

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

Suggested change
void whenNoActiveFederationChange_shouldNotTriggerActiveOrRetiringFederationChange() throws Exception {
void onBestBlock_whenNoActiveFederationChange_shouldNotTriggerActiveOrRetiringFederationChange() throws Exception {

wdyt? To be clear about the method we are calling

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 thing is that we are not testing the onBestBlock implementation, just a side effect of calling it. So it could confuse the reader if we preface it as such.

Copy link
Contributor

@jeremy-then jeremy-then left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@nathanieliov nathanieliov left a comment

Choose a reason for hiding this comment

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

LGTM

verify(federationProvider, times(1)).getActiveFederation();

// Assert
assertEquals(1, activeCalls.get());
Copy link
Contributor

@julia-zack julia-zack Oct 2, 2024

Choose a reason for hiding this comment

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

wasn't asserting the active calls were 2 before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this was being done before. It was testing the same "code" twice since the listeners have the same implementation. So it leads to redundancy, not sure why it was designed like this as a whole :)

Comment on lines +196 to +197
var activeCalls = new AtomicInteger(0);
var retiringCalls = new AtomicInteger(0);
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 a global setUp to reset these values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems to overcomplicate things for a local counter variable

Copy link

sonarcloud bot commented Oct 2, 2024

@marcos-iov marcos-iov merged commit c95edea into feat/powpeg_validation_protocol-phase3 Oct 9, 2024
7 checks passed
@marcos-iov marcos-iov deleted the refactor/federation_watcher_tests branch October 9, 2024 17:39
apancorb pushed a commit that referenced this pull request Oct 21, 2024
apancorb pushed a commit that referenced this pull request Oct 23, 2024
apancorb pushed a commit that referenced this pull request Nov 19, 2024
apancorb pushed a commit that referenced this pull request Dec 6, 2024
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.

5 participants