use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.
the class AccountabilityManagerImplTest method setUp.
@BeforeEach
public void setUp() throws Exception {
BlockchainAccess blockchainAccess = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.TEST, null);
ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.TEST, null);
this.provenance = new AccountabilityManagerImpl(blockchainAccess, storageProvider);
}
use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.
the class AccountabilityManagerImplIntegrationTest method setUp.
@BeforeEach
public void setUp() {
AccountabilityConfigurationManager.getInstance().setDefaultKeystore();
Environments.getInstance().getAccountabilityConfig().setEthereumPassword("winery");
Environments.getInstance().getAccountabilityConfig().setGethUrl("http://127.0.0.1:8545");
Environments.getInstance().getAccountabilityConfig().setSwarmGatewayUrl("https://swarm-gateways.net/");
// deploy smart contracts to (a new address in) the blockchain
try {
ContractDeployer deployer = new ContractDeployer(Environments.getInstance().getAccountabilityConfig());
Environments.getInstance().getAccountabilityConfig().setEthereumProvenanceSmartContractAddress(deployer.deployProvenance());
Environments.getInstance().getAccountabilityConfig().setEthereumAuthorizationSmartContractAddress(deployer.deployAuthorization());
// reset the contents of the accountability layer so older, possibly incompatible instances are nullified.
BlockchainFactory.reset();
ImmutableStorageProviderFactory.reset();
// create new instances
BlockchainAccess blockchainAccess = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, Environments.getInstance().getAccountabilityConfig());
ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, Environments.getInstance().getAccountabilityConfig());
this.accountabilityManager = new AccountabilityManagerImpl(blockchainAccess, storageProvider);
} catch (Exception e) {
Preconditions.condition(false, e.getMessage());
}
}
use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.
the class AccountabilityManagerFactory method getAccountabilityManager.
public static AccountabilityManager getAccountabilityManager() throws AccountabilityException {
if (Objects.isNull(accountabilityManager)) {
try {
AccountabilityConfigurationObject properties = Environments.getInstance().getAccountabilityConfig();
Environments.getInstance().addConfigurationChangeListener(() -> {
BlockchainFactory.reset();
ImmutableStorageProviderFactory.reset();
});
BlockchainAccess blockchain = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, properties);
ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, properties);
accountabilityManager = new AccountabilityManagerImpl(blockchain, storageProvider);
} catch (BlockchainException e) {
String msg = "Could not instantiate accountability layer: " + e.getMessage();
LOGGER.error(msg, e);
throw new AccountabilityException(msg, e);
}
}
return accountabilityManager;
}
use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.
the class SwarmProviderTest method testStorageAndRetrieval.
@Test
public void testStorageAndRetrieval() throws ExecutionException, InterruptedException {
final String dataToStore = "This a string intended for testing!";
ImmutableStorageProviderFactory.reset();
ImmutableStorageProvider swarm = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.TEST, null);
assertNotNull(swarm);
swarm.store(new ByteArrayInputStream(dataToStore.getBytes(StandardCharsets.UTF_8))).thenCompose((hash) -> {
LOGGER.debug("retrieved hash is: {}", hash);
return swarm.retrieve(hash);
}).thenAccept((bytes) -> {
try {
String receivedMsg = IOUtils.toString(bytes, StandardCharsets.UTF_8);
LOGGER.debug("retrieved msg is: {}", receivedMsg);
assertEquals(dataToStore, receivedMsg);
} catch (IOException e) {
throw new CompletionException(e);
}
}).get();
}
Aggregations