Search in sources :

Example 1 with Account

use of org.hyperledger.besu.tests.acceptance.dsl.account.Account in project besu by hyperledger.

the class CreateAccountAcceptanceTest method shouldCreateAnAccount.

@Test
public void shouldCreateAnAccount() {
    final Account account = accounts.createAccount("account-one");
    final Amount balance = Amount.ether(20);
    minerNode.execute(accountTransactions.createTransfer(account, balance));
    cluster.verify(account.balanceEquals(balance));
}
Also used : Account(org.hyperledger.besu.tests.acceptance.dsl.account.Account) Amount(org.hyperledger.besu.tests.acceptance.dsl.blockchain.Amount) Test(org.junit.Test)

Example 2 with Account

use of org.hyperledger.besu.tests.acceptance.dsl.account.Account 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 3 with Account

use of org.hyperledger.besu.tests.acceptance.dsl.account.Account in project besu by hyperledger.

the class AccountLocalConfigPermissioningAcceptanceTest method onlyAllowedAccountCanSubmitTransactions.

@Test
public void onlyAllowedAccountCanSubmitTransactions() {
    Account beneficiary = accounts.createAccount("beneficiary");
    node.execute(accountTransactions.createTransfer(senderA, beneficiary, 1));
    node.verify(beneficiary.balanceEquals(1));
    verifyTransferForbidden(senderB, beneficiary);
}
Also used : Account(org.hyperledger.besu.tests.acceptance.dsl.account.Account) Test(org.junit.Test)

Example 4 with Account

use of org.hyperledger.besu.tests.acceptance.dsl.account.Account in project besu by hyperledger.

the class BftBlockRewardPaymentAcceptanceTest method validatorsArePaidBlockReward.

@Test
public void validatorsArePaidBlockReward() throws Exception {
    final String[] validators = { "validator" };
    final BesuNode validator = nodeFactory.createNodeWithValidators(besu, "validator", validators);
    final BesuNode nonValidator = nodeFactory.createNodeWithValidators(besu, "nonValidator", validators);
    cluster.start(validator, nonValidator);
    final Account validator1Account = Account.create(ethTransactions, validator.getAddress());
    final int blockRewardEth = 5;
    final int blockToCheck = 2;
    cluster.verify(validator1Account.balanceAtBlockEquals(Amount.ether(0), BigInteger.ZERO));
    cluster.verify(validator1Account.balanceAtBlockEquals(Amount.ether(blockRewardEth * blockToCheck), BigInteger.valueOf(blockToCheck)));
}
Also used : BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) Account(org.hyperledger.besu.tests.acceptance.dsl.account.Account) Test(org.junit.Test)

Example 5 with Account

use of org.hyperledger.besu.tests.acceptance.dsl.account.Account in project besu by hyperledger.

the class BftBlockRewardPaymentAcceptanceTest method testMiningBeneficiaryTransitions.

private void testMiningBeneficiaryTransitions(final Optional<Address> initialMiningBeneficiary, final Map<Long, Optional<Address>> miningBeneficiaryTransitions) throws Exception {
    final String[] validators = { "validator1" };
    final BesuNode validator1 = nodeFactory.createNodeWithValidators(besu, "validator1", validators);
    final Optional<String> initialConfig = validator1.getGenesisConfigProvider().create(singletonList(validator1));
    if (initialConfig.isEmpty()) {
        throw new RuntimeException("Unable to generate genesis config.");
    }
    final String miningBeneficiary = initialMiningBeneficiary.map(Address::toHexString).orElse("");
    final String bftOptions = formatKeyValues("miningbeneficiary", miningBeneficiary);
    final String configWithMiningBeneficiary = configureBftOptions(initialConfig.get(), bftOptions, miningBeneficiaryTransitions);
    validator1.setGenesisConfig(configWithMiningBeneficiary);
    cluster.start(validator1);
    // Check that expected address receive block reward at each block
    final NavigableMap<Long, Optional<Address>> orderedTransitions = new TreeMap<>(miningBeneficiaryTransitions);
    final long lastConfiguredBlock = orderedTransitions.lastKey();
    final Map<Address, Amount> accountBalances = new HashMap<>();
    for (long i = 1; i < lastConfiguredBlock + 2; i++) {
        final Address beneficiaryAddress = Optional.ofNullable(orderedTransitions.floorEntry(i)).flatMap(Entry::getValue).orElse(validator1.getAddress());
        final Account beneficiary = Account.create(ethTransactions, beneficiaryAddress);
        final Amount currentBalance = accountBalances.computeIfAbsent(beneficiaryAddress, __ -> Amount.wei(BigInteger.ZERO));
        cluster.verify(beneficiary.balanceAtBlockEquals(currentBalance, BigInteger.valueOf(i - 1)));
        final Amount newBalance = currentBalance.add(BLOCK_REWARD);
        cluster.verify(beneficiary.balanceAtBlockEquals(newBalance, BigInteger.valueOf(i)));
        accountBalances.put(beneficiaryAddress, newBalance);
    }
}
Also used : Account(org.hyperledger.besu.tests.acceptance.dsl.account.Account) Optional(java.util.Optional) Address(org.hyperledger.besu.datatypes.Address) HashMap(java.util.HashMap) Amount(org.hyperledger.besu.tests.acceptance.dsl.blockchain.Amount) TreeMap(java.util.TreeMap) BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode)

Aggregations

Account (org.hyperledger.besu.tests.acceptance.dsl.account.Account)22 Test (org.junit.Test)21 BesuNode (org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode)13 Amount (org.hyperledger.besu.tests.acceptance.dsl.blockchain.Amount)4 Hash (org.hyperledger.besu.datatypes.Hash)3 TransferTransaction (org.hyperledger.besu.tests.acceptance.dsl.transaction.account.TransferTransaction)2 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 SECP256R1 (org.hyperledger.besu.crypto.SECP256R1)1 Address (org.hyperledger.besu.datatypes.Address)1 Node (org.hyperledger.besu.tests.acceptance.dsl.node.Node)1