@Test
  public void toSize() {
    TransactionTestFixture preparedTx =
        prepareTransaction(
            TransactionType.ACCESS_LIST,
            10,
            Wei.of(500),
            Wei.ZERO,
            10,
            0,
            BlobType.KZG_PROOF,
            null);
    Transaction txTo =
        preparedTx.to(Optional.of(Address.extract(Bytes32.random()))).createTransaction(KEYS1);
    BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
    txTo.writeTo(rlpOut);

    txTo = Transaction.readFrom(new BytesValueRLPInput(rlpOut.encoded(), false)).detachedCopy();
    System.out.println(txTo.getSender());
    System.out.println(txTo.getHash());
    System.out.println(txTo.getSize());

    Optional<Address> to = txTo.getTo();
    final ClassLayout cl = ClassLayout.parseInstance(to);
    System.out.println(cl.toPrintable());
    LongAdder size = new LongAdder();
    size.add(cl.instanceSize());
    System.out.println(size);

    GraphVisitor gv =
        gpr -> {
          size.add(gpr.size());
          System.out.println(
              "("
                  + size
                  + ")["
                  + gpr.size()
                  + ", "
                  + gpr.path()
                  + ", "
                  + gpr.klass().toString()
                  + "]");
          System.out.println(ClassLayout.parseClass(gpr.klass()).toPrintable());
        };

    GraphWalker gw = new GraphWalker(gv);

    gw.walk(to);

    System.out.println("Optional To size: " + size);

    assertThat(size.sum()).isEqualTo(OPTIONAL_TO_SIZE);
  }
Field which value is dynamic and can only be calculated at runtime
ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/PendingTransactionEstimatedMemorySizeTest.java