use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN 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.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN in project hedera-services by hashgraph.
the class TokenAssociationSpecs method dissociationFromExpiredTokensAsExpected.
public HapiApiSpec dissociationFromExpiredTokensAsExpected() {
final String treasury = "accountA";
final String frozenAccount = "frozen";
final String unfrozenAccount = "unfrozen";
final String expiringToken = "expiringToken";
long lifetimeSecs = 10;
AtomicLong now = new AtomicLong();
return defaultHapiSpec("DissociationFromExpiredTokensAsExpected").given(newKeyNamed("freezeKey"), cryptoCreate(treasury), cryptoCreate(frozenAccount).via("creation"), cryptoCreate(unfrozenAccount).via("creation"), withOpContext((spec, opLog) -> {
var subOp = getTxnRecord("creation");
allRunFor(spec, subOp);
var record = subOp.getResponseRecord();
now.set(record.getConsensusTimestamp().getSeconds());
}), sourcing(() -> tokenCreate(expiringToken).freezeKey("freezeKey").freezeDefault(true).treasury(treasury).initialSupply(1000L).expiry(now.get() + lifetimeSecs))).when(tokenAssociate(unfrozenAccount, expiringToken), tokenAssociate(frozenAccount, expiringToken), tokenUnfreeze(expiringToken, unfrozenAccount), cryptoTransfer(moving(100L, expiringToken).between(treasury, unfrozenAccount))).then(getAccountBalance(treasury).hasTokenBalance(expiringToken, 900L), sleepFor(lifetimeSecs * 1_000L), tokenDissociate(treasury, expiringToken).hasKnownStatus(ACCOUNT_IS_TREASURY), tokenDissociate(unfrozenAccount, expiringToken).via("dissociateTxn"), getTxnRecord("dissociateTxn").hasPriority(recordWith().tokenTransfers(new BaseErroringAssertsProvider<>() {
@Override
public ErroringAsserts<List<TokenTransferList>> assertsFor(HapiApiSpec spec) {
return tokenXfers -> {
try {
assertEquals(1, tokenXfers.size(), "Wrong number of tokens transferred!");
TokenTransferList xfers = tokenXfers.get(0);
assertEquals(spec.registry().getTokenID(expiringToken), xfers.getToken(), "Wrong token transferred!");
AccountAmount toTreasury = xfers.getTransfers(0);
assertEquals(spec.registry().getAccountID(treasury), toTreasury.getAccountID(), "Treasury should come first!");
assertEquals(100L, toTreasury.getAmount(), "Treasury should get 100 tokens back!");
AccountAmount fromAccount = xfers.getTransfers(1);
assertEquals(spec.registry().getAccountID(unfrozenAccount), fromAccount.getAccountID(), "Account should come second!");
assertEquals(-100L, fromAccount.getAmount(), "Account should send 100 tokens back!");
} catch (Throwable error) {
return List.of(error);
}
return Collections.emptyList();
};
}
})), getAccountBalance(treasury).hasTokenBalance(expiringToken, 1000L), getAccountInfo(frozenAccount).hasToken(relationshipWith(expiringToken).freeze(Frozen)), tokenDissociate(frozenAccount, expiringToken).hasKnownStatus(ACCOUNT_FROZEN_FOR_TOKEN));
}
Aggregations