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);
}
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));
}
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);
}
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);
}
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();
}
Aggregations