use of com.hedera.services.store.models.NftId in project hedera-services by hashgraph.
the class ApproveAllowanceChecksTest method setUpForTest.
private void setUpForTest() {
given(owner.getId()).willReturn(Id.fromGrpcAccount(ownerId1));
given(tokenStore.loadPossiblyPausedToken(token1Model.getId())).willReturn(token1Model);
given(tokenStore.loadPossiblyPausedToken(token2Model.getId())).willReturn(token2Model);
given(owner.isAssociatedWith(token1Model.getId())).willReturn(true);
given(owner.isAssociatedWith(token2Model.getId())).willReturn(true);
final NftId token1Nft1 = new NftId(0, 0, token2.getTokenNum(), 1L);
final NftId tokenNft2 = new NftId(0, 0, token2.getTokenNum(), 10L);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
}
use of com.hedera.services.store.models.NftId in project hedera-services by hashgraph.
the class ApproveAllowanceChecksTest method loadsOwnerAccountInNftNotDefaultingToPayer.
@Test
void loadsOwnerAccountInNftNotDefaultingToPayer() {
given(owner.getId()).willReturn(Id.fromGrpcAccount(ownerId1));
given(tokenStore.loadPossiblyPausedToken(token2Model.getId())).willReturn(token2Model);
given(owner.isAssociatedWith(token2Model.getId())).willReturn(true);
final NftId token1Nft1 = new NftId(0, 0, token2.getTokenNum(), 1L);
final NftId tokenNft2 = new NftId(0, 0, token2.getTokenNum(), 10L);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft1))).willReturn(true);
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft2))).willReturn(true);
given(owner.getId()).willReturn(Id.fromGrpcAccount(ownerId1));
given(accountStore.loadAccount(Id.fromGrpcAccount(ownerId1))).willReturn(owner);
getValidTxnCtx();
assertEquals(OK, subject.validateNftAllowances(op.getNftAllowancesList(), payerAccount));
verify(accountStore).loadAccount(Id.fromGrpcAccount(ownerId1));
given(accountStore.loadAccount(Id.fromGrpcAccount(ownerId1))).willThrow(InvalidTransactionException.class);
assertEquals(INVALID_ALLOWANCE_OWNER_ID, subject.validateNftAllowances(op.getNftAllowancesList(), payerAccount));
verify(accountStore, times(2)).loadAccount(Id.fromGrpcAccount(ownerId1));
}
use of com.hedera.services.store.models.NftId in project hedera-services by hashgraph.
the class ApproveAllowanceChecksTest method setupNeeded.
private void setupNeeded() {
given(tokenStore.loadPossiblyPausedToken(token1Model.getId())).willReturn(token1Model);
given(tokenStore.loadPossiblyPausedToken(token2Model.getId())).willReturn(token2Model);
final NftId token1Nft1 = new NftId(0, 0, token2.getTokenNum(), 1L);
final NftId tokenNft2 = new NftId(0, 0, token2.getTokenNum(), 10L);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId1));
given(payerAccount.getId()).willReturn(Id.fromGrpcAccount(payer));
given(tokenStore.loadPossiblyPausedToken(token1Model.getId())).willReturn(token1Model);
given(payerAccount.isAssociatedWith(token1Model.getId())).willReturn(true);
given(payerAccount.isAssociatedWith(token2Model.getId())).willReturn(true);
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft1))).willReturn(true);
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft2))).willReturn(true);
given(nftsMap.get(EntityNumPair.fromNftId(token2Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token2Nft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token2Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(payer));
given(nftsMap.get(EntityNumPair.fromNftId(token2Nft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(payer));
}
use of com.hedera.services.store.models.NftId in project hedera-services by hashgraph.
the class AdjustAllowanceChecksTest method fungibleInNFTAllowances.
@Test
void fungibleInNFTAllowances() {
given(payer.getId()).willReturn(Id.fromGrpcAccount(ownerId));
given(tokenStore.loadPossiblyPausedToken(token2Model.getId())).willReturn(token2Model);
given(tokenStore.loadPossiblyPausedToken(token1Model.getId())).willReturn(token1Model);
given(payer.isAssociatedWith(token2Model.getId())).willReturn(true);
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft1))).willReturn(true);
given(nftsMap.containsKey(EntityNumPair.fromNftId(token2Nft2))).willReturn(true);
final NftId token1Nft1 = new NftId(0, 0, token2.getTokenNum(), 1L);
final NftId tokenNft2 = new NftId(0, 0, token2.getTokenNum(), 10L);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId));
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId));
final var badNftAllowance = NftAllowance.newBuilder().setSpender(spender2).addAllSerialNumbers(List.of(1L)).setTokenId(token1).setOwner(ownerId).setApprovedForAll(BoolValue.of(false)).build();
nftAllowances.add(badNftAllowance);
assertEquals(FUNGIBLE_TOKEN_IN_NFT_ALLOWANCES, subject.validateNftAllowances(nftAllowances, payer));
}
use of com.hedera.services.store.models.NftId in project hedera-services by hashgraph.
the class AdjustAllowanceChecksTest method setUpForTest.
private void setUpForTest() {
given(payer.getId()).willReturn(Id.fromGrpcAccount(ownerId));
given(tokenStore.loadPossiblyPausedToken(token1Model.getId())).willReturn(token1Model);
given(tokenStore.loadPossiblyPausedToken(token2Model.getId())).willReturn(token2Model);
given(payer.isAssociatedWith(token1Model.getId())).willReturn(true);
given(payer.isAssociatedWith(token2Model.getId())).willReturn(true);
given(payer.getCryptoAllowances()).willReturn(existingCryptoAllowances);
given(payer.getFungibleTokenAllowances()).willReturn(existingTokenAllowances);
given(payer.getNftAllowances()).willReturn(existingNftAllowances);
given(payer.isAssociatedWith(token2Model.getId())).willReturn(true);
final NftId token1Nft1 = new NftId(0, 0, token2.getTokenNum(), 1L);
final NftId tokenNft2 = new NftId(0, 0, token2.getTokenNum(), 10L);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2))).willReturn(token);
given(nftsMap.get(EntityNumPair.fromNftId(token1Nft1)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId));
given(nftsMap.get(EntityNumPair.fromNftId(tokenNft2)).getOwner()).willReturn(EntityId.fromGrpcAccountId(ownerId));
}
Aggregations