Search in sources :

Example 1 with TokenRelationship

use of com.hedera.services.store.models.TokenRelationship in project hedera-services by hashgraph.

the class SideEffectsTrackerTest method prioritizesExplicitTokenBalanceChanges.

@Test
void prioritizesExplicitTokenBalanceChanges() {
    final var aaRelChange = new TokenRelationship(new Token(Id.fromGrpcToken(aToken)), new Account(Id.fromGrpcAccount(aAccount)));
    aaRelChange.getToken().setType(FUNGIBLE_COMMON);
    aaRelChange.setBalance(aFirstBalanceChange);
    final var bbRelChange = new TokenRelationship(new Token(Id.fromGrpcToken(bToken)), new Account(Id.fromGrpcAccount(bAccount)));
    bbRelChange.getToken().setType(FUNGIBLE_COMMON);
    final var ccRelChange = new TokenRelationship(new Token(Id.fromGrpcToken(cToken)), new Account(Id.fromGrpcAccount(cAccount)));
    ccRelChange.setBalance(cOnlyBalanceChange);
    ccRelChange.getToken().setType(FUNGIBLE_COMMON);
    subject.trackNftOwnerChange(cSN1, aAccount, bAccount);
    subject.trackTokenBalanceChanges(List.of(ccRelChange, bbRelChange, aaRelChange));
    final var tokenChanges = subject.getNetTrackedTokenUnitAndOwnershipChanges();
    assertEquals(2, tokenChanges.size());
    final var aChange = tokenChanges.get(0);
    assertEquals(aToken, aChange.getToken());
    assertEquals(1, aChange.getTransfersCount());
    assertEquals(aFirstBalanceChange, aChange.getTransfers(0).getAmount());
    final var cChange = tokenChanges.get(1);
    assertEquals(cToken, cChange.getToken());
    assertEquals(1, cChange.getTransfersCount());
    assertEquals(cOnlyBalanceChange, cChange.getTransfers(0).getAmount());
}
Also used : Account(com.hedera.services.store.models.Account) Token(com.hedera.services.store.models.Token) UniqueToken(com.hedera.services.store.models.UniqueToken) TokenRelationship(com.hedera.services.store.models.TokenRelationship) Test(org.junit.jupiter.api.Test)

Example 2 with TokenRelationship

use of com.hedera.services.store.models.TokenRelationship in project hedera-services by hashgraph.

the class EntityNumPairTest method factoryFromModelRelWorks.

@Test
void factoryFromModelRelWorks() {
    final var expected = fromLongs(1, 2);
    final var modelRel = new TokenRelationship(new Token(new Id(0, 0, 2)), new Account(new Id(0, 0, 1)));
    final var actual = EntityNumPair.fromModelRel(modelRel);
    assertEquals(expected, actual);
}
Also used : Account(com.hedera.services.store.models.Account) Token(com.hedera.services.store.models.Token) Id(com.hedera.services.store.models.Id) EntityNumPair.fromNftId(com.hedera.services.utils.EntityNumPair.fromNftId) NftId(com.hedera.services.store.models.NftId) TokenRelationship(com.hedera.services.store.models.TokenRelationship) Test(org.junit.jupiter.api.Test)

Example 3 with TokenRelationship

use of com.hedera.services.store.models.TokenRelationship in project hedera-services by hashgraph.

the class TokenWipeTransitionLogicTest method followsHappyPathForUnique.

@Test
void followsHappyPathForUnique() {
    givenValidUniqueTxnCtx();
    // needed only in the context of this test
    Account acc = mock(Account.class);
    var treasury = mock(Account.class);
    TokenRelationship treasuryRel = mock(TokenRelationship.class);
    TokenRelationship accRel = mock(TokenRelationship.class);
    given(token.getTreasury()).willReturn(treasury);
    given(accountStore.loadAccount(any())).willReturn(acc);
    given(typedTokenStore.loadTokenRelationship(token, acc)).willReturn(accRel);
    given(typedTokenStore.loadTokenRelationship(token, token.getTreasury())).willReturn(treasuryRel);
    // when:
    subject.doStateTransition();
    // then:
    verify(token).wipe(any(OwnershipTracker.class), any(TokenRelationship.class), anyList());
}
Also used : Account(com.hedera.services.store.models.Account) OwnershipTracker(com.hedera.services.store.models.OwnershipTracker) TokenRelationship(com.hedera.services.store.models.TokenRelationship) Test(org.junit.jupiter.api.Test)

Example 4 with TokenRelationship

use of com.hedera.services.store.models.TokenRelationship in project hedera-services by hashgraph.

the class TokenWipeTransitionLogicTest method givenValidCommonTxnCtx.

private void givenValidCommonTxnCtx() {
    tokenWipeTxn = TransactionBody.newBuilder().setTokenWipe(TokenWipeAccountTransactionBody.newBuilder().setToken(id).setAccount(accountID).setAmount(wipeAmount)).build();
    given(accessor.getTxn()).willReturn(tokenWipeTxn);
    given(txnCtx.accessor()).willReturn(accessor);
    given(merkleToken.totalSupply()).willReturn(totalAmount);
    given(merkleToken.tokenType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(typedTokenStore.loadToken(any())).willReturn(token);
    given(token.getType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(accountStore.loadAccount(any())).willReturn(account);
    given(typedTokenStore.loadTokenRelationship(token, account)).willReturn(new TokenRelationship(token, account));
}
Also used : TokenRelationship(com.hedera.services.store.models.TokenRelationship)

Example 5 with TokenRelationship

use of com.hedera.services.store.models.TokenRelationship in project hedera-services by hashgraph.

the class MintLogicTest method followsHappyPath.

@Test
void followsHappyPath() {
    // setup:
    treasuryRel = new TokenRelationship(token, treasury);
    givenValidTxnCtx();
    given(accessor.getTxn()).willReturn(tokenMintTxn);
    given(txnCtx.accessor()).willReturn(accessor);
    given(store.loadToken(id)).willReturn(token);
    given(token.getTreasury()).willReturn(treasury);
    given(store.loadTokenRelationship(token, treasury)).willReturn(treasuryRel);
    given(token.getType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(token.getId()).willReturn(id);
    // when:
    subject.mint(token.getId(), txnCtx.accessor().getTxn().getTokenMint().getMetadataCount(), txnCtx.accessor().getTxn().getTokenMint().getAmount(), txnCtx.accessor().getTxn().getTokenMint().getMetadataList(), Instant.now());
    // then:
    verify(token).mint(treasuryRel, amount, false);
    verify(store).commitToken(token);
    verify(store).commitTokenRelationships(List.of(treasuryRel));
}
Also used : TokenRelationship(com.hedera.services.store.models.TokenRelationship) Test(org.junit.jupiter.api.Test)

Aggregations

TokenRelationship (com.hedera.services.store.models.TokenRelationship)6 Test (org.junit.jupiter.api.Test)5 Account (com.hedera.services.store.models.Account)4 OwnershipTracker (com.hedera.services.store.models.OwnershipTracker)2 Token (com.hedera.services.store.models.Token)2 RichInstant (com.hedera.services.state.submerkle.RichInstant)1 Id (com.hedera.services.store.models.Id)1 NftId (com.hedera.services.store.models.NftId)1 UniqueToken (com.hedera.services.store.models.UniqueToken)1 EntityNumPair.fromNftId (com.hedera.services.utils.EntityNumPair.fromNftId)1 List (java.util.List)1