Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Add Privacy Precompiled contract Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Feb 8, 2019
1 parent c97d855 commit f661049
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class ProtocolSpec<C> {

private final MiningBeneficiaryCalculator miningBeneficiaryCalculator;

private final PrecompileContractRegistry precompileContractRegistry;

/**
* Creates a new protocol specification instance.
*
Expand All @@ -70,6 +72,7 @@ public class ProtocolSpec<C> {
* @param blockReward the blockReward to use.
* @param transactionReceiptType the type of transaction receipt to use, one of
* @param miningBeneficiaryCalculator determines to whom mining proceeds are paid
* @param precompileContractRegistry all the pre-compiled contracts added
*/
public ProtocolSpec(
final String name,
Expand All @@ -87,7 +90,8 @@ public ProtocolSpec(
final DifficultyCalculator<C> difficultyCalculator,
final Wei blockReward,
final TransactionReceiptType transactionReceiptType,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator) {
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final PrecompileContractRegistry precompileContractRegistry) {
this.name = name;
this.evm = evm;
this.transactionValidator = transactionValidator;
Expand All @@ -103,6 +107,7 @@ public ProtocolSpec(
this.difficultyCalculator = difficultyCalculator;
this.blockReward = blockReward;
this.miningBeneficiaryCalculator = miningBeneficiaryCalculator;
this.precompileContractRegistry = precompileContractRegistry;
}

/**
Expand Down Expand Up @@ -234,4 +239,8 @@ public Wei getBlockReward() {
public MiningBeneficiaryCalculator getMiningBeneficiaryCalculator() {
return miningBeneficiaryCalculator;
}

public PrecompileContractRegistry getPrecompileContractRegistry() {
return precompileContractRegistry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ public ProtocolSpec<T> build(final ProtocolSchedule<T> protocolSchedule) {
difficultyCalculator,
blockReward,
transactionReceiptType,
miningBeneficiaryCalculator);
miningBeneficiaryCalculator,
precompileContractRegistry);
}

public interface TransactionProcessorBuilder {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 ConsenSys AG.
* Copyright 2019 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 ConsenSys AG.
* Copyright 2019 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public class EthGetTransactionReceiptTest {
null,
null,
TransactionReceiptType.ROOT,
BlockHeader::getCoinbase);
BlockHeader::getCoinbase,
null);
private final ProtocolSpec<Void> statusTransactionTypeSpec =
new ProtocolSpec<>(
"status",
Expand All @@ -109,7 +110,8 @@ public class EthGetTransactionReceiptTest {
null,
null,
TransactionReceiptType.STATUS,
BlockHeader::getCoinbase);
BlockHeader::getCoinbase,
null);

private final JsonRpcParameter parameters = new JsonRpcParameter();

Expand Down
71 changes: 71 additions & 0 deletions pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2019 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.
*/
package tech.pegasys.pantheon;

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

import tech.pegasys.pantheon.config.GenesisConfigFile;
import tech.pegasys.pantheon.controller.MainnetPantheonController;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.mainnet.PrecompiledContract;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;

import java.io.IOException;
import java.nio.file.Path;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class PrivacyTest {

private static final Integer ADDRESS = 9;
@Rule public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void privacyPrecompiled() throws IOException {
final Path dataDir = folder.newFolder().toPath();
PrivacyParameters privacyParameters = PrivacyParameters.noPrivacy();
privacyParameters.setPrivacyAddress(ADDRESS);
privacyParameters.setEnabled(true);

MainnetPantheonController mainnetPantheonController =
(MainnetPantheonController)
PantheonController.fromConfig(
GenesisConfigFile.mainnet(),
SynchronizerConfiguration.builder().build(),
new InMemoryStorageProvider(),
false,
1,
new MiningParametersTestBuilder().enabled(false).build(),
SECP256K1.KeyPair.generate(),
new NoOpMetricsSystem(),
privacyParameters,
dataDir);

Address privacyContractAddress = Address.privacyPrecompiled(ADDRESS);
PrecompiledContract precompiledContract =
mainnetPantheonController
.getProtocolSchedule()
.getByBlockNumber(1)
.getPrecompileContractRegistry()
.get(privacyContractAddress);
assertThat(precompiledContract.getName()).isEqualTo("Privacy");
}
}

0 comments on commit f661049

Please sign in to comment.