Search in sources :

Example 1 with Node

use of org.hyperledger.besu.tests.acceptance.dsl.node.Node in project besu by hyperledger.

the class AccountLocalAndOnchainPermissioningAcceptanceTest method testAccountCannotSendTxWhenNotOnOnchainAllowList.

@Test
public void testAccountCannotSendTxWhenNotOnOnchainAllowList() {
    // Onchain allowlist: Primary, Secondary, Receiver
    // Local allowlist: Primary, Secondary, C, Receiver
    final Account receiverAccount = accounts.createAccount("Rec-A");
    final Node node = permissionedNode("node1", Arrays.asList(accounts.getPrimaryBenefactor().getAddress(), accounts.getSecondaryBenefactor().getAddress(), senderC.getAddress(), receiverAccount.getAddress()));
    permissionedCluster.start(node);
    // ensure SenderC has got some ether available
    node.execute(accountTransactions.createTransfer(senderC, 10));
    node.verify(senderC.balanceEquals(10));
    // add accounts to onchain allowlist
    node.execute(allowAccount(accounts.getPrimaryBenefactor()));
    node.verify(accountIsAllowed(accounts.getPrimaryBenefactor()));
    node.execute(allowAccount(accounts.getSecondaryBenefactor()));
    node.verify(accountIsAllowed(accounts.getSecondaryBenefactor()));
    node.execute(allowAccount(receiverAccount));
    node.verify(accountIsAllowed(receiverAccount));
    // verify senderC is forbidden because it is not on Onchain allowlist
    node.verify(accountIsForbidden(senderC));
    // sender C should not be able to send Tx
    verifyTransferForbidden(node, senderC, accounts.getSecondaryBenefactor());
    // final check, other account should be able to send tx
    node.execute(accountTransactions.createTransfer(accounts.getPrimaryBenefactor(), receiverAccount, 5));
    node.verify(receiverAccount.balanceEquals(5));
}
Also used : Account(org.hyperledger.besu.tests.acceptance.dsl.account.Account) Node(org.hyperledger.besu.tests.acceptance.dsl.node.Node) Test(org.junit.Test)

Example 2 with Node

use of org.hyperledger.besu.tests.acceptance.dsl.node.Node in project besu by hyperledger.

the class Cluster method start.

public void start(final List<? extends RunnableNode> nodes) {
    if (nodes.isEmpty()) {
        throw new IllegalArgumentException("Can't start a cluster with no nodes");
    }
    this.originalNodes = nodes;
    this.nodes.clear();
    this.bootnodes.clear();
    nodes.forEach(node -> this.nodes.put(node.getName(), node));
    final Optional<? extends RunnableNode> bootnode = selectAndStartBootnode(nodes);
    nodes.parallelStream().filter(node -> {
        LOG.info("starting non-bootnode {}", node.getName());
        return bootnode.map(boot -> boot != node).orElse(true);
    }).forEach(this::startNode);
    if (clusterConfiguration.isAwaitPeerDiscovery()) {
        for (final RunnableNode node : nodes) {
            LOG.info("Awaiting peer discovery for node {}, expecting {} peers", node.getName(), nodes.size() - 1);
            node.awaitPeerDiscovery(net.awaitPeerCount(nodes.size() - 1));
        }
    }
    LOG.info("Cluster startup complete.");
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) BesuNodeRunner(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNodeRunner) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode) Map(java.util.Map) Optional(java.util.Optional) NetConditions(org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions) URI(java.net.URI) Node(org.hyperledger.besu.tests.acceptance.dsl.node.Node) Condition(org.hyperledger.besu.tests.acceptance.dsl.condition.Condition) RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode)

Example 3 with Node

use of org.hyperledger.besu.tests.acceptance.dsl.node.Node in project besu by hyperledger.

the class Web3JSupportAcceptanceTest method setUp.

@Before
public void setUp() throws Exception {
    socketPath = Files.createTempFile("besu-test-", ".ipc");
    node = besu.createNode("node1", (configurationBuilder) -> configurationBuilder.jsonRpcIpcConfiguration(new JsonRpcIpcConfiguration(true, socketPath, Collections.singletonList(RpcApis.NET.name()))));
    cluster.start(node);
}
Also used : AcceptanceTestBase(org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase) Files(java.nio.file.Files) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RpcApis(org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis) IOException(java.io.IOException) Test(org.junit.Test) Request(org.web3j.protocol.core.Request) UnixIpcService(org.web3j.protocol.ipc.UnixIpcService) Assertions.fail(org.assertj.core.api.Assertions.fail) Web3j(org.web3j.protocol.Web3j) JsonRpcIpcConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration) Locale(java.util.Locale) NetVersion(org.web3j.protocol.core.methods.response.NetVersion) Assume.assumeTrue(org.junit.Assume.assumeTrue) Node(org.hyperledger.besu.tests.acceptance.dsl.node.Node) Path(java.nio.file.Path) Collections(java.util.Collections) Before(org.junit.Before) JsonRpcIpcConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration) Before(org.junit.Before)

Example 4 with Node

use of org.hyperledger.besu.tests.acceptance.dsl.node.Node in project besu by hyperledger.

the class AccountLocalAndOnchainPermissioningAcceptanceTest method testAccountCannotSendTxWhenNotOnLocalAllowList.

@Test
public void testAccountCannotSendTxWhenNotOnLocalAllowList() {
    // Onchain allowlist: Primary, Secondary, C
    // Local allowlist: Primary, Secondary
    final Node node = permissionedNode("node1", Arrays.asList(accounts.getPrimaryBenefactor().getAddress(), accounts.getSecondaryBenefactor().getAddress()));
    permissionedCluster.start(node);
    // ensure SenderC has got some ether available
    node.execute(accountTransactions.createTransfer(senderC, 10));
    node.verify(senderC.balanceEquals(10));
    // add accounts to onchain allowlist
    node.execute(allowAccount(accounts.getPrimaryBenefactor()));
    node.verify(accountIsAllowed(accounts.getPrimaryBenefactor()));
    node.execute(allowAccount(accounts.getSecondaryBenefactor()));
    node.verify(accountIsAllowed(accounts.getSecondaryBenefactor()));
    node.execute(allowAccount(senderC));
    node.verify(accountIsAllowed(senderC));
    // sender C should not be able to send Tx
    verifyTransferForbidden(node, senderC, accounts.getSecondaryBenefactor());
}
Also used : Node(org.hyperledger.besu.tests.acceptance.dsl.node.Node) Test(org.junit.Test)

Aggregations

Node (org.hyperledger.besu.tests.acceptance.dsl.node.Node)4 Test (org.junit.Test)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 IOException (java.io.IOException)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 RpcApis (org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis)1 JsonRpcIpcConfiguration (org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration)1