@Test
  public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
    final long GAS_LIMIT = 1_000_000L;
    cluster.verify(authorizer.balanceEquals(Amount.ether(90_000)));

    final CodeDelegation codeDelegation =
        org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
            .chainId(BigInteger.valueOf(20211))
            .nonce(
                1L) // nonce is 1, but because it is validated before the nonce increase, it should
            // be 0
            .address(SEND_ALL_ETH_CONTRACT_ADDRESS)
            .signAndBuild(
                secp256k1.createKeyPair(
                    secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

    final Transaction tx =
        Transaction.builder()
            .type(TransactionType.DELEGATE_CODE)
            .chainId(BigInteger.valueOf(20211))
            .nonce(0)
            .maxPriorityFeePerGas(Wei.of(1_000_000_000))
            .maxFeePerGas(Wei.fromHexString("0x02540BE400"))
            .gasLimit(GAS_LIMIT)
            .to(Address.fromHexStringStrict(authorizer.getAddress()))
            .value(Wei.ZERO)
            .payload(Bytes32.leftPad(Bytes.fromHexString(otherAccount.getAddress())))
            .accessList(List.of())
            .codeDelegations(List.of(codeDelegation))
            .signAndBuild(
                secp256k1.createKeyPair(
                    secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

    final String txHash =
        besuNode.execute(ethTransactions.sendRawTransaction(tx.encoded().toHexString()));
    testHelper.buildNewBlock();

    final Optional<TransactionReceipt> maybeFirstTransactionReceipt =
        besuNode.execute(ethTransactions.getTransactionReceipt(txHash));
    assertThat(maybeFirstTransactionReceipt).isPresent();

    final String gasPriceWithout0x =
        maybeFirstTransactionReceipt.get().getEffectiveGasPrice().substring(2);
    final BigInteger gasPrice = new BigInteger(gasPriceWithout0x, 16);
    final BigInteger txCost = maybeFirstTransactionReceipt.get().getGasUsed().multiply(gasPrice);

    final BigInteger authorizerBalanceAfterFirstTx =
        besuNode.execute(ethTransactions.getBalance(authorizer));

    // The remaining balance of the authorizer should the gas limit multiplied by the gas price
    // minus the transaction cost.
    // The following executes this calculation in reverse.
    assertThat(GAS_LIMIT)
        .isEqualTo(authorizerBalanceAfterFirstTx.add(txCost).divide(gasPrice).longValue());

    // The other accounts balance should be the initial 9000 ETH balance from the authorizer minus
    // the remaining balance of the authorizer and minus the transaction cost
    final BigInteger otherAccountBalanceAfterFirstTx =
        new BigInteger("90000000000000000000000")
            .subtract(authorizerBalanceAfterFirstTx)
            .subtract(txCost);

    cluster.verify(otherAccount.balanceEquals(Amount.wei(otherAccountBalanceAfterFirstTx)));

    final Transaction txSendEthToOtherAccount =
        Transaction.builder()
            .type(TransactionType.EIP1559)
            .chainId(BigInteger.valueOf(20211))
            .nonce(2)
            .maxPriorityFeePerGas(Wei.of(10))
            .maxFeePerGas(Wei.of(100))
            .gasLimit(21_000)
            .to(Address.fromHexStringStrict(otherAccount.getAddress()))
            .value(Wei.ONE)
            .payload(Bytes.EMPTY)
            .signAndBuild(
                secp256k1.createKeyPair(
                    secp256k1.createPrivateKey(AUTHORIZER_PRIVATE_KEY.toUnsignedBigInteger())));

    final String txSendEthToOtherAccountHash =
        besuNode.execute(
            ethTransactions.sendRawTransaction(txSendEthToOtherAccount.encoded().toHexString()));
    testHelper.buildNewBlock();

    final Optional<TransactionReceipt> maybeSecondTransactionReceipt =
        besuNode.execute(ethTransactions.getTransactionReceipt(txSendEthToOtherAccountHash));
    assertThat(maybeSecondTransactionReceipt).isPresent();

    // the balance of the other account should be the previous balance plus the value of the 1 Wei
    final BigInteger otherAccountBalanceAfterSecondTx =
        besuNode.execute(ethTransactions.getBalance(otherAccount));
    assertThat(otherAccountBalanceAfterFirstTx.add(BigInteger.ONE))
        .isEqualTo(otherAccountBalanceAfterSecondTx);
  }
The authorizer creates an authorization for a contract that sends all its ETH to any given
address. The nonce is 1 and the authorization list is processed after the nonce increase of the
sender. Therefore, the authorization should be valid. The authorizer balance should be 0 and
the transaction sponsor's * balance should be 180000 ETH minus the transaction costs.
acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/ethereum/CodeDelegationTransactionAcceptanceTest.java