Search in sources :

Example 6 with TokenBurnTransaction

use of com.hedera.hashgraph.sdk.TokenBurnTransaction in project hedera-sdk-java by hashgraph.

the class TokenBurnIntegrationTest method cannotBurnTokensWhenSupplyKeyDoesNotSignTransaction.

@Test
@DisplayName("Cannot burn tokens when supply key does not sign transaction")
void cannotBurnTokensWhenSupplyKeyDoesNotSignTransaction() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(PrivateKey.generate()).setFreezeDefault(false).execute(testEnv.client);
    var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenBurnTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_SIGNATURE.toString());
    testEnv.close(tokenId);
}
Also used : TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenBurnTransaction(com.hedera.hashgraph.sdk.TokenBurnTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with TokenBurnTransaction

use of com.hedera.hashgraph.sdk.TokenBurnTransaction in project hedera-sdk-java by hashgraph.

the class TokenBurnIntegrationTest method cannotBurnNftsWhenNftIsNotOwned.

@Test
@DisplayName("Cannot burn NFTs when NFT is not owned by treasury")
void cannotBurnNftsWhenNftIsNotOwned() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var createReceipt = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client);
    var tokenId = Objects.requireNonNull(createReceipt.tokenId);
    var serials = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 1)).execute(testEnv.client).getReceipt(testEnv.client).serials;
    var key = PrivateKey.generateED25519();
    var accountId = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addNftTransfer(tokenId.nft(serials.get(0)), testEnv.operatorId, accountId).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenBurnTransaction().setSerials(serials).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.TREASURY_MUST_OWN_BURNED_NFT.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenBurnTransaction(com.hedera.hashgraph.sdk.TokenBurnTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TokenBurnTransaction (com.hedera.hashgraph.sdk.TokenBurnTransaction)7 Test (org.junit.jupiter.api.Test)5 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)3 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)2 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)2 DisplayName (org.junit.jupiter.api.DisplayName)2 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)1 Hbar (com.hedera.hashgraph.sdk.Hbar)1 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)1 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)1 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1