use of com.hedera.services.bdd.spec.HapiSpecOperation 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))));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class DynamicGasCostSuite method inlineCreate2CanFailSafely.
// https://github.com/hashgraph/hedera-services/issues/2868
private HapiApiSpec inlineCreate2CanFailSafely() {
final var tcValue = 1_234L;
final var creation = "creation";
final var initcode = "initcode";
final var inlineCreate2Factory = "inlineCreate2Factory";
final int foo = 22;
final int salt = 23;
final int timesToFail = 7;
final AtomicLong factoryEntityNum = new AtomicLong();
final AtomicReference<String> factoryEvmAddress = new AtomicReference<>();
final AtomicReference<byte[]> testContractInitcode = new AtomicReference<>();
return defaultHapiSpec("InlineCreate2CanFailSafely").given(overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(REVERTING_CREATE2_FACTORY_PATH), contractCreate(inlineCreate2Factory).payingWith(GENESIS).bytecode(initcode).via(creation).exposingNumTo(num -> {
factoryEntityNum.set(num);
factoryEvmAddress.set(asHexedSolidityAddress(0, 0, num));
})).when(sourcing(() -> contractCallLocal(inlineCreate2Factory, CREATE2_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(inlineCreate2Factory, CREATE2_FACTORY_DEPLOY_ABI, testContractInitcode.get(), salt).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))));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class ContractCreateSuite method canCallPendingContractSafely.
private HapiApiSpec canCallPendingContractSafely() {
final int numSlots = 64;
final int createBurstSize = 500;
final int[] targets = { 19, 24 };
final AtomicLong createdFileNum = new AtomicLong();
final var callTxn = "callTxn";
final var initcode = "initcode";
return defaultHapiSpec("CanCallPendingContractSafely").given(UtilVerbs.overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(FIBONACCI_PLUS_PATH).payingWith(GENESIS).exposingNumTo(createdFileNum::set), inParallel(IntStream.range(0, createBurstSize).mapToObj(i -> contractCreate("contract" + i, FIBONACCI_PLUS_CONSTRUCTOR_ABI, numSlots).fee(ONE_HUNDRED_HBARS).gas(300_000L).payingWith(GENESIS).noLogging().deferStatusResolution().bytecode(initcode).adminKey(THRESHOLD)).toArray(HapiSpecOperation[]::new))).when().then(sourcing(() -> contractCall("0.0." + (createdFileNum.get() + createBurstSize), ADD_NTH_FIB_ABI, targets, 12).payingWith(GENESIS).gas(300_000L).via(callTxn)), UtilVerbs.resetAppPropertiesTo("src/main/resource/bootstrap.properties"));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class RandomTokenTransfer method get.
@Override
public Optional<HapiSpecOperation> get() {
var xferRel = tokenRels.getQualifying();
if (xferRel.isEmpty()) {
return Optional.empty();
}
HapiSpecOperation op;
var rel = explicit(xferRel.get());
var token = rel.getRight();
if (BASE_RANDOM.nextBoolean()) {
op = cryptoTransfer(moving(1, token).between(spec -> spec.registry().getTreasury(token), ignore -> rel.getLeft())).hasPrecheckFrom(STANDARD_PERMISSIBLE_PRECHECKS).hasKnownStatusFrom(permissibleOutcomes);
} else {
op = cryptoTransfer(moving(1, token).between(ignore -> rel.getLeft(), spec -> spec.registry().getTreasury(token))).hasPrecheckFrom(STANDARD_PERMISSIBLE_PRECHECKS).hasKnownStatusFrom(permissibleOutcomes).showingResolvedStatus();
}
return Optional.of(op);
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class RandomContract method suggestedInitializers.
@Override
public List<HapiSpecOperation> suggestedInitializers() {
List<HapiSpecOperation> ops = new ArrayList<>();
for (SupportedContract choice : choices) {
HapiFileCreate op = fileCreate(fileFor(choice)).noLogging().path(choice.getPathToBytecode());
ops.add(op);
}
return ops;
}
Aggregations