forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
priv_debugGetStateRoot bugfix. (hyperledger#1607)
priv_debugGetStateRoot bugfix, refactorings and tests. Signed-off-by: Mark Terry <mark.terry@consensys.net>
- Loading branch information
1 parent
fe2137a
commit 96a96ba
Showing
21 changed files
with
395 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../org/hyperledger/besu/tests/acceptance/dsl/transaction/privacy/PrivDebugGetStateRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; | ||
|
||
import java.io.IOException; | ||
|
||
public class PrivDebugGetStateRoot implements Transaction<PrivacyRequestFactory.DebugGetStateRoot> { | ||
|
||
private final String privacyGroupId; | ||
private final String blockParam; | ||
|
||
public PrivDebugGetStateRoot(final String privacyGroupId, final String blockParam) { | ||
this.privacyGroupId = privacyGroupId; | ||
this.blockParam = blockParam; | ||
} | ||
|
||
@Override | ||
public PrivacyRequestFactory.DebugGetStateRoot execute(final NodeRequests node) { | ||
try { | ||
final PrivacyRequestFactory.DebugGetStateRoot response = | ||
node.privacy().privDebugGetStateRoot(privacyGroupId, blockParam).send(); | ||
assertThat(response).as("check response is not null").isNotNull(); | ||
return response; | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...edger/besu/tests/acceptance/privacy/PrivDebugGetStateRootOffchainGroupAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.tests.acceptance.privacy; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.ethereum.core.Hash; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyRequestFactory; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
import org.apache.tuweni.bytes.Bytes32; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PrivDebugGetStateRootOffchainGroupAcceptanceTest extends PrivacyAcceptanceTestBase { | ||
|
||
private PrivacyNode aliceNode; | ||
private PrivacyNode bobNode; | ||
|
||
@Before | ||
public void setUp() throws IOException, URISyntaxException { | ||
aliceNode = | ||
privacyBesu.createPrivateTransactionEnabledMinerNode( | ||
"alice-node", PrivacyAccountResolver.ALICE); | ||
bobNode = | ||
privacyBesu.createPrivateTransactionEnabledMinerNode( | ||
"bob-node", PrivacyAccountResolver.BOB); | ||
privacyCluster.start(aliceNode, bobNode); | ||
} | ||
|
||
@Test | ||
public void nodesInGroupShouldHaveSameStateRoot() { | ||
final String privacyGroupId = | ||
aliceNode.execute( | ||
privacyTransactions.createPrivacyGroup( | ||
"testGroup", "A group for everyone", aliceNode, bobNode)); | ||
|
||
final Hash aliceStateRootId = | ||
aliceNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
final Hash bobStateRootId = | ||
bobNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
assertThat(aliceStateRootId).isEqualTo(bobStateRootId); | ||
} | ||
|
||
@Test | ||
public void unknownGroupShouldReturnError() { | ||
final PrivacyRequestFactory.DebugGetStateRoot aliceResult = | ||
aliceNode.execute( | ||
privacyTransactions.debugGetStateRoot( | ||
Hash.wrap(Bytes32.random()).toBase64String(), "latest")); | ||
|
||
assertThat(aliceResult.getResult()).isNull(); | ||
assertThat(aliceResult.hasError()).isTrue(); | ||
assertThat(aliceResult.getError()).isNotNull(); | ||
assertThat(aliceResult.getError().getMessage()).contains("Error finding privacy group"); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...ledger/besu/tests/acceptance/privacy/PrivDebugGetStateRootOnchainGroupAcceptanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.tests.acceptance.privacy; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.ethereum.core.Address; | ||
import org.hyperledger.besu.ethereum.core.Hash; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode; | ||
import org.hyperledger.besu.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver; | ||
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyRequestFactory; | ||
import org.hyperledger.besu.tests.web3j.privacy.OnChainPrivacyAcceptanceTestBase; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
import org.apache.tuweni.bytes.Bytes32; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PrivDebugGetStateRootOnchainGroupAcceptanceTest | ||
extends OnChainPrivacyAcceptanceTestBase { | ||
|
||
private PrivacyNode aliceNode; | ||
private PrivacyNode bobNode; | ||
|
||
@Before | ||
public void setUp() throws IOException, URISyntaxException { | ||
aliceNode = | ||
privacyBesu.createOnChainPrivacyGroupEnabledMinerNode( | ||
"alice-node", PrivacyAccountResolver.ALICE, Address.PRIVACY, false); | ||
bobNode = | ||
privacyBesu.createOnChainPrivacyGroupEnabledMinerNode( | ||
"bob-node", PrivacyAccountResolver.BOB, Address.PRIVACY, false); | ||
privacyCluster.start(aliceNode, bobNode); | ||
} | ||
|
||
@Test | ||
public void nodesInGroupShouldHaveSameStateRoot() { | ||
final String privacyGroupId = createOnChainPrivacyGroup(aliceNode, bobNode); | ||
|
||
final Hash aliceStateRootId = | ||
aliceNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
final Hash bobStateRootId = | ||
bobNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
assertThat(aliceStateRootId).isEqualTo(bobStateRootId); | ||
} | ||
|
||
@Test | ||
public void unknownGroupShouldReturnError() { | ||
final PrivacyRequestFactory.DebugGetStateRoot aliceResult = | ||
aliceNode.execute( | ||
privacyTransactions.debugGetStateRoot( | ||
Hash.wrap(Bytes32.random()).toBase64String(), "latest")); | ||
|
||
assertThat(aliceResult.getResult()).isNull(); | ||
assertThat(aliceResult.hasError()).isTrue(); | ||
assertThat(aliceResult.getError()).isNotNull(); | ||
assertThat(aliceResult.getError().getMessage()).contains("Error finding privacy group"); | ||
} | ||
|
||
@Test | ||
public void blockParamShouldBeApplied() { | ||
waitForBlockHeight(aliceNode, 2); | ||
waitForBlockHeight(bobNode, 2); | ||
|
||
final String privacyGroupId = createOnChainPrivacyGroup(aliceNode, bobNode); | ||
|
||
waitForBlockHeight(aliceNode, 10); | ||
waitForBlockHeight(bobNode, 10); | ||
|
||
final Hash aliceResult1 = | ||
aliceNode.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "1")).getResult(); | ||
final Hash bobResultInt1 = | ||
bobNode.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "1")).getResult(); | ||
|
||
assertThat(aliceResult1).isEqualTo(bobResultInt1); | ||
|
||
final Hash aliceResultLatest = | ||
aliceNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
final Hash bobResultLatest = | ||
bobNode | ||
.execute(privacyTransactions.debugGetStateRoot(privacyGroupId, "latest")) | ||
.getResult(); | ||
|
||
assertThat(aliceResultLatest).isEqualTo(bobResultLatest); | ||
assertThat(aliceResult1).isNotEqualTo(aliceResultLatest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.