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());
}
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<>());
}
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());
}
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<>());
}
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<>());
}
Aggregations