Search in sources :

Example 26 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class ContextOptionValidatorTest method acceptsOk.

@Test
void acceptsOk() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.minusSeconds(validDuration - 1).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(OK, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 27 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class ContextOptionValidatorTest method recognizesFutureValidStartStart.

@Test
void recognizesFutureValidStartStart() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.plusSeconds(1L).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(INVALID_TRANSACTION_START, status);
    // and:
    assertEquals(INVALID_TRANSACTION_START, subject.chronologyStatusForTxn(validStart, validDuration, consensusTime));
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 28 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class CryptoDeleteTransitionLogicTest method rejectsIfTargetMissing.

@Test
void rejectsIfTargetMissing() {
    givenDeleteTxnMissingTarget();
    // when:
    ResponseCodeEnum validity = subject.semanticCheck().apply(cryptoDeleteTxn);
    // then:
    assertEquals(ACCOUNT_ID_DOES_NOT_EXIST, validity);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) Test(org.junit.jupiter.api.Test)

Example 29 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class CryptoDeleteTransitionLogicTest method rejectsIfTransferMissing.

@Test
void rejectsIfTransferMissing() {
    givenDeleteTxnMissingTransfer();
    // when:
    ResponseCodeEnum validity = subject.semanticCheck().apply(cryptoDeleteTxn);
    // then:
    assertEquals(ACCOUNT_ID_DOES_NOT_EXIST, validity);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) Test(org.junit.jupiter.api.Test)

Example 30 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class HederaTokenStore method update.

@Override
public ResponseCodeEnum update(final TokenUpdateTransactionBody changes, final long now) {
    final var tId = resolve(changes.getToken());
    if (tId == MISSING_TOKEN) {
        return INVALID_TOKEN_ID;
    }
    ResponseCodeEnum validity;
    final var isExpiryOnly = affectsExpiryAtMost(changes);
    validity = checkAutoRenewAccount(changes);
    if (validity != OK) {
        return validity;
    }
    final var newKycKey = changes.hasKycKey() ? asUsableFcKey(changes.getKycKey()) : Optional.empty();
    final var newWipeKey = changes.hasWipeKey() ? asUsableFcKey(changes.getWipeKey()) : Optional.empty();
    final var newSupplyKey = changes.hasSupplyKey() ? asUsableFcKey(changes.getSupplyKey()) : Optional.empty();
    final var newFreezeKey = changes.hasFreezeKey() ? asUsableFcKey(changes.getFreezeKey()) : Optional.empty();
    final var newFeeScheduleKey = changes.hasFeeScheduleKey() ? asUsableFcKey(changes.getFeeScheduleKey()) : Optional.empty();
    final var newPauseKey = changes.hasPauseKey() ? asUsableFcKey(changes.getPauseKey()) : Optional.empty();
    var appliedValidity = new AtomicReference<>(OK);
    apply(tId, token -> {
        processExpiry(appliedValidity, changes, token);
        processAutoRenewAccount(appliedValidity, changes, token);
        checkKeyOfType(appliedValidity, token.hasKycKey(), newKycKey.isPresent(), TOKEN_HAS_NO_KYC_KEY);
        checkKeyOfType(appliedValidity, token.hasFreezeKey(), newFreezeKey.isPresent(), TOKEN_HAS_NO_FREEZE_KEY);
        checkKeyOfType(appliedValidity, token.hasPauseKey(), newPauseKey.isPresent(), TOKEN_HAS_NO_PAUSE_KEY);
        checkKeyOfType(appliedValidity, token.hasWipeKey(), newWipeKey.isPresent(), TOKEN_HAS_NO_WIPE_KEY);
        checkKeyOfType(appliedValidity, token.hasSupplyKey(), newSupplyKey.isPresent(), TOKEN_HAS_NO_SUPPLY_KEY);
        checkKeyOfType(appliedValidity, token.hasAdminKey(), !isExpiryOnly, TOKEN_IS_IMMUTABLE);
        checkKeyOfType(appliedValidity, token.hasFeeScheduleKey(), newFeeScheduleKey.isPresent(), TOKEN_HAS_NO_FEE_SCHEDULE_KEY);
        if (OK != appliedValidity.get()) {
            return;
        }
        final var ret = checkNftBalances(token, tId, changes);
        if (ret != OK) {
            appliedValidity.set(ret);
            return;
        }
        updateAdminKeyIfAppropriate(token, changes);
        updateAutoRenewAccountIfAppropriate(token, changes);
        updateAutoRenewPeriodIfAppropriate(token, changes);
        updateKeyOfTypeIfAppropriate(changes.hasFreezeKey(), token::setFreezeKey, changes::getFreezeKey);
        updateKeyOfTypeIfAppropriate(changes.hasKycKey(), token::setKycKey, changes::getKycKey);
        updateKeyOfTypeIfAppropriate(changes.hasPauseKey(), token::setPauseKey, changes::getPauseKey);
        updateKeyOfTypeIfAppropriate(changes.hasSupplyKey(), token::setSupplyKey, changes::getSupplyKey);
        updateKeyOfTypeIfAppropriate(changes.hasWipeKey(), token::setWipeKey, changes::getWipeKey);
        updateKeyOfTypeIfAppropriate(changes.hasFeeScheduleKey(), token::setFeeScheduleKey, changes::getFeeScheduleKey);
        updateTokenSymbolIfAppropriate(token, changes);
        updateTokenNameIfAppropriate(token, changes);
        updateTreasuryIfAppropriate(token, changes, tId);
        updateMemoIfAppropriate(token, changes);
        updateExpiryIfAppropriate(token, changes);
    });
    return appliedValidity.get();
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)52 Test (org.junit.jupiter.api.Test)38 Query (com.hederahashgraph.api.proto.java.Query)24 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)8 AccountID (com.hederahashgraph.api.proto.java.AccountID)6 Response (com.hederahashgraph.api.proto.java.Response)6 CryptoGetAccountBalanceResponse (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 SignedTxnAccessor (com.hedera.services.utils.SignedTxnAccessor)3 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)3 ContractID (com.hederahashgraph.api.proto.java.ContractID)3 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)3 AliasManager (com.hedera.services.ledger.accounts.AliasManager)2 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)2 EntityNum (com.hedera.services.utils.EntityNum)2 TopicID (com.hederahashgraph.api.proto.java.TopicID)2 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)2 Instant (java.time.Instant)2 ByteString (com.google.protobuf.ByteString)1 EntityNumbers (com.hedera.services.config.EntityNumbers)1