Search in sources :

Example 21 with EntityId

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());
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) Test(org.junit.jupiter.api.Test)

Example 22 with EntityId

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);
    }
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId)

Example 23 with EntityId

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));
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) SystemUndeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemUndeleteTransactionBody) FileID(com.hederahashgraph.api.proto.java.FileID)

Example 24 with EntityId

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);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) Test(org.junit.jupiter.api.Test)

Example 25 with EntityId

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();
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) TopicID(com.hederahashgraph.api.proto.java.TopicID) Arrays(java.util.Arrays) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) EntityId(com.hedera.services.state.submerkle.EntityId) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) SelfSerializable(com.swirlds.common.io.SelfSerializable) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) RequestBuilder(com.hederahashgraph.builder.RequestBuilder) REVERTED_SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REVERTED_SUCCESS) CommonUtils(com.swirlds.common.CommonUtils) TxnId(com.hedera.services.state.submerkle.TxnId) ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) CommonUtils.getNormalisedStringFromBytes(com.swirlds.common.CommonUtils.getNormalisedStringFromBytes) TxnId(com.hedera.services.state.submerkle.TxnId) ByteString(com.google.protobuf.ByteString)

Aggregations

EntityId (com.hedera.services.state.submerkle.EntityId)35 Test (org.junit.jupiter.api.Test)18 MerkleToken (com.hedera.services.state.merkle.MerkleToken)9 RichInstant (com.hedera.services.state.submerkle.RichInstant)6 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)5 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)5 TxnId (com.hedera.services.state.submerkle.TxnId)4 EntityNum (com.hedera.services.utils.EntityNum)4 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)4 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)3 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)3 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)3 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)3 ScheduleStore (com.hedera.services.store.schedule.ScheduleStore)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 ByteString (com.google.protobuf.ByteString)2 JKeyList (com.hedera.services.legacy.core.jproto.JKeyList)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)2 DomainSerdes (com.hedera.services.state.serdes.DomainSerdes)2