use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class ScheduleExecutionSpecs method scheduledXferFailingWithFrozenAccountTransferPaysServiceFeeButNoImpact.
private HapiApiSpec scheduledXferFailingWithFrozenAccountTransferPaysServiceFeeButNoImpact() {
String xToken = "XXX";
String validSchedule = "withUnfrozenAccount";
String invalidSchedule = "withFrozenAccount";
String schedulePayer = "somebody", xTreasury = "xt", xCivilian = "xc";
String successTxn = "good", failedTxn = "bad";
AtomicReference<Map<AccountID, Long>> successFeesObs = new AtomicReference<>();
AtomicReference<Map<AccountID, Long>> failureFeesObs = new AtomicReference<>();
return defaultHapiSpec("ScheduledXferFailingWithFrozenAccountTransferPaysServiceFeeButNoImpact").given(newKeyNamed("freeze"), cryptoCreate(schedulePayer), cryptoCreate(xTreasury), cryptoCreate(xCivilian), tokenCreate(xToken).treasury(xTreasury).initialSupply(101).freezeKey("freeze").freezeDefault(true), tokenAssociate(xCivilian, xToken), tokenUnfreeze(xToken, xCivilian)).when(scheduleCreate(validSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian)).memo(randomUppercase(100))).via(successTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xCivilian).hasTokenBalance(xToken, 1), getTxnRecord(successTxn).scheduled().logged().revealingDebitsTo(successFeesObs::set), tokenFreeze(xToken, xCivilian), scheduleCreate(invalidSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian)).memo(randomUppercase(100))).via(failedTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer)).then(getTxnRecord(failedTxn).scheduled().hasPriority(recordWith().status(ACCOUNT_FROZEN_FOR_TOKEN)).revealingDebitsTo(failureFeesObs::set), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), assertionsHold((spec, opLog) -> assertBasicallyIdentical(successFeesObs.get(), failureFeesObs.get(), 1.0)));
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class MigrationValidationPreSteps method migrationPreservesEntitiesPreStep.
/**
* Builds a spec in which it...
* 1. create a File with some contents
* 2. create a couple of crypto accounts and do some transaction between them
* 3. create a smart contract and call it a few times.
*
* @return the spec.
*/
private HapiApiSpec migrationPreservesEntitiesPreStep() {
return defaultHapiSpec("migrationPreservesEntitiesPreStep").given(UtilVerbs.blockingOrder(doFileActions()), UtilVerbs.blockingOrder(doCryptoActions()), UtilVerbs.blockingOrder(doSmartContractActions())).when().then(QueryVerbs.getFileInfo(MIGRATION_FILE).logged().saveToRegistry("migrationFile"), QueryVerbs.getFileContents(MIGRATION_FILE).logged(), QueryVerbs.getAccountInfo(MIGRATION_ACCOUNT_A).logged().savingSnapshot("migrationAccountA"), QueryVerbs.getAccountInfo(MIGRATION_ACCOUNT_B).logged().savingSnapshot("migrationAccountB"), QueryVerbs.getContractInfo(MIGRATION_SMART_CONTRACT).logged().saveToRegistry("migrationContract"), UtilVerbs.withOpContext((spec, ctxLog) -> {
FileWriter fw = null;
try {
fw = new FileWriter("src/main/resource/migration_config_default.properties");
AccountID id = spec.setup().genesisAccount();
String tmpId = asEntityId(id.getRealmNum(), id.getShardNum(), id.getAccountNum());
fw.write("default.payer=" + tmpId + "\n");
FileGetInfoResponse.FileInfo fileInfo = spec.registry().getFileInfo("migrationFile");
tmpId = asEntityId(fileInfo.getFileID().getRealmNum(), fileInfo.getFileID().getShardNum(), fileInfo.getFileID().getFileNum());
fw.write("migration.file.id=" + tmpId + "\n");
CryptoGetInfoResponse.AccountInfo accountInfoA = spec.registry().getAccountInfo("migrationAccountA");
CryptoGetInfoResponse.AccountInfo accountInfoB = spec.registry().getAccountInfo("migrationAccountB");
tmpId = asEntityId(accountInfoA.getAccountID().getRealmNum(), accountInfoA.getAccountID().getShardNum(), accountInfoA.getAccountID().getAccountNum());
fw.write("migration.crypto.AccountA.id=" + tmpId + "\n");
tmpId = asEntityId(accountInfoB.getAccountID().getRealmNum(), accountInfoB.getAccountID().getShardNum(), accountInfoB.getAccountID().getAccountNum());
fw.write("migration.crypto.AccountB.id=" + tmpId + "\n");
ContractGetInfoResponse.ContractInfo contractInfo = spec.registry().getContractInfo("migrationContract");
tmpId = asEntityId(contractInfo.getContractID().getRealmNum(), contractInfo.getContractID().getShardNum(), contractInfo.getContractID().getContractNum());
fw.write("migration.smartContract.id=" + tmpId + "\n");
fw.write("nodes=" + spec.setup().nodes().stream().map(NodeConnectInfo::uri).collect(Collectors.joining(" ")));
fw.flush();
} catch (IOException e) {
ctxLog.warn("Something wrong with File operation: {} ", e);
} catch (Exception e) {
ctxLog.warn("Unexpected error: {}", e);
} finally {
fw.close();
}
})).saveContext(true);
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class ScheduleExecutionSpecs method scheduledXferFailingWithEmptyTokenTransferAccountAmountsPaysServiceFeeButNoImpact.
private HapiApiSpec scheduledXferFailingWithEmptyTokenTransferAccountAmountsPaysServiceFeeButNoImpact() {
String xToken = "XXX", yToken = "YYY";
String validSchedule = "withNonEmptyTransfers";
String invalidSchedule = "withEmptyTransfer";
String schedulePayer = "somebody", xTreasury = "xt", yTreasury = "yt", xyCivilian = "xyt";
String successTxn = "good", failedTxn = "bad";
AtomicReference<Map<AccountID, Long>> successFeesObs = new AtomicReference<>();
AtomicReference<Map<AccountID, Long>> failureFeesObs = new AtomicReference<>();
return defaultHapiSpec("ScheduledXferFailingWithEmptyTokenTransferAccountAmountsPaysServiceFeeButNoImpact").given(cryptoCreate(schedulePayer), cryptoCreate(xTreasury), cryptoCreate(yTreasury), cryptoCreate(xyCivilian), tokenCreate(xToken).treasury(xTreasury).initialSupply(101), tokenCreate(yToken).treasury(yTreasury).initialSupply(101), tokenAssociate(xTreasury, yToken), tokenAssociate(yTreasury, xToken)).when(scheduleCreate(validSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, yTreasury), moving(1, yToken).between(yTreasury, xTreasury))).via(successTxn).alsoSigningWith(xTreasury, yTreasury, schedulePayer).designatingPayer(schedulePayer), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xTreasury).hasTokenBalance(yToken, 1), getAccountBalance(yTreasury).hasTokenBalance(yToken, 100), getAccountBalance(yTreasury).hasTokenBalance(xToken, 1), getTxnRecord(successTxn).scheduled().logged().revealingDebitsTo(successFeesObs::set), scheduleCreate(invalidSchedule, cryptoTransfer(moving(2, xToken).distributing(xTreasury, yTreasury, xyCivilian)).withEmptyTokenTransfers(yToken)).via(failedTxn).alsoSigningWith(xTreasury, yTreasury, schedulePayer).designatingPayer(schedulePayer)).then(getTxnRecord(failedTxn).scheduled().hasPriority(recordWith().status(EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS)).revealingDebitsTo(failureFeesObs::set), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xTreasury).hasTokenBalance(yToken, 1), getAccountBalance(yTreasury).hasTokenBalance(yToken, 100), getAccountBalance(yTreasury).hasTokenBalance(xToken, 1), assertionsHold((spec, opLog) -> assertBasicallyIdentical(successFeesObs.get(), failureFeesObs.get(), 1.0)));
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class ScheduleExecutionSpecs method scheduledXferFailingWithDeletedTokenPaysServiceFeeButNoImpact.
private HapiApiSpec scheduledXferFailingWithDeletedTokenPaysServiceFeeButNoImpact() {
String xToken = "XXX";
String validSchedule = "withLiveToken";
String invalidSchedule = "withDeletedToken";
String schedulePayer = "somebody", xTreasury = "xt", xCivilian = "xc";
String successTxn = "good", failedTxn = "bad";
AtomicReference<Map<AccountID, Long>> successFeesObs = new AtomicReference<>();
AtomicReference<Map<AccountID, Long>> failureFeesObs = new AtomicReference<>();
return defaultHapiSpec("ScheduledXferFailingWithDeletedTokenPaysServiceFeeButNoImpact").given(newKeyNamed("admin"), cryptoCreate(schedulePayer), cryptoCreate(xTreasury), cryptoCreate(xCivilian), tokenCreate(xToken).treasury(xTreasury).initialSupply(101).adminKey("admin"), tokenAssociate(xCivilian, xToken)).when(scheduleCreate(validSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian)).memo(randomUppercase(100))).via(successTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xCivilian).hasTokenBalance(xToken, 1), getTxnRecord(successTxn).scheduled().logged().revealingDebitsTo(successFeesObs::set), tokenDelete(xToken), scheduleCreate(invalidSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian)).memo(randomUppercase(100))).via(failedTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer)).then(getTxnRecord(failedTxn).scheduled().hasPriority(recordWith().status(TOKEN_WAS_DELETED)).revealingDebitsTo(failureFeesObs::set), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), assertionsHold((spec, opLog) -> assertBasicallyIdentical(successFeesObs.get(), failureFeesObs.get(), 1.0)));
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class StateView method infoForAccount.
public Optional<CryptoGetInfoResponse.AccountInfo> infoForAccount(final AccountID id, final AliasManager aliasManager) {
final var accountEntityNum = id.getAlias().isEmpty() ? fromAccountId(id) : aliasManager.lookupIdBy(id.getAlias());
final var account = accounts().get(accountEntityNum);
if (account == null) {
return Optional.empty();
}
final AccountID accountID = id.getAlias().isEmpty() ? id : accountEntityNum.toGrpcAccountId();
final var info = CryptoGetInfoResponse.AccountInfo.newBuilder().setLedgerId(networkInfo.ledgerId()).setKey(asKeyUnchecked(account.getAccountKey())).setAccountID(accountID).setAlias(account.getAlias()).setReceiverSigRequired(account.isReceiverSigRequired()).setDeleted(account.isDeleted()).setMemo(account.getMemo()).setAutoRenewPeriod(Duration.newBuilder().setSeconds(account.getAutoRenewSecs())).setBalance(account.getBalance()).setExpirationTime(Timestamp.newBuilder().setSeconds(account.getExpiry())).setContractAccountID(asHexedEvmAddress(accountID)).setOwnedNfts(account.getNftsOwned()).setMaxAutomaticTokenAssociations(account.getMaxAutomaticAssociations());
Optional.ofNullable(account.getProxy()).map(EntityId::toGrpcAccountId).ifPresent(info::setProxyAccountID);
final var tokenRels = tokenRelsFn.apply(this, accountEntityNum);
if (!tokenRels.isEmpty()) {
info.addAllTokenRelationships(tokenRels);
}
setAllowancesIfAny(info, account);
return Optional.of(info.build());
}
Aggregations