use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.
the class PrivacyBlockProcessorTest method setUp.
@Before
public void setUp() {
blockProcessor = mock(AbstractBlockProcessor.class);
privateStateStorage = new PrivateStateKeyValueStorage(new InMemoryKeyValueStorage());
privateWorldStateArchive = mock(WorldStateArchive.class);
enclave = mock(Enclave.class);
protocolSchedule = mock(ProtocolSchedule.class);
this.privacyBlockProcessor = new PrivacyBlockProcessor(blockProcessor, protocolSchedule, enclave, privateStateStorage, privateWorldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(true, (privacyGroupId, blockNumber) -> Collections::emptyList));
publicWorldStateArchive = mock(WorldStateArchive.class);
privacyBlockProcessor.setPublicWorldStateArchive(publicWorldStateArchive);
}
use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.
the class PrivateStorageMigrationBuilder method build.
public PrivateStorageMigration build() {
final Blockchain blockchain = besuController.getProtocolContext().getBlockchain();
final Address privacyPrecompileAddress = privacyParameters.getPrivacyAddress();
final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
final WorldStateArchive publicWorldStateArchive = besuController.getProtocolContext().getWorldStateArchive();
final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
final LegacyPrivateStateStorage legacyPrivateStateStorage = privacyParameters.getPrivateStorageProvider().createLegacyPrivateStateStorage();
final PrivateStateRootResolver privateStateRootResolver = privacyParameters.getPrivateStateRootResolver();
return new PrivateStorageMigration(blockchain, privacyPrecompileAddress, protocolSchedule, publicWorldStateArchive, privateStateStorage, privateStateRootResolver, legacyPrivateStateStorage, PrivateMigrationBlockProcessor::new);
}
use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.
the class PrivacyReorgTest method setUp.
@Before
public void setUp() throws IOException {
mockEnclave = mock(Enclave.class);
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
PRIVATE_TRANSACTION.writeTo(rlpOutput);
when(mockEnclave.receive(any())).thenReturn(new ReceiveResponse(rlpOutput.encoded().toBase64String().getBytes(StandardCharsets.UTF_8), PRIVACY_GROUP_BYTES32.toBase64String(), ENCLAVE_PUBLIC_KEY.toBase64String()));
privacyMarkerTransaction = Transaction.builder().type(TransactionType.FRONTIER).chainId(BigInteger.valueOf(1337)).gasLimit(60000).gasPrice(Wei.of(1000)).nonce(0).payload(PRIVACY_TRANSACTION_PAYLOAD).to(DEFAULT_PRIVACY).value(Wei.ZERO).signAndBuild(KEY_PAIR);
// Create Storage
final Path dataDir = folder.newFolder().toPath();
// Configure Privacy
EnclaveFactory enclaveFactory = mock(EnclaveFactory.class);
when(enclaveFactory.createVertxEnclave(any())).thenReturn(mockEnclave);
privacyParameters = new PrivacyParameters.Builder().setEnabled(true).setStorageProvider(createKeyValueStorageProvider()).setEnclaveUrl(URI.create("http//1.1.1.1:1234")).setEnclaveFactory(enclaveFactory).build();
privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
privacyController = mock(RestrictedDefaultPrivacyController.class);
when(privacyController.findPrivacyGroupByGroupId(any(), any())).thenReturn(Optional.of(new PrivacyGroup()));
privateStateRootResolver = new PrivateStateRootResolver(privacyParameters.getPrivateStateStorage());
besuController = new BesuController.Builder().fromGenesisConfig(GenesisConfigFile.development()).synchronizerConfiguration(SynchronizerConfiguration.builder().build()).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).storageProvider(new InMemoryKeyValueStorageProvider()).networkId(BigInteger.ONE).miningParameters(new MiningParameters.Builder().minTransactionGasPrice(Wei.of(1000)).miningEnabled(false).build()).nodeKey(NodeKeyUtils.generate()).metricsSystem(new NoOpMetricsSystem()).dataDirectory(dataDir).clock(TestClock.fixed()).privacyParameters(privacyParameters).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
}
use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.
the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.
@Test
public void testSendAndReceive() {
final List<String> publicKeys = testHarness.getPublicKeys();
final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
privateTransaction.writeTo(bytesValueRLPOutput);
final String s = bytesValueRLPOutput.encoded().toBase64String();
final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.
the class PrivateStorageMigrationTest method setUp.
@Before
public void setUp() {
final KeyValueStorage kvStorage = new InMemoryKeyValueStorage();
privateStateStorage = new PrivateStateKeyValueStorage(kvStorage);
privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
lenient().when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
lenient().when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
lenient().when(protocolSpec.getTransactionReceiptFactory()).thenReturn(transactionReceiptFactory);
lenient().when(protocolSpec.getBlockReward()).thenReturn(Wei.ZERO);
lenient().when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(miningBeneficiaryCalculator);
lenient().when(protocolSpec.isSkipZeroBlockRewards()).thenReturn(false);
migration = new PrivateStorageMigration(blockchain, PRIVACY_ADDRESS, protocolSchedule, publicWorldStateArchive, privateStateStorage, privateStateRootResolver, legacyPrivateStateStorage, (protocolSpec) -> privateMigrationBlockProcessor);
}
Aggregations