use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY 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