use of org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider 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