use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class DissociatePrecompileSuite method dissociatePrecompileHasExpectedSemanticsForDeletedTokens.
/* -- Not specifically required in the HTS Precompile Test Plan -- */
public HapiApiSpec dissociatePrecompileHasExpectedSemanticsForDeletedTokens() {
final String tbdUniqToken = "UniqToBeDeleted";
final String zeroBalanceFrozen = "0bFrozen";
final String zeroBalanceUnfrozen = "0bUnfrozen";
final String nonZeroBalanceFrozen = "1bFrozen";
final String nonZeroBalanceUnfrozen = "1bUnfrozen";
final long initialSupply = 100L;
final long nonZeroXfer = 10L;
final var firstMeta = ByteString.copyFrom("FIRST".getBytes(StandardCharsets.UTF_8));
final var secondMeta = ByteString.copyFrom("SECOND".getBytes(StandardCharsets.UTF_8));
final var thirdMeta = ByteString.copyFrom("THIRD".getBytes(StandardCharsets.UTF_8));
final AtomicReference<AccountID> accountID = new AtomicReference<>();
final AtomicReference<AccountID> treasuryID = new AtomicReference<>();
final AtomicReference<AccountID> zeroBalanceFrozenID = new AtomicReference<>();
final AtomicReference<AccountID> zeroBalanceUnfrozenID = new AtomicReference<>();
final AtomicReference<AccountID> nonZeroBalanceFrozenID = new AtomicReference<>();
final AtomicReference<AccountID> nonZeroBalanceUnfrozenID = new AtomicReference<>();
final AtomicReference<TokenID> tbdTokenID = new AtomicReference<>();
final AtomicReference<TokenID> tbdUniqueTokenID = new AtomicReference<>();
return defaultHapiSpec("DissociatePrecompileHasExpectedSemanticsForDeletedTokens").given(newKeyNamed(MULTI_KEY), cryptoCreate(ACCOUNT).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(accountID::set), fileCreate(THE_CONTRACT), updateLargeFile(ACCOUNT, THE_CONTRACT, extractByteCode(ContractResources.ASSOCIATE_DISSOCIATE_CONTRACT)), cryptoCreate(TOKEN_TREASURY).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(treasuryID::set), tokenCreate(TBD_TOKEN).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(initialSupply).treasury(TOKEN_TREASURY).freezeKey(MULTI_KEY).freezeDefault(true).exposingCreatedIdTo(id -> tbdTokenID.set(asToken(id))), tokenCreate(tbdUniqToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(0).exposingCreatedIdTo(id -> tbdUniqueTokenID.set(asToken(id))), cryptoCreate(zeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceFrozenID::set), cryptoCreate(zeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceUnfrozenID::set), cryptoCreate(nonZeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceFrozenID::set), cryptoCreate(nonZeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceUnfrozenID::set)).when(withOpContext((spec, opLog) -> allRunFor(spec, contractCreate(THE_CONTRACT).bytecode(THE_CONTRACT).gas(GAS_TO_OFFER), tokenAssociate(zeroBalanceFrozen, TBD_TOKEN), tokenAssociate(zeroBalanceUnfrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceFrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceUnfrozen, TBD_TOKEN), mintToken(tbdUniqToken, List.of(firstMeta, secondMeta, thirdMeta)), getAccountInfo(TOKEN_TREASURY).hasOwnedNfts(3), tokenUnfreeze(TBD_TOKEN, zeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceFrozen), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceFrozen)), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceUnfrozen)), tokenFreeze(TBD_TOKEN, nonZeroBalanceFrozen), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer), tokenDelete(TBD_TOKEN), tokenDelete(tbdUniqToken), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceFrozenTxn"), getTxnRecord("dissociateZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceFrozenTxn"), getTxnRecord("dissociateNonZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateNonZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(treasuryID.get()), asAddress(tbdUniqueTokenID.get())).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).payingWith(TOKEN_TREASURY)))).then(childRecordsCheck("dissociateZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), getAccountInfo(zeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(zeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(TOKEN_TREASURY).hasToken(relationshipWith(TBD_TOKEN)).hasNoTokenRelationship(tbdUniqToken).hasOwnedNfts(0), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer));
}
Aggregations