use of com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method callForMintWithDelegateContractKey.
private HapiApiSpec callForMintWithDelegateContractKey() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var amount = 10L;
final var fungibleToken = "fungibleToken";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("callForMintWithDelegateContractKey").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, newKeyNamed("delegateContractKey").shape(DELEGATE_CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("delegateContractKey"), contractCall(theContract, MINT_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), amount, new byte[] {}).via(firstMintTxn).payingWith(theAccount))), childRecordsCheck(firstMintTxn, SUCCESS, recordWith().status(SUCCESS).tokenTransfers(changingFungibleBalances().including(fungibleToken, TOKEN_TREASURY, 10)).newTotalSupply(10)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
use of com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method tokenSupplyTransaction.
private Transaction tokenSupplyTransaction(TokenType tokenType, boolean mint) {
var serialNumbers = List.of(1L, 2L, 3L);
Transaction transaction = null;
if (mint) {
transaction = buildTransaction(builder -> {
builder.getTokenMintBuilder().setToken(TOKEN_ID);
if (tokenType == FUNGIBLE_COMMON) {
builder.getTokenMintBuilder().setAmount(10);
} else {
builder.getTokenMintBuilder().addAllMetadata(Collections.nCopies(serialNumbers.size(), ByteString.copyFromUtf8(METADATA)));
}
});
} else {
transaction = buildTransaction(builder -> {
builder.getTokenBurnBuilder().setToken(TOKEN_ID);
if (tokenType == FUNGIBLE_COMMON) {
builder.getTokenBurnBuilder().setAmount(10);
} else {
builder.getTokenBurnBuilder().addAllSerialNumbers(serialNumbers);
}
});
}
return transaction;
}
use of com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenDissociateDeletedFungibleToken.
@Test
void tokenDissociateDeletedFungibleToken() {
// given
createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
long tokenDeleteTimestamp = 15L;
Transaction deleteTransaction = tokenDeleteTransaction(TOKEN_ID);
insertAndParseTransaction(tokenDeleteTimestamp, deleteTransaction);
// when
Transaction dissociateTransaction = tokenDissociate(List.of(TOKEN_ID), PAYER2);
long dissociateTimeStamp = 20L;
TokenTransferList dissociateTransfer = tokenTransfer(TOKEN_ID, PAYER2, -10);
insertAndParseTransaction(dissociateTimeStamp, dissociateTransaction, builder -> builder.addTokenTransferLists(dissociateTransfer));
// then
assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, dissociateTimeStamp, SYMBOL, INITIAL_SUPPLY - 10);
var expected = domainBuilder.tokenTransfer().customize(t -> t.amount(-10).id(new TokenTransfer.Id(dissociateTimeStamp, EntityId.of(TOKEN_ID), EntityId.of(PAYER2))).isApproval(false).payerAccountId(EntityId.of(PAYER)).tokenDissociate(false)).get();
assertThat(tokenTransferRepository.findById(expected.getId())).get().isEqualTo(expected);
}
use of com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method callForMintWithContractKey.
private HapiApiSpec callForMintWithContractKey() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var amount = 10L;
final var fungibleToken = "fungibleToken";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("callForMintWithContractKey").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, newKeyNamed("contractKey").shape(CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("contractKey"), contractCall(theContract, MINT_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), amount, new byte[] {}).via(firstMintTxn).payingWith(theAccount))), childRecordsCheck(firstMintTxn, SUCCESS, recordWith().status(SUCCESS).tokenTransfers(changingFungibleBalances().including(fungibleToken, TOKEN_TREASURY, 10)).newTotalSupply(10)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
Aggregations