Search in sources :

Example 1 with TokenAllowance

use of com.hederahashgraph.api.proto.java.TokenAllowance in project hedera-services by hashgraph.

the class CryptoAdjustAllowanceTransitionLogicTest method doesntDoAnythingIfAmountZeroForNonExistingKey.

@Test
void doesntDoAnythingIfAmountZeroForNonExistingKey() {
    final CryptoAllowance cryptoAllowance1 = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(0L).build();
    final TokenAllowance tokenAllowance1 = TokenAllowance.newBuilder().setSpender(spender1).setAmount(0L).setTokenId(token1).build();
    cryptoAdjustAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoAdjustAllowance(CryptoAdjustAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(List.of(cryptoAllowance1)).addAllTokenAllowances(List.of(tokenAllowance1))).build();
    given(accessor.getTxn()).willReturn(cryptoAdjustAllowanceTxn);
    given(txnCtx.accessor()).willReturn(accessor);
    given(accountStore.loadAccount(ownerAcccount.getId())).willReturn(ownerAcccount);
    subject.doStateTransition();
    assertEquals(0, ownerAcccount.getCryptoAllowances().size());
    assertEquals(0, ownerAcccount.getFungibleTokenAllowances().size());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance) Test(org.junit.jupiter.api.Test)

Example 2 with TokenAllowance

use of com.hederahashgraph.api.proto.java.TokenAllowance in project hedera-services by hashgraph.

the class CryptoApproveAllowanceTransitionLogicTest method givenValidTxnCtxWithOwnerAsPayer.

private void givenValidTxnCtxWithOwnerAsPayer() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    final CryptoAllowance cryptoAllowance1 = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(10L).build();
    final TokenAllowance tokenAllowance1 = TokenAllowance.newBuilder().setSpender(spender1).setAmount(10L).setTokenId(token1).build();
    final NftAllowance nftAllowance1 = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(true)).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    payerAcccount.setNftAllowances(new HashMap<>());
    payerAcccount.setCryptoAllowances(new HashMap<>());
    payerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Example 3 with TokenAllowance

use of com.hederahashgraph.api.proto.java.TokenAllowance in project hedera-services by hashgraph.

the class ApproveAllowanceChecksTest method missingOwnerDefaultsToPayer.

@Test
void missingOwnerDefaultsToPayer() {
    setupNeeded();
    final CryptoAllowance cryptoAllowance1 = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(10L).build();
    final TokenAllowance tokenAllowance1 = TokenAllowance.newBuilder().setSpender(spender1).setAmount(10L).setTokenId(token1).build();
    final NftAllowance nftAllowance1 = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.clear();
    tokenAllowances.clear();
    nftAllowances.clear();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateCryptoAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getCryptoAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllTokenAllowances(tokenAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateFungibleTokenAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getTokenAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllNftAllowances(nftAllowances)).build();
    op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    assertEquals(OK, subject.validateNftAllowances(cryptoApproveAllowanceTxn.getCryptoApproveAllowance().getNftAllowancesList(), payerAccount));
    verify(accountStore, never()).loadAccount(any());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) Test(org.junit.jupiter.api.Test)

Example 4 with TokenAllowance

use of com.hederahashgraph.api.proto.java.TokenAllowance in project hedera-services by hashgraph.

the class CryptoAdjustAllowanceTransitionLogicTest method givenTxnCtxWithZeroAmount.

private void givenTxnCtxWithZeroAmount() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    List<Long> serials = new ArrayList<>();
    serials.add(-12L);
    serials.add(-10L);
    final CryptoAllowance cryptoAllowance = CryptoAllowance.newBuilder().setSpender(spender1).setAmount(-20L).build();
    final TokenAllowance tokenAllowance = TokenAllowance.newBuilder().setSpender(spender1).setAmount(-10L).setTokenId(token1).build();
    final NftAllowance nftAllowance = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).addAllSerialNumbers(serials).build();
    cryptoAllowances.add(cryptoAllowance);
    tokenAllowances.add(tokenAllowance);
    nftAllowances.add(nftAllowance);
    cryptoAdjustAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoAdjustAllowance(CryptoAdjustAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    ownerAcccount.setNftAllowances(new HashMap<>());
    ownerAcccount.setCryptoAllowances(new HashMap<>());
    ownerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) ArrayList(java.util.ArrayList) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Example 5 with TokenAllowance

use of com.hederahashgraph.api.proto.java.TokenAllowance in project hedera-services by hashgraph.

the class CryptoApproveAllowanceTransitionLogicTest method givenTxnCtxWithZeroAmount.

private void givenTxnCtxWithZeroAmount() {
    token1Model.setMaxSupply(5000L);
    token1Model.setType(TokenType.FUNGIBLE_COMMON);
    token2Model.setMaxSupply(5000L);
    token2Model.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    final CryptoAllowance cryptoAllowance = CryptoAllowance.newBuilder().setOwner(ownerId).setSpender(spender1).setAmount(0L).build();
    final TokenAllowance tokenAllowance = TokenAllowance.newBuilder().setSpender(spender1).setAmount(0L).setTokenId(token1).setOwner(ownerId).build();
    final NftAllowance nftAllowance = NftAllowance.newBuilder().setSpender(spender1).setTokenId(token2).setApprovedForAll(BoolValue.of(false)).setOwner(ownerId).addAllSerialNumbers(List.of(1L, 10L)).build();
    cryptoAllowances.add(cryptoAllowance1);
    tokenAllowances.add(tokenAllowance1);
    nftAllowances.add(nftAllowance1);
    cryptoAllowances.add(cryptoAllowance);
    tokenAllowances.add(tokenAllowance);
    nftAllowances.add(nftAllowance);
    cryptoApproveAllowanceTxn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setCryptoApproveAllowance(CryptoApproveAllowanceTransactionBody.newBuilder().addAllCryptoAllowances(cryptoAllowances).addAllTokenAllowances(tokenAllowances).addAllNftAllowances(nftAllowances)).build();
    ownerAcccount.setNftAllowances(new HashMap<>());
    ownerAcccount.setCryptoAllowances(new HashMap<>());
    ownerAcccount.setFungibleTokenAllowances(new HashMap<>());
}
Also used : CryptoAllowance(com.hederahashgraph.api.proto.java.CryptoAllowance) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TokenAllowance(com.hederahashgraph.api.proto.java.TokenAllowance) FcTokenAllowance(com.hedera.services.state.submerkle.FcTokenAllowance)

Aggregations

CryptoAllowance (com.hederahashgraph.api.proto.java.CryptoAllowance)5 TokenAllowance (com.hederahashgraph.api.proto.java.TokenAllowance)5 FcTokenAllowance (com.hedera.services.state.submerkle.FcTokenAllowance)4 NftAllowance (com.hederahashgraph.api.proto.java.NftAllowance)4 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1