From ce503710ebfc2a2da68c12286186e7b5f50d6cd5 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Thu, 5 Dec 2024 17:26:58 -0300 Subject: [PATCH] Use clear methods instead of setting null values --- .../co/rsk/peg/BridgeStorageProvider.java | 26 ++++++++++++---- .../main/java/co/rsk/peg/BridgeSupport.java | 6 ++-- .../co/rsk/peg/BridgeStorageProviderTest.java | 30 +++++++++---------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java index dc3e231c47..188f16feaf 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java @@ -614,6 +614,10 @@ public void setSvpFundTxHashUnsigned(Sha256Hash hash) { this.isSvpFundTxHashUnsignedSet = true; } + public void clearSvpFundTxHashUnsigned() { + setSvpFundTxHashUnsigned(null); + } + private void saveSvpFundTxHashUnsigned() { if (!activations.isActive(RSKIP419) || !isSvpFundTxHashUnsignedSet) { return; @@ -630,6 +634,10 @@ public void setSvpFundTxSigned(BtcTransaction svpFundTxSigned) { this.isSvpFundTxSignedSet = true; } + public void clearSvpFundTxSigned() { + setSvpFundTxSigned(null); + } + private void saveSvpFundTxSigned() { if (!activations.isActive(RSKIP419) || !isSvpFundTxSignedSet) { return; @@ -646,6 +654,10 @@ public void setSvpSpendTxHashUnsigned(Sha256Hash hash) { this.isSvpSpendTxHashUnsignedSet = true; } + public void clearSvpSpendTxHashUnsigned() { + setSvpSpendTxHashUnsigned(null); + } + private void saveSvpSpendTxHashUnsigned() { if (!activations.isActive(RSKIP419) || !isSvpSpendTxHashUnsignedSet) { return; @@ -670,6 +682,10 @@ public void setSvpSpendTxWaitingForSignatures(Map.Entry signatures) { diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java index 6679779c13..76e99a50a7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java @@ -227,7 +227,7 @@ void saveSvpFundTxHashUnsigned_postLovell700AndResettingToNull_shouldSaveNullInS bridgeStorageProvider.save(); // Act - bridgeStorageProvider.setSvpFundTxHashUnsigned(null); + bridgeStorageProvider.clearSvpFundTxHashUnsigned(); bridgeStorageProvider.save(); // Assert @@ -289,7 +289,7 @@ void getSvpFundTxHashUnsigned_whenDifferentHashIsInStorageAndAnotherIsSetButNotS void getSvpFundTxHashUnsigned_whenStorageIsNotEmptyAndHashSetToNullButNotSaved_shouldReturnEmpty() { // Arrange repository.addStorageBytes(bridgeAddress, SVP_FUND_TX_HASH_UNSIGNED.getKey(), BridgeSerializationUtils.serializeSha256Hash(svpFundTxHash)); - bridgeStorageProvider.setSvpFundTxHashUnsigned(null); + bridgeStorageProvider.clearSvpFundTxHashUnsigned(); // Act Optional svpFundTxHashUnsigned = bridgeStorageProvider.getSvpFundTxHashUnsigned(); @@ -328,7 +328,7 @@ void getSvpFundTxHashUnsigned_whenHashDirectlySavedInStorage_shouldReturnTheHash @Test void getSvpFundTxHashUnsigned_whenSetToNull_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpFundTxHashUnsigned(null); + bridgeStorageProvider.clearSvpFundTxHashUnsigned(); // Act Optional svpFundTxHashUnsigned = bridgeStorageProvider.getSvpFundTxHashUnsigned(); @@ -352,7 +352,7 @@ void getSvpFundTxHashUnsigned_whenHashIsNullInStorage_shouldReturnEmpty() { @Test void getSvpFundTxHashUnsigned_whenNullHashIsSetAndSaved_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpFundTxHashUnsigned(null); + bridgeStorageProvider.clearSvpFundTxHashUnsigned(); bridgeStorageProvider.save(); // Act @@ -438,7 +438,7 @@ void saveSvpFundTxSigned_postLovell700AndResettingToNull_shouldSaveNullInStorage bridgeStorageProvider.save(); // Act - bridgeStorageProvider.setSvpFundTxSigned(null); + bridgeStorageProvider.clearSvpFundTxSigned(); bridgeStorageProvider.save(); // Assert @@ -503,7 +503,7 @@ void getSvpFundTxSigned_whenHashSet_shouldReturnTheHash() { @Test void getSvpFundTxSigned_whenHashSetToNull_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpFundTxSigned(null); + bridgeStorageProvider.clearSvpFundTxSigned(); // Act Optional svpFundTxSigned = bridgeStorageProvider.getSvpFundTxSigned(); @@ -538,7 +538,7 @@ void getSvpFundTxSigned_whenHashSavedAndHashSetToNull_shouldReturnEmpty() { SVP_FUND_TX_SIGNED.getKey(), BridgeSerializationUtils.serializeBtcTransaction(svpFundTx) ); - bridgeStorageProvider.setSvpFundTxSigned(null); + bridgeStorageProvider.clearSvpFundTxSigned(); // Act Optional svpFundTxSigned = bridgeStorageProvider.getSvpFundTxSigned(); @@ -686,7 +686,7 @@ void saveSvpSpendTxHashUnsigned_postLovell700AndResettingToNull_shouldSaveNullIn bridgeStorageProvider.save(); // Act - bridgeStorageProvider.setSvpSpendTxHashUnsigned(null); + bridgeStorageProvider.clearSvpSpendTxHashUnsigned(); bridgeStorageProvider.save(); // Assert @@ -748,7 +748,7 @@ void getSvpSpendTxHashUnsigned_whenDifferentHashIsInStorageAndAnotherIsSetButNot void getSvpFundTxHashUnsigned_whenStorageIsNotEmptyAndHashSetToNullButNotSaved_shouldReturnEmpty() { // Arrange repository.addStorageBytes(bridgeAddress, SVP_SPEND_TX_HASH_UNSIGNED.getKey(), BridgeSerializationUtils.serializeSha256Hash(svpSpendTxHash)); - bridgeStorageProvider.setSvpSpendTxHashUnsigned(null); + bridgeStorageProvider.clearSvpSpendTxHashUnsigned(); // Act Optional svpSpendTxHashUnsigned = bridgeStorageProvider.getSvpSpendTxHashUnsigned(); @@ -787,7 +787,7 @@ void getSvpSpendTxHashUnsigned_whenHashDirectlySavedInStorage_shouldReturnTheHas @Test void getSvpSpendTxHashUnsigned_whenSetToNull_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpSpendTxHashUnsigned(null); + bridgeStorageProvider.clearSvpSpendTxHashUnsigned(); // Act Optional svpSpendTxHashUnsigned = bridgeStorageProvider.getSvpSpendTxHashUnsigned(); @@ -811,7 +811,7 @@ void getSvpSpendTxHashUnsigned_whenHashIsNullInStorage_shouldReturnEmpty() { @Test void getSvpSpendTxHashUnsigned_whenNullHashIsSetAndSaved_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpSpendTxHashUnsigned(null); + bridgeStorageProvider.clearSvpSpendTxHashUnsigned(); bridgeStorageProvider.save(); // Act @@ -966,7 +966,7 @@ void saveSvpSpendTxWaitingForSignatures_postLovell700AndNullSvpSpendTxWaitingFor bridgeStorageProvider.save(); // Act - bridgeStorageProvider.setSvpSpendTxWaitingForSignatures(null); + bridgeStorageProvider.clearSvpSpendTxWaitingForSignatures(); bridgeStorageProvider.save(); // Assert @@ -1047,7 +1047,7 @@ void getSvpSpendTxWaitingForSignatures_whenDifferentEntryIsInStorageAndEntrySetT bridgeAddress, SVP_SPEND_TX_WAITING_FOR_SIGNATURES.getKey(), BridgeSerializationUtils.serializeRskTxWaitingForSignatures(svpSpendTxWaitingForSignatures)); - bridgeStorageProvider.setSvpSpendTxWaitingForSignatures(null); + bridgeStorageProvider.clearSvpSpendTxWaitingForSignatures(); // Act Optional> actualSvpSpendTxWaitingForSignatures = @@ -1092,7 +1092,7 @@ void getSvpSpendTxWaitingForSignatures_whenEntryDirectlySavedInStorage_shouldRet @Test void getSvpSpendTxWaitingForSignatures_whenSetToNull_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpSpendTxWaitingForSignatures(null); + bridgeStorageProvider.clearSvpSpendTxWaitingForSignatures(); // Act Optional> actualSvpSpendTxWaitingForSignatures = @@ -1105,7 +1105,7 @@ void getSvpSpendTxWaitingForSignatures_whenSetToNull_shouldReturnEmpty() { @Test void getSvpSpendTxWaitingForSignatures_whenNullEntryIsSetAndSaved_shouldReturnEmpty() { // Arrange - bridgeStorageProvider.setSvpSpendTxWaitingForSignatures(null); + bridgeStorageProvider.clearSvpSpendTxWaitingForSignatures(); bridgeStorageProvider.save(); // Act