use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.
the class RenewalHelperTest method removesAutoAccountEntityWhenExpired.
@Test
void removesAutoAccountEntityWhenExpired() {
MerkleMap<EntityNum, MerkleAccount> accountsMap = new MerkleMap<>();
accountsMap.put(EntityNum.fromLong(nonExpiredAccountNum), nonExpiredAccount);
accountsMap.put(EntityNum.fromLong(brokeExpiredAccountNum), expiredAccountZeroBalance);
AliasManager liveAliasManager = new AliasManager();
linkWellKnownEntities(liveAliasManager);
final var backingAccounts = new BackingAccounts(() -> accountsMap);
backingAccounts.put(IdUtils.asAccount("0.0." + nonExpiredAccountNum), nonExpiredAccount);
backingAccounts.put(IdUtils.asAccount("0.0." + brokeExpiredAccountNum), expiredAccountZeroBalance);
subject = new RenewalHelper(tokenStore, sigImpactHistorian, dynamicProps, () -> tokens, () -> accountsMap, () -> tokenRels, backingAccounts, liveAliasManager);
final var expiredKey = EntityNum.fromLong(brokeExpiredAccountNum);
givenTokenPresent(deletedTokenId, deletedToken);
givenTokenPresent(survivedTokenId, longLivedToken);
givenRelPresent(expiredKey, deletedTokenId, Long.MAX_VALUE);
givenRelPresent(expiredKey, survivedTokenId, tokenBalance);
givenRelPresent(expiredKey, EntityNum.fromTokenId(missingTokenGrpcId), 0);
givenModifiableRelPresent(EntityNum.fromAccountId(treasuryGrpcId), survivedTokenId, 0L);
assertTrue(liveAliasManager.contains(expiredAccountZeroBalance.getAlias()));
assertTrue(backingAccounts.contains(AccountID.newBuilder().setAccountNum(brokeExpiredAccountNum).build()));
subject.classify(brokeExpiredAccountNum, now);
subject.removeLastClassifiedAccount();
assertFalse(backingAccounts.contains(AccountID.newBuilder().setAccountNum(brokeExpiredAccountNum).build()));
}
use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.
the class SigOpsRegressionTest method invokePayerSigActivationScenario.
private boolean invokePayerSigActivationScenario(List<TransactionSignature> knownSigs) {
SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, null, () -> accounts, () -> null, ref -> null, ref -> null), mockSignatureWaivers);
final var impliedOrdering = keysOrder.keysForPayer(platformTxn.getTxn(), CODE_ORDER_RESULT_FACTORY);
final var impliedKey = impliedOrdering.getPayerKey();
platformTxn.setSigMeta(RationalizedSigMeta.forPayerOnly(impliedKey, new ArrayList<>(knownSigs)));
return payerSigIsActive(platformTxn, ONLY_IF_SIG_IS_VALID);
}
use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.
the class SigOpsRegressionTest method invokeOtherPartySigActivationScenario.
private boolean invokeOtherPartySigActivationScenario(List<TransactionSignature> knownSigs) {
platformTxn.getPlatformTxn().clear();
platformTxn.getPlatformTxn().addAll(knownSigs.toArray(new TransactionSignature[0]));
final var hfsSigMetaLookup = new HfsSigMetaLookup(hfs, fileNumbers);
SigRequirements keysOrder = new SigRequirements(defaultLookupsFor(aliasManager, hfsSigMetaLookup, () -> accounts, null, ref -> null, ref -> null), mockSignatureWaivers);
return otherPartySigsAreActive(platformTxn, keysOrder, CODE_ORDER_RESULT_FACTORY);
}
use of com.hedera.services.ledger.accounts.AliasManager in project hedera-services by hashgraph.
the class SignedTxnAccessorTest method parsesLegacyCorrectly.
@Test
void parsesLegacyCorrectly() throws Exception {
final Key aPrimitiveKey = Key.newBuilder().setEd25519(ByteString.copyFromUtf8("01234567890123456789012345678901")).build();
final ByteString aNewAlias = aPrimitiveKey.toByteString();
final AliasManager aliasManager = mock(AliasManager.class);
given(aliasManager.lookupIdBy(any())).willReturn(EntityNum.MISSING_NUM);
final long offeredFee = 100_000_000L;
var xferNoAliases = RequestBuilder.getCryptoTransferRequest(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, -70000l, 5679l, 70000l);
xferNoAliases = xferNoAliases.toBuilder().setSigMap(expectedMap).build();
var xferWithAutoCreation = RequestBuilder.getHbarCryptoTransferRequestToAlias(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, -70000l, aNewAlias, 70000l);
xferWithAutoCreation = xferWithAutoCreation.toBuilder().setSigMap(expectedMap).build();
var xferWithAliasesNoAutoCreation = RequestBuilder.getTokenTransferRequestToAlias(1234l, 0l, 0l, 3l, 0l, 0l, offeredFee, Timestamp.getDefaultInstance(), Duration.getDefaultInstance(), false, zeroByteMemo, 5678l, 5555l, -70000l, ByteString.copyFromUtf8("aaaa"), 70000l);
xferWithAliasesNoAutoCreation = xferWithAliasesNoAutoCreation.toBuilder().setSigMap(expectedMap).build();
final var body = CommonUtils.extractTransactionBody(xferNoAliases);
var accessor = SignedTxnAccessor.uncheckedFrom(xferNoAliases);
accessor.countAutoCreationsWith(aliasManager);
final var txnUsageMeta = accessor.baseUsageMeta();
assertEquals(xferNoAliases, accessor.getSignedTxnWrapper());
assertArrayEquals(xferNoAliases.toByteArray(), accessor.getSignedTxnWrapperBytes());
assertEquals(body, accessor.getTxn());
assertArrayEquals(body.toByteArray(), accessor.getTxnBytes());
assertEquals(body.getTransactionID(), accessor.getTxnId());
assertEquals(1234l, accessor.getPayer().getAccountNum());
assertEquals(HederaFunctionality.CryptoTransfer, accessor.getFunction());
assertEquals(offeredFee, accessor.getOfferedFee());
assertArrayEquals(CommonUtils.noThrowSha384HashOf(xferNoAliases.toByteArray()), accessor.getHash());
assertEquals(expectedMap, accessor.getSigMap());
assertArrayEquals("irst".getBytes(), accessor.getPkToSigsFn().sigBytesFor("f".getBytes()));
assertArrayEquals(zeroByteMemoUtf8Bytes, accessor.getMemoUtf8Bytes());
assertTrue(accessor.memoHasZeroByte());
assertEquals(FeeBuilder.getSignatureCount(accessor.getSignedTxnWrapper()), accessor.numSigPairs());
assertEquals(FeeBuilder.getSignatureSize(accessor.getSignedTxnWrapper()), accessor.sigMapSize());
assertEquals(zeroByteMemo, accessor.getMemo());
assertEquals(false, accessor.isTriggeredTxn());
assertEquals(false, accessor.canTriggerTxn());
assertEquals(0, accessor.getNumAutoCreations());
assertEquals(memoUtf8Bytes.length, txnUsageMeta.memoUtf8Bytes());
accessor = SignedTxnAccessor.uncheckedFrom(xferWithAutoCreation);
accessor.countAutoCreationsWith(aliasManager);
assertEquals(1, accessor.getNumAutoCreations());
accessor = SignedTxnAccessor.uncheckedFrom(xferWithAliasesNoAutoCreation);
accessor.countAutoCreationsWith(aliasManager);
assertEquals(0, accessor.getNumAutoCreations());
}
Aggregations