Search in sources :

Example 11 with Account

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

the class CallLocalExecutorTest method processingSuccessfulWithAlias.

@Test
void processingSuccessfulWithAlias() {
    // setup:
    final var targetAlias = CommonUtils.unhex("6aea3773ea468a814d954e6dec795bfee7d76e25");
    final var target = ContractID.newBuilder().setEvmAddress(ByteString.copyFrom(targetAlias)).build();
    query = localCallQuery(target, ANSWER_ONLY);
    given(aliasManager.lookupIdBy(target.getEvmAddress())).willReturn(EntityNum.fromLong(contractID.num()));
    final var transactionProcessingResult = TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, 1, Bytes.EMPTY, callerID.asEvmAddress(), new TreeMap<>());
    final var expected = response(OK, transactionProcessingResult);
    given(accountStore.loadAccount(any())).willReturn(new Account(callerID));
    given(accountStore.loadContract(contractID)).willReturn(new Account(contractID));
    given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
    // when:
    final var result = CallLocalExecutor.execute(accountStore, evmTxProcessor, query, aliasManager);
    // then:
    assertEquals(expected, result);
}
Also used : Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 12 with Account

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

the class CallLocalExecutorTest method processingReturnsRevertReason.

@Test
void processingReturnsRevertReason() {
    // setup:
    final var transactionProcessingResult = TransactionProcessingResult.failed(0, 0, 1, Optional.of(Bytes.of("out of gas".getBytes())), Optional.empty(), Collections.emptyMap());
    final var expected = response(CONTRACT_REVERT_EXECUTED, transactionProcessingResult);
    given(accountStore.loadAccount(any())).willReturn(new Account(callerID));
    given(accountStore.loadContract(any())).willReturn(new Account(contractID));
    given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
    // when:
    final var result = CallLocalExecutor.execute(accountStore, evmTxProcessor, query, aliasManager);
    // then:
    assertEquals(expected, result);
}
Also used : Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 13 with Account

use of com.hedera.services.store.models.Account 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 14 with Account

use of com.hedera.services.store.models.Account 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 15 with Account

use of com.hedera.services.store.models.Account 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)

Aggregations

Account (com.hedera.services.store.models.Account)15 Test (org.junit.jupiter.api.Test)14 TokenRelationship (com.hedera.services.store.models.TokenRelationship)3 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)2 Id (com.hedera.services.store.models.Id)2 Token (com.hedera.services.store.models.Token)2 IdUtils.asAccount (com.hedera.test.utils.IdUtils.asAccount)2 NftId (com.hedera.services.store.models.NftId)1 OwnershipTracker (com.hedera.services.store.models.OwnershipTracker)1 UniqueToken (com.hedera.services.store.models.UniqueToken)1 EntityNumPair.fromNftId (com.hedera.services.utils.EntityNumPair.fromNftId)1 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)1 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)1 Query (com.hederahashgraph.api.proto.java.Query)1 Response (com.hederahashgraph.api.proto.java.Response)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Address (org.hyperledger.besu.datatypes.Address)1