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));
}
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));
}
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);
}
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)));
}
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);
}
}
Aggregations