use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.
the class CryptoTransferLoadTest method runCryptoTransfers.
protected HapiApiSpec runCryptoTransfers() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
Supplier<HapiSpecOperation[]> transferBurst = () -> {
String sender = "sender";
String receiver = "receiver";
if (settings.getTotalAccounts() > 2) {
int s = r.nextInt(settings.getTotalAccounts());
int re = 0;
do {
re = r.nextInt(settings.getTotalAccounts());
} while (re == s);
sender = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + s);
receiver = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + re);
}
return new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromTo(sender, receiver, 1L)).noLogging().payingWith(sender).signedBy(GENESIS).suppressStats(true).fee(100_000_000L).hasKnownStatusFrom(SUCCESS, OK, INSUFFICIENT_PAYER_BALANCE, UNKNOWN, TRANSACTION_EXPIRED, INSUFFICIENT_ACCOUNT_BALANCE).hasRetryPrecheckFrom(BUSY, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
};
return defaultHapiSpec("RunCryptoTransfers").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(cryptoCreate("sender").balance(ignore -> settings.getInitialBalance()).payingWith(GENESIS).withRecharging().key(GENESIS).rechargeWindow(3).logging().hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), cryptoCreate("receiver").payingWith(GENESIS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).key(GENESIS).logging()).then(defaultLoadTest(transferBurst, settings), getAccountBalance("sender").logged());
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.
the class SysFilesUpdate method updateTargetFromHumanReadable.
private HapiApiSpec updateTargetFromHumanReadable() {
byte[] bytes = new byte[0];
String nodesOverride = envNodes();
System.out.println("Targeting " + nodesOverride);
String loc = humanReadableFileNames.get(target);
String readableFile = qualifiedPath(nodesOverride, loc, false);
try {
if (BOOK_FILES.contains(target)) {
AddressBookPojo pojoBook = mapper.readValue(new File(readableFile), AddressBookPojo.class);
var addressBook = NodeAddressBook.newBuilder();
pojoBook.getEntries().stream().flatMap(updateConverters.get(target)).forEach(addressBook::addNodeAddress);
bytes = addressBook.build().toByteArray();
} else if (target == SystemFile.EXCHANGE_RATES) {
var pojoRates = mapper.readValue(new File(readableFile), ExchangeRatesPojo.class);
bytes = pojoRates.toProto().toByteArray();
} else if (target == SystemFile.FEE_SCHEDULE) {
final var literal = java.nio.file.Files.readString(Paths.get(readableFile));
bytes = FeesJsonToProtoSerde.parseFeeScheduleFromJson(literal).toByteArray();
} else {
var jutilConfig = new Properties();
jutilConfig.load(java.nio.file.Files.newInputStream(Paths.get(readableFile)));
ServicesConfigurationList.Builder protoConfig = ServicesConfigurationList.newBuilder();
jutilConfig.stringPropertyNames().stream().sorted(JutilPropsToSvcCfgBytes.LEGACY_THROTTLES_FIRST_ORDER).forEach(prop -> protoConfig.addNameValue(Setting.newBuilder().setName(prop).setValue(jutilConfig.getProperty(prop))));
bytes = protoConfig.build().toByteArray();
}
} catch (Exception e) {
System.out.println(String.format("File '%s' should contain a human-readable %s representation!", readableFile, target.toString()));
e.printStackTrace();
System.exit(1);
}
final byte[] toUpload = bytes;
return customHapiSpec(String.format("Update-%s-FromHumanReadable", target)).withProperties(Map.of("nodes", nodesOverride, "default.payer", defaultPayerOverride, "startupAccounts.path", startupAccountsPathOverride)).given(withOpContext((spec, opLog) -> {
var sysFileOcKeystore = SpecUtils.asOcKeystore(new File(DEFAULT_SYSFILE_PEM_LOC), KeyFactory.PEM_PASSPHRASE);
var sysFileKey = Key.newBuilder().setEd25519(ByteString.copyFrom(com.swirlds.common.CommonUtils.unhex(sysFileOcKeystore.getPublicKeyAbyteStr()))).build();
opLog.info("Will ensure default public key :: " + sysFileKey + " (hex = " + sysFileOcKeystore.getPublicKeyAbyteStr() + ")");
spec.registry().saveKey(DEFAULT_SYSFILE_KEY, sysFileKey);
spec.keys().incorporate(DEFAULT_SYSFILE_KEY, sysFileOcKeystore);
}), keyFromPem(DEFAULT_SYSFILE_PEM_LOC).name("insurance").simpleWacl().passphrase(KeyFactory.PEM_PASSPHRASE)).when().then(withOpContext((spec, opLog) -> {
if (toUpload.length < (6 * 1024)) {
var singleOp = fileUpdate(registryNames.get(target)).payingWith(DEFAULT_PAYER).fee(feeToOffer()).contents(toUpload).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY);
CustomSpecAssert.allRunFor(spec, singleOp);
} else {
int n = 0;
while (n < toUpload.length) {
int thisChunkSize = Math.min(toUpload.length - n, 4096);
byte[] thisChunk = Arrays.copyOfRange(toUpload, n, n + thisChunkSize);
HapiSpecOperation subOp;
if (n == 0) {
subOp = fileUpdate(registryNames.get(target)).fee(feeToOffer()).wacl("insurance").contents(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
} else {
subOp = fileAppend(registryNames.get(target)).fee(feeToOffer()).content(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
}
CustomSpecAssert.allRunFor(spec, subOp);
n += thisChunkSize;
}
}
}));
}
Aggregations