Search in sources :

Example 1 with PrivacyGroupGenesisProvider

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());
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Bytes(org.apache.tuweni.bytes.Bytes) PrivacyPluginPayloadProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyPluginPayloadProvider) Optional(java.util.Optional) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivacyPluginService(org.hyperledger.besu.plugin.services.PrivacyPluginService) Block(org.hyperledger.besu.ethereum.core.Block) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) PrivacyGroupGenesisProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) PrivacyGroupAuthProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupAuthProvider) Before(org.junit.Before)

Aggregations

Optional (java.util.Optional)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)1 InMemoryPrivacyStorageProvider (org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider)1 PrivateMetadataUpdater (org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater)1 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)1 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)1 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)1 SpuriousDragonGasCalculator (org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator)1 PrivacyPluginService (org.hyperledger.besu.plugin.services.PrivacyPluginService)1 PrivacyGroupAuthProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyGroupAuthProvider)1 PrivacyGroupGenesisProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider)1 PrivacyPluginPayloadProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyPluginPayloadProvider)1 PrivateMarkerTransactionFactory (org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory)1 Before (org.junit.Before)1