Search in sources :

Example 1 with CopyOnWriteIds

use of com.hedera.services.state.merkle.internals.CopyOnWriteIds in project hedera-services by hashgraph.

the class MerkleAccountTokensTest method rejectsIndivisibleParts.

@Test
void rejectsIndivisibleParts() {
    final var idLength = new long[MerkleAccountTokens.NUM_ID_PARTS + 1];
    Assertions.assertThrows(IllegalArgumentException.class, () -> new CopyOnWriteIds(idLength));
}
Also used : CopyOnWriteIds(com.hedera.services.state.merkle.internals.CopyOnWriteIds) Test(org.junit.jupiter.api.Test)

Example 2 with CopyOnWriteIds

use of com.hedera.services.state.merkle.internals.CopyOnWriteIds 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);
}
Also used : MerkleAccountTokens(com.hedera.services.state.merkle.MerkleAccountTokens) CopyOnWriteIds(com.hedera.services.state.merkle.internals.CopyOnWriteIds) MerkleMap(com.swirlds.merkle.map.MerkleMap) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) TreeMap(java.util.TreeMap) EntityNum(com.hedera.services.utils.EntityNum) Test(org.junit.jupiter.api.Test)

Aggregations

CopyOnWriteIds (com.hedera.services.state.merkle.internals.CopyOnWriteIds)2 Test (org.junit.jupiter.api.Test)2 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)1 MerkleAccountTokens (com.hedera.services.state.merkle.MerkleAccountTokens)1 EntityNum (com.hedera.services.utils.EntityNum)1 MerkleMap (com.swirlds.merkle.map.MerkleMap)1 TreeMap (java.util.TreeMap)1