Search in sources :

Example 1 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class RequestBuilder method getTransactionBody.

private static TransactionBody.Builder getTransactionBody(Long payerAccountNum, Long payerRealmNum, Long payerShardNum, Long nodeAccountNum, Long nodeRealmNum, Long nodeShardNum, long transactionFee, Timestamp timestamp, Duration transactionDuration, boolean generateRecord, String memo) {
    AccountID payerAccountID = getAccountIdBuild(payerAccountNum, payerRealmNum, payerShardNum);
    AccountID nodeAccountID = getAccountIdBuild(nodeAccountNum, nodeRealmNum, nodeShardNum);
    return getTxBodyBuilder(transactionFee, timestamp, transactionDuration, generateRecord, memo, payerAccountID, nodeAccountID);
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 2 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class BaseHederaLedgerTestHelper method commonSetup.

protected void commonSetup() {
    sideEffectsTracker = mock(SideEffectsTracker.class);
    creator = mock(ExpiringCreations.class);
    historian = mock(AccountRecordsHistorian.class);
    ids = new EntityIdSource() {

        long nextId = NEXT_ID;

        @Override
        public TopicID newTopicId(final AccountID sponsor) {
            return TopicID.newBuilder().setTopicNum(nextId++).build();
        }

        @Override
        public AccountID newAccountId(AccountID newAccountSponsor) {
            return AccountID.newBuilder().setAccountNum(nextId++).build();
        }

        @Override
        public ContractID newContractId(AccountID newContractSponsor) {
            return ContractID.newBuilder().setContractNum(nextId++).build();
        }

        @Override
        public FileID newFileId(AccountID newFileSponsor) {
            return FileID.newBuilder().setFileNum(nextId++).build();
        }

        @Override
        public TokenID newTokenId(AccountID sponsor) {
            return TokenID.newBuilder().setTokenNum(nextId++).build();
        }

        @Override
        public ScheduleID newScheduleId(AccountID sponsor) {
            return ScheduleID.newBuilder().setScheduleNum(nextId++).build();
        }

        @Override
        public void reclaimLastId() {
            nextId--;
        }

        @Override
        public void reclaimProvisionalIds() {
        }

        @Override
        public void resetProvisionalIds() {
        }
    };
}
Also used : EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) TopicID(com.hederahashgraph.api.proto.java.TopicID) FileID(com.hederahashgraph.api.proto.java.FileID) ContractID(com.hederahashgraph.api.proto.java.ContractID) ExpiringCreations(com.hedera.services.state.expiry.ExpiringCreations) TokenID(com.hederahashgraph.api.proto.java.TokenID) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) AccountRecordsHistorian(com.hedera.services.records.AccountRecordsHistorian)

Example 3 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class ImpliedTransfersMarshalTest method hasAliasInChanges.

@Test
void hasAliasInChanges() {
    Key aliasA = KeyFactory.getDefaultInstance().newEd25519();
    Key aliasB = KeyFactory.getDefaultInstance().newEd25519();
    AccountID a = AccountID.newBuilder().setShardNum(0).setRealmNum(0).setAccountNum(9_999L).setAlias(aliasA.toByteString()).build();
    AccountID validAliasAccount = AccountID.newBuilder().setAlias(aliasB.toByteString()).build();
    setupProps();
    final var builder = CryptoTransferTransactionBody.newBuilder().setTransfers(TransferList.newBuilder().addAccountAmounts(adjustFrom(a, -100)).addAccountAmounts(adjustFrom(validAliasAccount, 100)).build());
    op = builder.build();
    final List<BalanceChange> expectedChanges = new ArrayList<>();
    expectedChanges.add(changingHbar(adjustFrom(a, -100), payer));
    expectedChanges.add(changingHbar(adjustFrom(validAliasAccount, +100), payer));
    final var expectedMeta = new ImpliedTransfersMeta(propsWithAutoCreation, OK, Collections.emptyList(), NO_ALIASES);
    givenValidity(OK);
    final var result = subject.unmarshalFromGrpc(op, payer);
    assertEquals(expectedChanges, result.getAllBalanceChanges());
    assertEquals(aliasA.toByteString(), result.getAllBalanceChanges().get(0).alias());
    assertEquals(aliasB.toByteString(), result.getAllBalanceChanges().get(1).alias());
    assertEquals(result.getMeta(), expectedMeta);
    assertTrue(result.getAssessedCustomFees().isEmpty());
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) BalanceChange(com.hedera.services.ledger.BalanceChange) ArrayList(java.util.ArrayList) Key(com.hederahashgraph.api.proto.java.Key) Test(org.junit.jupiter.api.Test)

Example 4 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class LedgerBalanceChangesTest method givenInitialBalancesAndOwnership.

