use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class HederaWorldStateTest method updaterGetsHederaTokenAccount.
@Test
void updaterGetsHederaTokenAccount() {
givenNonNullWorldLedgers();
final var zeroAddress = EntityIdUtils.accountIdFromEvmAddress(Address.ZERO.toArray());
final var updater = subject.updater();
// and:
given(entityAccess.isTokenAccount(EntityIdUtils.asTypedEvmAddress(zeroAddress))).willReturn(true);
given(dynamicProperties.isRedirectTokenCallsEnabled()).willReturn(true);
// and:
final var expected = subject.new WorldStateAccount(Address.ZERO, Wei.of(0), 0, 0, new EntityId());
// when:
final var result = updater.getHederaAccount(Address.ZERO);
// then:
assertEquals(expected.getAddress(), result.getAddress());
assertEquals(expected.getBalance(), result.getBalance());
assertEquals(expected.getProxyAccount(), result.getProxyAccount());
assertEquals(expected.getExpiry(), result.getExpiry());
assertEquals(-1, result.getNonce());
assertEquals(TOKEN_CALL_REDIRECT_CONTRACT_BINARY_WITH_ZERO_ADDRESS, result.getCode());
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class HederaWorldStateTest method givenWellKnownAccountWithCode.
private void givenWellKnownAccountWithCode(final AccountID account, final Bytes bytecode) {
given(entityAccess.getProxy(account)).willReturn(new EntityId(0, 0, 1));
given(entityAccess.getBalance(account)).willReturn(balance);
given(entityAccess.getAutoRenew(account)).willReturn(100L);
given(entityAccess.isExtant(any())).willReturn(true);
given(entityAccess.isDeleted(any())).willReturn(false);
if (bytecode != null) {
given(entityAccess.fetchCodeIfPresent(any())).willReturn(bytecode);
}
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class FileSysUndelTransitionLogicTest method givenTxnCtxSysUndeleting.
private void givenTxnCtxSysUndeleting(TargetType type, OldExpiryType expiryType) {
SystemUndeleteTransactionBody.Builder op = SystemUndeleteTransactionBody.newBuilder();
FileID id = null;
switch(type) {
case VALID:
op.setFileID(undeleted);
id = undeleted;
break;
case MISSING:
op.setFileID(missing);
id = missing;
break;
case DELETED:
op.setFileID(deleted);
id = deleted;
break;
}
EntityId entity = EntityId.fromGrpcFileId(id);
switch(expiryType) {
case NONE:
given(oldExpiries.containsKey(entity)).willReturn(false);
given(oldExpiries.get(entity)).willReturn(null);
break;
case FUTURE:
given(oldExpiries.containsKey(entity)).willReturn(true);
given(oldExpiries.get(entity)).willReturn(oldFutureExpiry);
break;
case PAST:
given(oldExpiries.containsKey(entity)).willReturn(true);
given(oldExpiries.get(entity)).willReturn(oldPastExpiry);
break;
}
txnId = TransactionID.newBuilder().setTransactionValidStart(MiscUtils.asTimestamp(Instant.ofEpochSecond(Instant.now().getEpochSecond()))).build();
fileSysUndelTxn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(180)).setSystemUndelete(op).build();
given(accessor.getTxn()).willReturn(fileSysUndelTxn);
given(txnCtx.accessor()).willReturn(accessor);
given(txnCtx.consensusTime()).willReturn(Instant.ofEpochSecond(now));
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class ScheduleExecutorTest method triggersIfCanMarkAsExecuted.
@Test
void triggersIfCanMarkAsExecuted() throws InvalidProtocolBufferException {
given(txnCtx.consensusTime()).willReturn(consensusNow);
given(store.markAsExecuted(id, consensusNow)).willReturn(OK);
given(store.get(id)).willReturn(schedule);
given(schedule.asSignedTxn()).willReturn(Transaction.getDefaultInstance());
given(schedule.effectivePayer()).willReturn(new EntityId(0, 0, 4321));
// when:
var result = subject.processExecution(id, store, txnCtx);
// then:
verify(txnCtx).trigger(any());
// and:
Assertions.assertEquals(OK, result);
}
use of com.hedera.services.state.submerkle.EntityId in project hedera-services by hashgraph.
the class TxnReceipt method fromGrpc.
/* --- Helpers --- */
public static TxnReceipt fromGrpc(TransactionReceipt grpc) {
final var effRates = grpc.hasExchangeRate() ? ExchangeRates.fromGrpc(grpc.getExchangeRate()) : null;
String status = grpc.getStatus() != null ? grpc.getStatus().name() : null;
EntityId accountId = grpc.hasAccountID() ? EntityId.fromGrpcAccountId(grpc.getAccountID()) : null;
EntityId jFileID = grpc.hasFileID() ? EntityId.fromGrpcFileId(grpc.getFileID()) : null;
EntityId jContractID = grpc.hasContractID() ? EntityId.fromGrpcContractId(grpc.getContractID()) : null;
EntityId topicId = grpc.hasTopicID() ? EntityId.fromGrpcTopicId(grpc.getTopicID()) : null;
EntityId tokenId = grpc.hasTokenID() ? EntityId.fromGrpcTokenId(grpc.getTokenID()) : null;
EntityId scheduleId = grpc.hasScheduleID() ? EntityId.fromGrpcScheduleId(grpc.getScheduleID()) : null;
long runningHashVersion = Math.max(MISSING_RUNNING_HASH_VERSION, grpc.getTopicRunningHashVersion());
long newTotalSupply = grpc.getNewTotalSupply();
long[] serialNumbers = grpc.getSerialNumbersList().stream().mapToLong(l -> l).toArray();
TxnId scheduledTxnId = grpc.hasScheduledTransactionID() ? TxnId.fromGrpc(grpc.getScheduledTransactionID()) : MISSING_SCHEDULED_TXN_ID;
return TxnReceipt.newBuilder().setStatus(status).setAccountId(accountId).setFileId(jFileID).setContractId(jContractID).setTokenId(tokenId).setScheduleId(scheduleId).setExchangeRates(effRates).setTopicId(topicId).setTopicSequenceNumber(grpc.getTopicSequenceNumber()).setTopicRunningHash(grpc.getTopicRunningHash().toByteArray()).setRunningHashVersion(runningHashVersion).setNewTotalSupply(newTotalSupply).setScheduledTxnId(scheduledTxnId).setSerialNumbers(serialNumbers).build();
}
Aggregations