use of org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration in project besu by hyperledger.
the class AccountPermissioningControllerFactoryTest method createOnchainConfigOnlyControllerShouldReturnExpectedController.
@Test
public void createOnchainConfigOnlyControllerShouldReturnExpectedController() {
SmartContractPermissioningConfiguration onchainConfig = onchainConfig();
assertThat(onchainConfig.isSmartContractAccountAllowlistEnabled()).isTrue();
PermissioningConfiguration permissioningConfiguration = new PermissioningConfiguration(Optional.empty(), Optional.of(onchainConfig), Optional.empty());
Optional<AccountPermissioningController> controller = AccountPermissioningControllerFactory.create(permissioningConfiguration, transactionSimulator, metricsSystem, blockchain);
Assertions.assertThat(controller).isNotEmpty();
assertThat(controller.get().getAccountLocalConfigPermissioningController()).isEmpty();
assertThat(controller.get().getTransactionSmartContractPermissioningController()).isNotEmpty();
}
use of org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration in project besu by hyperledger.
the class AccountPermissioningControllerFactoryTest method createLocalAndOnchainControllerShouldReturnExpectedControllers.
@Test
public void createLocalAndOnchainControllerShouldReturnExpectedControllers() {
LocalPermissioningConfiguration localConfig = localConfig();
assertThat(localConfig.isAccountAllowlistEnabled()).isTrue();
SmartContractPermissioningConfiguration onchainConfig = onchainConfig();
assertThat(onchainConfig.isSmartContractAccountAllowlistEnabled()).isTrue();
PermissioningConfiguration permissioningConfiguration = new PermissioningConfiguration(Optional.of(localConfig), Optional.of(onchainConfig), Optional.empty());
Optional<AccountPermissioningController> controller = AccountPermissioningControllerFactory.create(permissioningConfiguration, transactionSimulator, metricsSystem, blockchain);
Assertions.assertThat(controller).isNotEmpty();
assertThat(controller.get().getAccountLocalConfigPermissioningController()).isNotEmpty();
assertThat(controller.get().getTransactionSmartContractPermissioningController()).isNotEmpty();
}
use of org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration in project besu by hyperledger.
the class NodePermissioningControllerFactoryTest method createOnchainShouldFailIfValidationFails.
@Test
public void createOnchainShouldFailIfValidationFails() {
smartContractPermissioningConfiguration = new SmartContractPermissioningConfiguration();
smartContractPermissioningConfiguration.setNodeSmartContractAddress(Address.fromHexString("0x0000000000000000000000000000000000001234"));
smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(true);
config = new PermissioningConfiguration(Optional.empty(), Optional.of(smartContractPermissioningConfiguration), Optional.empty());
when(transactionSimulator.processAtHead(any())).thenThrow(new RuntimeException());
final Throwable thrown = catchThrowable(() -> new NodePermissioningControllerFactory().create(config, synchronizer, bootnodes, selfEnode.getNodeId(), transactionSimulator, new NoOpMetricsSystem(), blockchain, Collections.emptyList()));
assertThat(thrown).isInstanceOf(IllegalStateException.class).hasMessage("Error: node permissioning contract at address 0x0000000000000000000000000000000000001234 does not match the expected interface version 1.");
}
use of org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration in project besu by hyperledger.
the class NodePermissioningControllerFactoryTest method testCreateWithLocalNodeAndSmartContractPermissioningEnabled.
@Test
public void testCreateWithLocalNodeAndSmartContractPermissioningEnabled() {
localPermissioningConfig = LocalPermissioningConfiguration.createDefault();
localPermissioningConfig.setNodeAllowlist(Collections.emptyList());
localPermissioningConfig.setNodePermissioningConfigFilePath("fake-file-path");
smartContractPermissioningConfiguration = new SmartContractPermissioningConfiguration();
smartContractPermissioningConfiguration.setNodeSmartContractAddress(Address.fromHexString("0x0000000000000000000000000000000000001234"));
smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(true);
config = new PermissioningConfiguration(Optional.of(localPermissioningConfig), Optional.of(smartContractPermissioningConfiguration), Optional.empty());
NodePermissioningControllerFactory factory = new NodePermissioningControllerFactory();
NodePermissioningController controller = factory.create(config, synchronizer, bootnodes, selfEnode.getNodeId(), transactionSimulator, new NoOpMetricsSystem(), blockchain, Collections.emptyList());
List<NodeConnectionPermissioningProvider> providers = controller.getProviders();
assertThat(providers.size()).isEqualTo(2);
NodeConnectionPermissioningProvider p1 = providers.get(0);
NodeConnectionPermissioningProvider p2 = providers.get(1);
if (p1.getClass() == NodeLocalConfigPermissioningController.class) {
assertThat(p2).isInstanceOf(NodeSmartContractPermissioningController.class);
} else {
assertThat(p2).isInstanceOf(NodeLocalConfigPermissioningController.class);
assertThat(p1).isInstanceOf(NodeSmartContractPermissioningController.class);
}
assertThat(controller.getSyncStatusNodePermissioningProvider()).isEmpty();
}
use of org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration in project besu by hyperledger.
the class NodePermissioningControllerFactoryTest method testCreateWithSmartContractNodePermissioningEnabledOnlyAndBootnode.
@Test
public void testCreateWithSmartContractNodePermissioningEnabledOnlyAndBootnode() {
final Collection<EnodeURL> fixedNodes = Collections.singleton(selfEnode);
smartContractPermissioningConfiguration = new SmartContractPermissioningConfiguration();
smartContractPermissioningConfiguration.setNodeSmartContractAddress(Address.fromHexString("0x0000000000000000000000000000000000001234"));
smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(true);
config = new PermissioningConfiguration(Optional.empty(), Optional.of(smartContractPermissioningConfiguration), Optional.empty());
NodePermissioningControllerFactory factory = new NodePermissioningControllerFactory();
NodePermissioningController controller = factory.create(config, synchronizer, fixedNodes, selfEnode.getNodeId(), transactionSimulator, new NoOpMetricsSystem(), blockchain, Collections.emptyList());
assertThat(controller.getSyncStatusNodePermissioningProvider()).isPresent();
}
Aggregations