use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.
the class PrivateMetadataUpdaterTest method before.
@Before
public void before() {
blockHeader = mock(BlockHeader.class);
privateStateStorage = new InMemoryPrivacyStorageProvider().createPrivateStateStorage();
final Hash hashBlockZero = Hash.ZERO;
when(blockHeader.getParentHash()).thenReturn(hashBlockZero);
updater = new PrivateMetadataUpdater(blockHeader, privateStateStorage);
hashBlockOne = Hash.fromHexString("1111111111111111111111111111111111111111111111111111111111111111");
stateRoot = Hash.fromHexString("2222222222222222222222222222222222222222222222222222222222222222");
privacyGroupId = Bytes32.fromHexString("3333333333333333333333333333333333333333333333333333333333333333");
}
use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.
the class BesuNodeFactory method createNodeWithMultiTenantedPrivacy.
public BesuNode createNodeWithMultiTenantedPrivacy(final String name, final String enclaveUrl, final String authFile, final String privTransactionSigningKey, final boolean enableFlexiblePrivacy) throws IOException, URISyntaxException {
final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder();
final PrivacyParameters privacyParameters = privacyParametersBuilder.setMultiTenancyEnabled(true).setEnabled(true).setFlexiblePrivacyGroupsEnabled(enableFlexiblePrivacy).setStorageProvider(new InMemoryPrivacyStorageProvider()).setEnclaveFactory(new EnclaveFactory(Vertx.vertx())).setEnclaveUrl(URI.create(enclaveUrl)).setPrivateKeyPath(Paths.get(ClassLoader.getSystemResource(privTransactionSigningKey).toURI())).build();
final MiningParameters miningParameters = new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).coinbase(AddressHelpers.ofValue(1)).miningEnabled(true).build();
return create(new BesuNodeConfigurationBuilder().name(name).jsonRpcEnabled().jsonRpcAuthenticationConfiguration(authFile).enablePrivateTransactions().privacyParameters(privacyParameters).miningConfiguration(miningParameters).build());
}
use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.
the class PrivacyPluginPrecompiledContractTest method setup.
@Before
public void setup() {
final PrivateStateStorage privateStateStorage = mock(PrivateStateStorage.class);
messageFrame = mock(MessageFrame.class);
final BlockDataGenerator blockGenerator = new BlockDataGenerator();
final Block genesis = blockGenerator.genesisBlock();
final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(mock(PrivateMetadataUpdater.class));
when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(PrivacyGroupHeadBlockMap.empty());
contract = new PrivacyPluginPrecompiledContract(new SpuriousDragonGasCalculator(), new PrivacyParameters.Builder().setEnabled(true).setPrivacyPluginEnabled(true).setStorageProvider(new InMemoryPrivacyStorageProvider()).setPrivacyService(new PrivacyPluginService() {
@Override
public void setPayloadProvider(final PrivacyPluginPayloadProvider provider) {
}
@Override
public PrivacyPluginPayloadProvider getPayloadProvider() {
return new PrivacyPluginPayloadProvider() {
@Override
public Bytes generateMarkerPayload(final org.hyperledger.besu.plugin.data.PrivateTransaction privateTransaction, final String privacyUserId) {
return serialize(privateTransaction).encoded();
}
@Override
public Optional<org.hyperledger.besu.plugin.data.PrivateTransaction> getPrivateTransactionFromPayload(final org.hyperledger.besu.plugin.data.Transaction transaction) {
final BytesValueRLPInput bytesValueRLPInput = new BytesValueRLPInput(transaction.getPayload(), false);
return Optional.of(readFrom(bytesValueRLPInput));
}
};
}
@Override
public void setPrivacyGroupAuthProvider(final PrivacyGroupAuthProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupAuthProvider getPrivacyGroupAuthProvider() {
return (privacyGroupId, privacyUserId, blockNumber) -> true;
}
@Override
public void setPrivacyGroupGenesisProvider(final PrivacyGroupGenesisProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupGenesisProvider getPrivacyGroupGenesisProvider() {
return (privacyGroupId, blockNumber) -> (PrivacyGenesis) Collections::emptyList;
}
@Override
public PrivateMarkerTransactionFactory getPrivateMarkerTransactionFactory() {
return null;
}
@Override
public void setPrivateMarkerTransactionFactory(final PrivateMarkerTransactionFactory privateMarkerTransactionFactory) {
}
}).setEnclaveFactory(mock(EnclaveFactory.class)).build());
}
Aggregations