private void givenInitialBalancesAndOwnership() {
    final var aAccount = MerkleAccountFactory.newAccount().balance(aStartBalance).get();
    backingAccounts.put(aModel, aAccount);
    final var bAccount = MerkleAccountFactory.newAccount().balance(bStartBalance).get();
    backingAccounts.put(bModel, bAccount);
    final var cAccount = MerkleAccountFactory.newAccount().balance(cStartBalance).get();
    backingAccounts.put(cModel, cAccount);
    Pair<AccountID, TokenID> bTokenKey = rel(bModel, token);
    final var bTokenRel = new MerkleTokenRelStatus(bTokenStartBalance, false, true, false);
    backingRels.put(bTokenKey, bTokenRel);
    Pair<AccountID, TokenID> cTokenKey = rel(cModel, token);
    final var cTokenRel = new MerkleTokenRelStatus(cTokenStartBalance, false, true, false);
    backingRels.put(cTokenKey, cTokenRel);
    Pair<AccountID, TokenID> aAnotherTokenKey = rel(aModel, anotherToken);
    final var aAnotherTokenRel = new MerkleTokenRelStatus(aAnotherTokenStartBalance, false, true, true);
    backingRels.put(aAnotherTokenKey, aAnotherTokenRel);
    Pair<AccountID, TokenID> bAnotherTokenKey = rel(bModel, anotherToken);
    final var bAnotherTokenRel = new MerkleTokenRelStatus(bAnotherTokenStartBalance, false, true, false);
    backingRels.put(bAnotherTokenKey, bAnotherTokenRel);
    Pair<AccountID, TokenID> cAnotherTokenKey = rel(cModel, anotherToken);
    final var cAnotherTokenRel = new MerkleTokenRelStatus(cAnotherTokenStartBalance, false, true, true);
    backingRels.put(cAnotherTokenKey, cAnotherTokenRel);
    Pair<AccountID, TokenID> aYaTokenKey = rel(aModel, yetAnotherToken);
    final var aYaTokenRel = new MerkleTokenRelStatus(aYetAnotherTokenBalance, false, true, false);
    backingRels.put(aYaTokenKey, aYaTokenRel);
    Pair<AccountID, TokenID> bYaTokenKey = rel(bModel, yetAnotherToken);
    final var bYaTokenRel = new MerkleTokenRelStatus(bYetAnotherTokenBalance, false, true, false);
    backingRels.put(bYaTokenKey, bYaTokenRel);
    Pair<AccountID, TokenID> aaNftTokenKey = rel(aModel, aNft);
    final var aaNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(aaNftTokenKey, aaNftTokenRel);
    Pair<AccountID, TokenID> abNftTokenKey = rel(aModel, bNft);
    final var abNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(abNftTokenKey, abNftTokenRel);
    Pair<AccountID, TokenID> baNftTokenKey = rel(bModel, aNft);
    final var baNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(baNftTokenKey, baNftTokenRel);
    Pair<AccountID, TokenID> bbNftTokenKey = rel(bModel, bNft);
    final var bbNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(bbNftTokenKey, bbNftTokenRel);
    Pair<AccountID, TokenID> caNftTokenKey = rel(cModel, aNft);
    final var caNftTokenRel = new MerkleTokenRelStatus(2, false, true, true);
    backingRels.put(caNftTokenKey, caNftTokenRel);
    Pair<AccountID, TokenID> cbNftTokenKey = rel(cModel, bNft);
    final var cbNftTokenRel = new MerkleTokenRelStatus(2, false, true, false);
    backingRels.put(cbNftTokenKey, cbNftTokenRel);
    backingNfts.put(aaNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(aModel), "aa".getBytes(), MISSING_INSTANT));
    backingNfts.put(baNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(bModel), "ba".getBytes(), MISSING_INSTANT));
    backingNfts.put(bbNft, new MerkleUniqueToken(EntityId.fromGrpcAccountId(cModel), "bb".getBytes(), MISSING_INSTANT));
    backingRels.rebuildFromSources();
}
Also used : MerkleTokenRelStatus(com.hedera.services.state.merkle.MerkleTokenRelStatus) AccountID(com.hederahashgraph.api.proto.java.AccountID) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 5 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class HederaTokenStoreTest method setup.

