use of com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CREATE_FACTORY_GET_BYTECODE_ABI in project hedera-services by hashgraph.
the class DynamicGasCostSuite method inlineCreateCanFailSafely.
private HapiApiSpec inlineCreateCanFailSafely() {
final var tcValue = 1_234L;
final var creation = "creation";
final var initcode = "initcode";
final var inlineCreateFactory = "inlineCreateFactory";
final int foo = 22;
final int timesToFail = 7;
final AtomicLong factoryEntityNum = new AtomicLong();
final AtomicReference<String> factoryEvmAddress = new AtomicReference<>();
final AtomicReference<byte[]> testContractInitcode = new AtomicReference<>();
return defaultHapiSpec("InlineCreateCanFailSafely").given(overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(REVERTING_CREATE_FACTORY_PATH), contractCreate(inlineCreateFactory).payingWith(GENESIS).bytecode(initcode).via(creation).exposingNumTo(num -> {
factoryEntityNum.set(num);
factoryEvmAddress.set(asHexedSolidityAddress(0, 0, num));
})).when(sourcing(() -> contractCallLocal(inlineCreateFactory, CREATE_FACTORY_GET_BYTECODE_ABI, factoryEvmAddress.get(), foo).exposingTypedResultsTo(results -> {
final var tcInitcode = (byte[]) results[0];
testContractInitcode.set(tcInitcode);
log.info("Contract reported TestContract initcode is {} bytes", tcInitcode.length);
}).payingWith(GENESIS).nodePayment(ONE_HBAR))).then(inParallel(IntStream.range(0, timesToFail).mapToObj(i -> sourcing(() -> contractCall(inlineCreateFactory, NORMAL_DEPLOY_ABI, testContractInitcode.get()).payingWith(GENESIS).gas(4_000_000L).sending(tcValue).via(creation))).toArray(HapiSpecOperation[]::new)), sourcing(() -> cryptoCreate("nextUp").exposingCreatedIdTo(id -> log.info("Next entity num was {} instead of expected {}", id.getAccountNum(), factoryEntityNum.get() + 1))));
}
Aggregations