use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class HapiQueryOp method opDef.
private Consumer<TransactionBody.Builder> opDef(HapiApiSpec spec, long amount) throws Throwable {
TransferList transfers = asTransferList(tinyBarsFromTo(amount, spec.registry().getAccountID(effectivePayer(spec)), targetNodeFor(spec)));
CryptoTransferTransactionBody opBody = spec.txns().<CryptoTransferTransactionBody, CryptoTransferTransactionBody.Builder>body(CryptoTransferTransactionBody.class, b -> b.setTransfers(transfers));
return b -> b.setCryptoTransfer(opBody);
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ValidationScenarios method updatePaymentCsv.
private static HapiApiSpec updatePaymentCsv() {
ensureScenarios();
if (scenarios.getFeeSnapshots() == null) {
scenarios.setFeeSnapshots(new FeeSnapshotsScenario());
}
var feeSnapshots = scenarios.getFeeSnapshots();
try {
return customHapiSpec("UpdatePaymentCsv").withProperties(Map.of("nodes", nodes(), "default.payer", primaryPayer(), "default.node", defaultNode(), "fees.useFixedOffer", "true", "fees.fixedOffer", "" + FEE_TO_OFFER, "startupAccounts.literal", payerKeystoreLiteral())).given().when().then(withOpContext((spec, opLog) -> {
var payments = HapiApiSpec.costSnapshotFrom("cost-snapshots/fees/ValidationScenarios-FeeSnapshots-costs.properties");
var network = params.getTargetNetwork();
var feesCsvLoc = String.format("fees/%s-fees.csv", network);
var csvFile = new File(feesCsvLoc);
if (!feeSnapshots.getAppendToSnapshotCsv() || !csvFile.exists()) {
createInitialFeesCsv(feesCsvLoc, payments, feeSnapshots);
} else {
appendToFeesCsv(feesCsvLoc, payments, feeSnapshots);
}
}));
} catch (Exception e) {
log.warn("Unable to ensure fee snapshots bytecode, skipping it!", e);
errorsOccurred.set(true);
return null;
}
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ValidationScenarios method ensureBytecode.
private static HapiApiSpec ensureBytecode() {
ensureScenarios();
if (scenarios.getFeeSnapshots() == null) {
scenarios.setFeeSnapshots(new FeeSnapshotsScenario());
}
var feeSnapshots = scenarios.getFeeSnapshots();
try {
return customHapiSpec("EnsureBytecodeForFeeSnapshots").withProperties(Map.of("nodes", nodes(), "default.payer", primaryPayer(), "default.node", defaultNode(), "fees.useFixedOffer", "true", "fees.fixedOffer", "" + FEE_TO_OFFER, "startupAccounts.literal", payerKeystoreLiteral())).given().when().then(withOpContext((spec, opLog) -> {
if (feeSnapshots.getOpsConfig().getBytecode() == null) {
var bytecodeCreate = fileCreate("unusedName").path(ContractResources.MULTIPURPOSE_BYTECODE_PATH);
allRunFor(spec, bytecodeCreate);
feeSnapshots.getOpsConfig().setBytecode(bytecodeCreate.numOfCreatedFile());
}
}));
} catch (Exception e) {
log.warn("Unable to ensure fee snapshots bytecode, skipping it!", e);
errorsOccurred.set(true);
return null;
}
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ValidationScenarios method fileScenario.
private static HapiApiSpec fileScenario() {
try {
ensureScenarios();
if (scenarios.getFile() == null) {
var fs = new FileScenario();
fs.setPersistent(new PersistentFile());
scenarios.setFile(fs);
}
var file = scenarios.getFile();
return customHapiSpec("FileScenario").withProperties(Map.of("nodes", nodes(), "default.payer", primaryPayer(), "default.node", defaultNode(), "fees.useFixedOffer", "true", "fees.fixedOffer", "" + FEE_TO_OFFER, "startupAccounts.literal", payerKeystoreLiteral())).given(keyFromPem(() -> pemForAccount(targetNetwork().getScenarioPayer())).name(SCENARIO_PAYER_NAME).linkedTo(() -> String.format("0.0.%d", targetNetwork().getScenarioPayer())), ensureValidatedFileExistence(PERSISTENT_FILE_NAME, file.getPersistent().getContents(), pemForFile(persistentOrNegativeOne(file).getAsLong()), persistentOrNegativeOne(file), num -> file.getPersistent().setNum(num), loc -> file.getPersistent().setContents(loc))).when().then(novelFileIfDesired());
} catch (Exception e) {
log.warn("Unable to initialize file scenario, skipping it!", e);
errorsOccurred.set(true);
return null;
}
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ValidationScenarios method contractScenario.
private static HapiApiSpec contractScenario() {
try {
ensureScenarios();
if (scenarios.getContract() == null) {
var cs = new ContractScenario();
cs.setPersistent(new PersistentContract());
scenarios.setContract(cs);
}
var contract = scenarios.getContract();
Object[] donationArgs = new Object[] { Integer.valueOf((int) targetNetwork().getBootstrap()), "Hey, Ma!" };
return customHapiSpec("ContractScenario").withProperties(Map.of("nodes", nodes(), "default.payer", primaryPayer(), "default.node", defaultNode(), "fees.useFixedOffer", "true", "fees.fixedOffer", "" + FEE_TO_OFFER, "startupAccounts.literal", payerKeystoreLiteral())).given(keyFromPem(() -> pemForAccount(targetNetwork().getScenarioPayer())).name(SCENARIO_PAYER_NAME).linkedTo(() -> String.format("0.0.%d", targetNetwork().getScenarioPayer())), ensureValidatedContractExistence(PERSISTENT_CONTRACT_NAME, contract.getPersistent().getLuckyNo(), contract.getPersistent().getSource(), pemForContract(persistentContractOrNegativeOne(contract).getAsLong()), persistentContractOrNegativeOne(contract), num -> contract.getPersistent().setNum(num), bytecodeNum -> contract.getPersistent().setBytecode(bytecodeNum), luckyNo -> contract.getPersistent().setLuckyNo(luckyNo), loc -> contract.getPersistent().setSource(loc))).when(flattened(contractCall(PERSISTENT_CONTRACT_NAME).payingWith(SCENARIO_PAYER_NAME).setNodeFrom(ValidationScenarios::nextNode).sending(1L), contractCall(PERSISTENT_CONTRACT_NAME, ContractResources.CONSPICUOUS_DONATION_ABI, donationArgs).payingWith(SCENARIO_PAYER_NAME).setNodeFrom(ValidationScenarios::nextNode).via("donation"), getTxnRecord("donation").payingWith(SCENARIO_PAYER_NAME).setNodeFrom(ValidationScenarios::nextNode).logged().hasPriority(recordWith().transfers(includingDeduction(contract.getPersistent()::getNum, 1))), novelContractIfDesired(contract))).then();
} catch (Exception e) {
log.warn("Unable to initialize contract scenario, skipping it!", e);
errorsOccurred.set(true);
return null;
}
}
Aggregations