Search in sources :

Example 11 with Hbar

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

the class ScheduleCreateIntegrationTest method canCreateWithSchedule.

@Test
@Disabled
@DisplayName("Can create schedule with schedule()")
void canCreateWithSchedule() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var key = PrivateKey.generateED25519();
    var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10));
    var tx = transaction.schedule();
    var response = tx.setAdminKey(testEnv.operatorKey).setPayerAccountId(testEnv.operatorId).execute(testEnv.client);
    var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId);
    var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client);
    assertThat(info.executedAt).isNotNull();
    assertThat(info.getScheduledTransaction()).isNotNull();
    testEnv.close();
}
Also used : Hbar(com.hedera.hashgraph.sdk.Hbar) ScheduleInfoQuery(com.hedera.hashgraph.sdk.ScheduleInfoQuery) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName) Disabled(org.junit.jupiter.api.Disabled)

Example 12 with Hbar

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

the class TokenMintIntegrationTest method cannotMintTokensWhenSupplyKeyDoesNotSignTransaction.

@Test
@DisplayName("Cannot mint tokens when supply key does not sign transaction")
void cannotMintTokensWhenSupplyKeyDoesNotSignTransaction() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var tokenId = Objects.requireNonNull(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(key).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TokenMintTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_SIGNATURE.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with Hbar

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

the class TokenNftTransferIntegrationTest method canTransferNfts.

@Test
@DisplayName("Can transfer NFTs")
void canTransferNfts() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = response.getReceipt(testEnv.client).accountId;
    assertThat(accountId).isNotNull();
    response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client);
    var tokenId = response.getReceipt(testEnv.client).tokenId;
    assertThat(tokenId).isNotNull();
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 10)).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = new ArrayList<Long>(mintReceipt.serials.subList(0, 4));
    var transfer = new TransferTransaction();
    for (var serial : serialsToTransfer) {
        transfer.addNftTransfer(tokenId.nft(serial), testEnv.operatorId, accountId);
    }
    transfer.execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ArrayList(java.util.ArrayList) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with Hbar

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

the class TokenRevokeKycIntegrationTest method canRevokeKycAccountWithToken.

@Test
@DisplayName("Can revoke kyc to account with token")
void canRevokeKycAccountWithToken() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var tokenId = Objects.requireNonNull(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(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenRevokeKycTransaction().setAccountId(accountId).setTokenId(tokenId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) TokenRevokeKycTransaction(com.hedera.hashgraph.sdk.TokenRevokeKycTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with Hbar

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

the class TokenRevokeKycIntegrationTest method cannotRevokeKycToAccountOnTokenWhenTokenIDIsNotSet.

@Test
@DisplayName("Cannot revoke kyc to account on token when token ID is not set")
void cannotRevokeKycToAccountOnTokenWhenTokenIDIsNotSet() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenRevokeKycTransaction().setAccountId(accountId).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_TOKEN_ID.toString());
    testEnv.close(accountId, key);
}
Also used : TokenRevokeKycTransaction(com.hedera.hashgraph.sdk.TokenRevokeKycTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Hbar (com.hedera.hashgraph.sdk.Hbar)106 Test (org.junit.jupiter.api.Test)77 DisplayName (org.junit.jupiter.api.DisplayName)75 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)62 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)34 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)31 Client (com.hedera.hashgraph.sdk.Client)22 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)22 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)19 Var (com.google.errorprone.annotations.Var)18 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 AccountId (com.hedera.hashgraph.sdk.AccountId)15 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)13 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)13 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)12 AccountInfoQuery (com.hedera.hashgraph.sdk.AccountInfoQuery)11 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)11 TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)11 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)9 ScheduleInfoQuery (com.hedera.hashgraph.sdk.ScheduleInfoQuery)9