Search in sources :

Example 6 with NftId

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));
}
Also used : NftId(com.hedera.services.store.models.NftId)

Example 7 with NftId

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));
}
Also used : NftId(com.hedera.services.store.models.NftId) Test(org.junit.jupiter.api.Test)

Example 8 with NftId

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));
}
Also used : NftId(com.hedera.services.store.models.NftId)

Example 9 with NftId

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));
}
Also used : NftId(com.hedera.services.store.models.NftId) Test(org.junit.jupiter.api.Test)

Example 10 with NftId

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));
}
Also used : NftId(com.hedera.services.store.models.NftId)

Aggregations

NftId (com.hedera.services.store.models.NftId)10 Test (org.junit.jupiter.api.Test)5 MerkleToken (com.hedera.services.state.merkle.MerkleToken)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 SideEffectsTracker (com.hedera.services.context.SideEffectsTracker)1 GlobalDynamicProperties (com.hedera.services.context.properties.GlobalDynamicProperties)1 HederaLedger (com.hedera.services.ledger.HederaLedger)1 TransactionalLedger (com.hedera.services.ledger.TransactionalLedger)1 BackingTokens (com.hedera.services.ledger.backing.BackingTokens)1 EntityIdSource (com.hedera.services.ledger.ids.EntityIdSource)1 AccountProperty (com.hedera.services.ledger.properties.AccountProperty)1 NftProperty (com.hedera.services.ledger.properties.NftProperty)1 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)1 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)1 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1