Search in sources :

Example 1 with Frozen

use of com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen 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));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ACCOUNT_IS_TREASURY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) StandardCharsets(java.nio.charset.StandardCharsets) NoTokenTransfers.emptyTokenTransfers(com.hedera.services.bdd.spec.assertions.NoTokenTransfers.emptyTokenTransfers) ByteString(com.google.protobuf.ByteString) BaseErroringAssertsProvider(com.hedera.services.bdd.spec.assertions.BaseErroringAssertsProvider) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) TxnVerbs.tokenDissociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDissociate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) KycNotApplicable(com.hederahashgraph.api.proto.java.TokenKycStatus.KycNotApplicable) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Granted(com.hederahashgraph.api.proto.java.TokenKycStatus.Granted) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) Unfrozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Unfrozen) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FreezeNotApplicable(com.hederahashgraph.api.proto.java.TokenFreezeStatus.FreezeNotApplicable) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ACCOUNT_FROZEN_FOR_TOKEN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) AtomicLong(java.util.concurrent.atomic.AtomicLong) ErroringAsserts(com.hedera.services.bdd.spec.assertions.ErroringAsserts) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ByteString(com.google.protobuf.ByteString) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Aggregations

ByteString (com.google.protobuf.ByteString)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)1 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)1 BaseErroringAssertsProvider (com.hedera.services.bdd.spec.assertions.BaseErroringAssertsProvider)1 ErroringAsserts (com.hedera.services.bdd.spec.assertions.ErroringAsserts)1 NoTokenTransfers.emptyTokenTransfers (com.hedera.services.bdd.spec.assertions.NoTokenTransfers.emptyTokenTransfers)1 SomeFungibleTransfers.changingFungibleBalances (com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances)1 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)1 ContractResources (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources)1 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)1 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)1 QueryVerbs.getContractInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo)1 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)1 ExpectedTokenRel.relationshipWith (com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith)1 TxnVerbs.contractCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate)1 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)1 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)1 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)1 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)1