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