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

Adding Transaction.isGoQuorumPrivateTransaction() method #1661

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,21 @@ public boolean isEIP1559Transaction() {
return getGasPremium().isPresent() && getFeeCap().isPresent();
}

/**
* Returns whether or not the transaction is a GoQuorum private transaction. <br>
* <br>
* A GoQuorum private transaction has its <i>v</i> value equal to 37 or 38.
*
* @return true if GoQuorum private transaction, false otherwise
*/
public boolean isGoQuorumPrivateTransaction() {
return v.map(
value ->
GO_QUORUM_PRIVATE_TRANSACTION_V_VALUE_MIN.equals(value)
|| GO_QUORUM_PRIVATE_TRANSACTION_V_VALUE_MAX.equals(value))
.orElse(false);
}

private static Bytes32 computeSenderRecoveryHash(
final long nonce,
final Wei gasPrice,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.ethereum.core;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.config.GoQuorumOptions;
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPInput;

import org.apache.tuweni.bytes.Bytes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class TransactionGoQuorumTest {

private static final RLPInput ETHEREUM_PUBLIC_TX_RLP =
toRLP(
"0xf901fc8032830138808080b901ae60056013565b6101918061001d6000396000f35b3360008190555056006001600060e060020a6000350480630a874df61461003a57806341c0e1b514610058578063a02b161e14610066578063dbbdf0831461007757005b610045600435610149565b80600160a060020a031660005260206000f35b610060610161565b60006000f35b6100716004356100d4565b60006000f35b61008560043560243561008b565b60006000f35b600054600160a060020a031632600160a060020a031614156100ac576100b1565b6100d0565b8060018360005260205260406000208190555081600060005260206000a15b5050565b600054600160a060020a031633600160a060020a031614158015610118575033600160a060020a0316600182600052602052604060002054600160a060020a031614155b61012157610126565b610146565b600060018260005260205260406000208190555080600060005260206000a15b50565b60006001826000526020526040600020549050919050565b600054600160a060020a031633600160a060020a0316146101815761018f565b600054600160a060020a0316ff5b561ca0c5689ed1ad124753d54576dfb4b571465a41900a1dff4058d8adf16f752013d0a01221cbd70ec28c94a3b55ec771bcbc70778d6ee0b51ca7ea9514594c861b1884");
private static final RLPInput GOQUORUM_PRIVATE_TX_RLP_V37 =
toRLP(
"0xf88d0b808347b7608080b840290a80a37d198ff06abe189b638ff53ac8a8dc51a0aff07609d2aa75342783ae493b3e3c6b564c0eebe49284b05a0726fb33087b9e0231d349ea0c7b5661c8c525a07144db7045a395e608cda6ab051c86cc4fb42e319960b82087f3b26f0cbc3c2da00223ac129b22aec7a6c2ace3c3ef39c5eaaa54070fd82d8ee2140b0e70b1dca9");
private static final RLPInput GOQUORUM_PRIVATE_TX_RLP_V38 =
toRLP(
"0xf88d0b808347b7608080b840290a80a37d198ff06abe189b638ff53ac8a8dc51a0aff07609d2aa75342783ae493b3e3c6b564c0eebe49284b05a0726fb33087b9e0231d349ea0c7b5661c8c526a07144db7045a395e608cda6ab051c86cc4fb42e319960b82087f3b26f0cbc3c2da00223ac129b22aec7a6c2ace3c3ef39c5eaaa54070fd82d8ee2140b0e70b1dca9");

@BeforeClass
public static void beforeClass() {
GoQuorumOptions.goquorumCompatibilityMode = true;
}

@AfterClass
public static void afterClass() {
GoQuorumOptions.goquorumCompatibilityMode =
GoQuorumOptions.GOQUORUM_COMPATIBILITY_MODE_DEFAULT_VALUE;
Copy link
Contributor

Choose a reason for hiding this comment

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

neat

}

@Test
public void givenPublicTransaction_assertThatIsGoQuorumFlagIsFalse() {
Transaction transaction = Transaction.readFrom(ETHEREUM_PUBLIC_TX_RLP);
assertThat(transaction.isGoQuorumPrivateTransaction()).isFalse();
}

@Test
public void givenGoQuorumTransactionV37_assertThatIsGoQuorumFlagIsTrue() {
Transaction transaction = Transaction.readFrom(GOQUORUM_PRIVATE_TX_RLP_V37);

assertThat(transaction.getV()).isEqualTo(37);
assertThat(transaction.isGoQuorumPrivateTransaction()).isTrue();
}

@Test
public void givenGoQuorumTransactionV38_assertThatIsGoQuorumFlagIsTrue() {
Transaction transaction = Transaction.readFrom(GOQUORUM_PRIVATE_TX_RLP_V38);

assertThat(transaction.getV()).isEqualTo(38);
assertThat(transaction.isGoQuorumPrivateTransaction()).isTrue();
}

private static RLPInput toRLP(final String bytes) {
return RLP.input(Bytes.fromHexString(bytes));
}
}