@BeforeEach
void setup() {
    token = mock(MerkleToken.class);
    given(token.expiry()).willReturn(expiry);
    given(token.symbol()).willReturn(symbol);
    given(token.hasAutoRenewAccount()).willReturn(true);
    given(token.adminKey()).willReturn(Optional.of(TOKEN_ADMIN_KT.asJKeyUnchecked()));
    given(token.name()).willReturn(name);
    given(token.hasAdminKey()).willReturn(true);
    given(token.hasFeeScheduleKey()).willReturn(true);
    given(token.treasury()).willReturn(EntityId.fromGrpcAccountId(treasury));
    given(token.tokenType()).willReturn(TokenType.FUNGIBLE_COMMON);
    given(token.decimals()).willReturn(2);
    nonfungibleToken = mock(MerkleToken.class);
    given(nonfungibleToken.hasAdminKey()).willReturn(true);
    given(nonfungibleToken.tokenType()).willReturn(TokenType.NON_FUNGIBLE_UNIQUE);
    ids = mock(EntityIdSource.class);
    given(ids.newTokenId(sponsor)).willReturn(created);
    hederaLedger = mock(HederaLedger.class);
    nftsLedger = (TransactionalLedger<NftId, NftProperty, MerkleUniqueToken>) mock(TransactionalLedger.class);
    given(nftsLedger.get(aNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(sponsor));
    given(nftsLedger.get(tNft, NftProperty.OWNER)).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(nftsLedger.exists(aNft)).willReturn(true);
    given(nftsLedger.exists(tNft)).willReturn(true);
    accountsLedger = (TransactionalLedger<AccountID, AccountProperty, MerkleAccount>) mock(TransactionalLedger.class);
    given(accountsLedger.exists(treasury)).willReturn(true);
    given(accountsLedger.exists(anotherFeeCollector)).willReturn(true);
    given(accountsLedger.exists(autoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(newAutoRenewAccount)).willReturn(true);
    given(accountsLedger.exists(primaryTreasury)).willReturn(true);
    given(accountsLedger.exists(sponsor)).willReturn(true);
    given(accountsLedger.exists(counterparty)).willReturn(true);
    given(accountsLedger.get(treasury, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(autoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(newAutoRenewAccount, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(sponsor, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(counterparty, IS_DELETED)).willReturn(false);
    given(accountsLedger.get(primaryTreasury, IS_DELETED)).willReturn(false);
    backingTokens = mock(BackingTokens.class);
    given(backingTokens.contains(misc)).willReturn(true);
    given(backingTokens.contains(nonfungible)).willReturn(true);
    given(backingTokens.getRef(created)).willReturn(token);
    given(backingTokens.getImmutableRef(created)).willReturn(token);
    given(backingTokens.getRef(misc)).willReturn(token);
    given(backingTokens.getImmutableRef(misc)).willReturn(token);
    given(backingTokens.getRef(nonfungible)).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId())).willReturn(nonfungibleToken);
    given(backingTokens.getImmutableRef(tNft.tokenId()).treasury()).willReturn(EntityId.fromGrpcAccountId(primaryTreasury));
    given(backingTokens.idSet()).willReturn(Set.of(created));
    tokenRelsLedger = mock(TransactionalLedger.class);
    given(tokenRelsLedger.exists(sponsorMisc)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryNft)).willReturn(true);
    given(tokenRelsLedger.exists(sponsorNft)).willReturn(true);
    given(tokenRelsLedger.exists(counterpartyNft)).willReturn(true);
    given(tokenRelsLedger.get(sponsorMisc, TOKEN_BALANCE)).willReturn(sponsorBalance);
    given(tokenRelsLedger.get(sponsorMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.exists(treasuryMisc)).willReturn(true);
    given(tokenRelsLedger.exists(anotherFeeCollectorMisc)).willReturn(true);
    given(tokenRelsLedger.get(treasuryMisc, TOKEN_BALANCE)).willReturn(treasuryBalance);
    given(tokenRelsLedger.get(treasuryMisc, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryMisc, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(treasuryNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(treasuryNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(treasuryNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(sponsorNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(sponsorNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(sponsorNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(counterpartyNft, TOKEN_BALANCE)).willReturn(123L);
    given(tokenRelsLedger.get(counterpartyNft, IS_FROZEN)).willReturn(false);
    given(tokenRelsLedger.get(counterpartyNft, IS_KYC_GRANTED)).willReturn(true);
    given(tokenRelsLedger.get(newTreasuryNft, TOKEN_BALANCE)).willReturn(1L);
    properties = mock(GlobalDynamicProperties.class);
    given(properties.maxTokensPerAccount()).willReturn(MAX_TOKENS_PER_ACCOUNT);
    given(properties.maxTokenSymbolUtf8Bytes()).willReturn(MAX_TOKEN_SYMBOL_UTF8_BYTES);
    given(properties.maxTokenNameUtf8Bytes()).willReturn(MAX_TOKEN_NAME_UTF8_BYTES);
    given(properties.maxCustomFeesAllowed()).willReturn(maxCustomFees);
    sideEffectsTracker = new SideEffectsTracker();
    subject = new HederaTokenStore(ids, TEST_VALIDATOR, sideEffectsTracker, properties, tokenRelsLedger, nftsLedger, backingTokens);
    subject.setAccountsLedger(accountsLedger);
    subject.setHederaLedger(hederaLedger);
    subject.knownTreasuries.put(treasury, new HashSet<>() {

        {
            add(misc);
        }
    });
}
Also used : BackingTokens(com.hedera.services.ledger.backing.BackingTokens) EntityIdSource(com.hedera.services.ledger.ids.EntityIdSource) AccountID(com.hederahashgraph.api.proto.java.AccountID) HederaLedger(com.hedera.services.ledger.HederaLedger) SideEffectsTracker(com.hedera.services.context.SideEffectsTracker) MerkleToken(com.hedera.services.state.merkle.MerkleToken) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) GlobalDynamicProperties(com.hedera.services.context.properties.GlobalDynamicProperties) NftId(com.hedera.services.store.models.NftId) NftProperty(com.hedera.services.ledger.properties.NftProperty) AccountProperty(com.hedera.services.ledger.properties.AccountProperty) TransactionalLedger(com.hedera.services.ledger.TransactionalLedger) MerkleUniqueToken(com.hedera.services.state.merkle.MerkleUniqueToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12