use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.
the class MerkleTokenTest method v0120DeserializeWorks.
@Test
void v0120DeserializeWorks() throws IOException {
final var fin = mock(SerializableDataInputStream.class);
subject.setFeeScheduleFrom(Collections.emptyList());
subject.setFeeScheduleKey(MerkleToken.UNUSED_KEY);
given(serdes.readNullableSerializable(any())).willReturn(autoRenewAccount);
given(serdes.deserializeKey(fin)).willReturn(adminKey);
given(serdes.readNullable(argThat(fin::equals), any(IoReadingFunction.class))).willReturn(adminKey).willReturn(freezeKey).willReturn(kycKey).willReturn(supplyKey).willReturn(wipeKey);
given(fin.readNormalisedString(anyInt())).willReturn(symbol).willReturn(name).willReturn(memo);
given(fin.readLong()).willReturn(subject.expiry()).willReturn(subject.autoRenewPeriod()).willReturn(subject.totalSupply()).willReturn(subject.getLastUsedSerialNumber());
given(fin.readInt()).willReturn(subject.decimals()).willReturn(TokenType.FUNGIBLE_COMMON.ordinal()).willReturn(TokenSupplyType.INFINITE.ordinal());
given(fin.readBoolean()).willReturn(isDeleted).willReturn(subject.accountsAreFrozenByDefault());
given(fin.readSerializable()).willReturn(subject.treasury());
final var read = new MerkleToken();
read.deserialize(fin, MerkleToken.RELEASE_0120_VERSION);
// then:
assertNotEquals(subject, read);
// and when:
read.setKey(new EntityNum(number));
// expect:
assertEquals(subject, read);
}
use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.
the class MerkleAccountStateTest method addingAndRemovingToMapsWork.
@Test
void addingAndRemovingToMapsWork() {
final EntityNum spenderNum = EntityNum.fromLong(2000L);
final EntityNum tokenForAllowance = EntityNum.fromLong(4000L);
final Long cryptoAllowance = 100L;
final boolean approvedForAll = false;
final Long tokenAllowanceVal = 10L;
final List<Long> serialNumbers = List.of(3L, 4L);
final FcTokenAllowanceId tokenAllowanceKey = FcTokenAllowanceId.from(tokenForAllowance, spenderNum);
subject.addCryptoAllowance(spenderNum, cryptoAllowance);
subject.addFungibleTokenAllowance(tokenForAllowance, spenderNum, tokenAllowanceVal);
subject.addNftAllowance(tokenForAllowance, spenderNum, approvedForAll, serialNumbers);
assertTrue(subject.getCryptoAllowances().containsKey(spenderNum));
assertTrue(subject.getNftAllowances().containsKey(tokenAllowanceKey));
assertEquals(2, subject.getCryptoAllowances().size());
assertEquals(2, subject.getNftAllowances().size());
subject.removeCryptoAllowance(spenderNum);
subject.removeFungibleTokenAllowance(tokenForAllowance, spenderNum);
subject.removeNftAllowance(tokenForAllowance, spenderNum);
assertFalse(subject.getCryptoAllowances().containsKey(spenderNum));
assertFalse(subject.getNftAllowances().containsKey(tokenAllowanceKey));
assertEquals(1, subject.getCryptoAllowances().size());
assertEquals(1, subject.getNftAllowances().size());
}
use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.
the class MerkleAccountStateTest method equalsWorksForAllowances.
@Test
void equalsWorksForAllowances() {
final EntityNum spenderNum = EntityNum.fromLong(100L);
final EntityNum tokenForAllowance = EntityNum.fromLong(200L);
final Long cryptoAllowance = 100L;
final boolean approvedForAll = true;
final Long tokenAllowanceVal = 1L;
final List<Long> serialNumbers = new ArrayList<>();
final FcTokenAllowanceId tokenAllowanceKey = FcTokenAllowanceId.from(tokenForAllowance, spenderNum);
final FcTokenAllowance tokenAllowanceValue = FcTokenAllowance.from(approvedForAll, serialNumbers);
otherCryptoAllowances.put(spenderNum, cryptoAllowance);
otherNftAllowances.put(tokenAllowanceKey, tokenAllowanceValue);
otherFungibleTokenAllowances.put(tokenAllowanceKey, tokenAllowanceVal);
final var otherSubject = new MerkleAccountState(key, expiry, balance, autoRenewSecs, memo, deleted, smartContract, receiverSigRequired, proxy, number, autoAssociationMetadata, alias, otherKvPairs, otherCryptoAllowances, otherFungibleTokenAllowances, otherNftAllowances);
assertNotEquals(subject, otherSubject);
}
use of com.hedera.services.utils.EntityNum in project hedera-services by hashgraph.
the class ToStringAccountsExporterTest method producesExpectedText.
@Test
void producesExpectedText() throws Exception {
// setup:
TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap();
cryptoAllowances.put(EntityNum.fromLong(1L), 10L);
account1.setBalance(1L);
account1.setTokens(new MerkleAccountTokens(new CopyOnWriteIds(new long[] { 1L, 2L, 3L, 3L, 2L, 1L })));
account1.setMaxAutomaticAssociations(10);
account1.setAlreadyUsedAutomaticAssociations(7);
account1.setCryptoAllowances(cryptoAllowances);
account2.setBalance(2L);
account2.setTokens(new MerkleAccountTokens(new CopyOnWriteIds(new long[] { 0L, 0L, 1234L })));
// and:
var desired = "0.0.1\n" + "---\n" + "MerkleAccount{state=MerkleAccountState{number=1 <-> 0.0.1, key=ed25519: \"first-fake\"\n" + ", expiry=1234567, balance=1, autoRenewSecs=555555, memo=This ecstasy doth unperplex, deleted=false, " + "smartContract=true, numContractKvPairs=0, receiverSigRequired=true, " + "proxy=EntityId{shard=0, realm=0, num=0}, nftsOwned=0, " + "alreadyUsedAutoAssociations=7, maxAutoAssociations=10, alias=, " + "cryptoAllowances={EntityNum{value=1}=10}, " + "fungibleTokenAllowances={}, nftAllowances={}}, # records=0, tokens=[3.2.1, 1.2.3]}\n\n0.0.2\n---\n" + "MerkleAccount{state=MerkleAccountState{number=2 <-> 0.0.2, key=ed25519: \"second-fake\"\n" + ", expiry=7654321, balance=2, autoRenewSecs=444444, memo=We said, and show us what we love, " + "deleted=true, smartContract=false, numContractKvPairs=0, receiverSigRequired=false, " + "proxy=EntityId{shard=0, realm=0, num=0}, nftsOwned=0, alreadyUsedAutoAssociations=0, " + "maxAutoAssociations=0, alias=, cryptoAllowances={}, fungibleTokenAllowances={}, nftAllowances={}}, #" + " records=0, tokens=[1234.0.0]}\n";
// given:
MerkleMap<EntityNum, MerkleAccount> accounts = new MerkleMap<>();
// and:
accounts.put(EntityNum.fromInt(2), account2);
accounts.put(EntityNum.fromInt(1), account1);
// and:
given(nodeLocalProperties.exportAccountsOnStartup()).willReturn(true);
given(nodeLocalProperties.accountsExportPath()).willReturn(testExportLoc);
// when:
subject.toFile(accounts);
// and:
var result = Files.readString(Paths.get(testExportLoc));
// then:
assertEquals(desired, result);
}
use of com.hedera.services.utils.EntityNum 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()));
}
Aggregations