-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '666b834a3038dd3d4b78523e57c91b4dae51dd15'
- Loading branch information
Showing
31 changed files
with
764 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
sdk/src/integrationTest/java/AccountAllowanceIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import com.hedera.hashgraph.sdk.AccountAllowanceApproveTransaction; | ||
import com.hedera.hashgraph.sdk.AccountBalanceQuery; | ||
import com.hedera.hashgraph.sdk.AccountCreateTransaction; | ||
import com.hedera.hashgraph.sdk.AccountDeleteTransaction; | ||
import com.hedera.hashgraph.sdk.AccountInfoQuery; | ||
import com.hedera.hashgraph.sdk.Hbar; | ||
import com.hedera.hashgraph.sdk.PrivateKey; | ||
import com.hedera.hashgraph.sdk.Status; | ||
import com.hedera.hashgraph.sdk.TransactionId; | ||
import com.hedera.hashgraph.sdk.TransactionRecordQuery; | ||
import com.hedera.hashgraph.sdk.TransferTransaction; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class AccountAllowanceIntegrationTest { | ||
@Test | ||
@Disabled | ||
@DisplayName("Can spend hbar allowance") | ||
// TODO: this currently is not passing, and I don't know why. | ||
void canSpendHbarAllowance() throws Throwable { | ||
var testEnv = new IntegrationTestEnv(1); | ||
|
||
var aliceKey = PrivateKey.generateED25519(); | ||
var aliceId = new AccountCreateTransaction() | ||
.setKey(aliceKey) | ||
.setInitialBalance(new Hbar(10)) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client) | ||
.accountId; | ||
|
||
var bobKey = PrivateKey.generateED25519(); | ||
var bobId = new AccountCreateTransaction() | ||
.setKey(bobKey) | ||
.setInitialBalance(new Hbar(10)) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client) | ||
.accountId; | ||
|
||
Objects.requireNonNull(aliceId); | ||
Objects.requireNonNull(bobId); | ||
|
||
var allowanceTx = new AccountAllowanceApproveTransaction() | ||
.addHbarAllowance(aliceId, new Hbar(10)) | ||
.setTransactionId(TransactionId.generate(bobId)) | ||
.freezeWith(testEnv.client) | ||
.sign(bobKey); | ||
System.out.println(allowanceTx); | ||
allowanceTx | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client); | ||
|
||
var transferTx = new TransferTransaction() | ||
.addHbarTransfer(testEnv.operatorId, new Hbar(5)) | ||
.addHbarTransfer(bobId, new Hbar(5).negated()) | ||
.setHbarTransferApproval(bobId, true) | ||
.setTransactionId(TransactionId.generate(aliceId)) | ||
.freezeWith(testEnv.client) | ||
.sign(aliceKey); | ||
System.out.println(transferTx); | ||
var transferRecord = transferTx | ||
.execute(testEnv.client) | ||
.getRecord(testEnv.client); | ||
|
||
var transferFound = false; | ||
System.out.println(transferRecord); | ||
for (var transfer : transferRecord.transfers) { | ||
if (transfer.accountId.equals(testEnv.operatorId) && transfer.amount.equals(new Hbar(5))) { | ||
transferFound = true; | ||
break; | ||
} | ||
} | ||
assertTrue(transferFound); | ||
|
||
new AccountDeleteTransaction() | ||
.setAccountId(bobId) | ||
.freezeWith(testEnv.client) | ||
.sign(bobKey) | ||
.execute(testEnv.client) | ||
.getReceipt(testEnv.client); | ||
|
||
testEnv.close(aliceId, aliceKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.