use of com.hedera.services.state.merkle.MerkleToken in project hedera-services by hashgraph.
the class FcmCustomFeeSchedulesTest method testObjectContract.
@Test
void testObjectContract() {
// given:
MerkleMap<EntityNum, MerkleToken> secondMerkleMap = new MerkleMap<>();
MerkleToken token = new MerkleToken();
final var missingFees = List.of(FcCustomFee.fixedFee(50L, missingToken, feeCollector).asGrpc());
token.setFeeScheduleFrom(missingFees);
secondMerkleMap.put(EntityNum.fromLong(missingToken.num()), new MerkleToken());
final var fees1 = new FcmCustomFeeSchedules(() -> tokens);
final var fees2 = new FcmCustomFeeSchedules(() -> secondMerkleMap);
// expect:
assertNotEquals(fees1, fees2);
assertNotEquals(fees1.hashCode(), fees2.hashCode());
}
use of com.hedera.services.state.merkle.MerkleToken in project hedera-services by hashgraph.
the class MerkleAccountPropertyTest method gettersAndSettersWork.
@Test
void gettersAndSettersWork() throws Exception {
final boolean origIsDeleted = false;
final boolean origIsReceiverSigReq = false;
final boolean origIsContract = false;
final long origBalance = 1L;
final long origAutoRenew = 1L;
final long origNumNfts = 123L;
final long origExpiry = 1L;
final int origMaxAutoAssociations = 10;
final int origAlreadyUsedAutoAssociations = 7;
final var origKey = SignedTxnFactory.DEFAULT_PAYER_KT.asKey();
final String origMemo = "a";
final var origProxy = AccountID.getDefaultInstance();
final List<ExpirableTxnRecord> origRecords = new ArrayList<>();
origRecords.add(expirableRecord(ResponseCodeEnum.MODIFYING_IMMUTABLE_CONTRACT));
origRecords.add(expirableRecord(ResponseCodeEnum.INVALID_PAYER_SIGNATURE));
final List<ExpirableTxnRecord> origPayerRecords = new ArrayList<>();
origPayerRecords.add(expirableRecord(ResponseCodeEnum.INVALID_CHUNK_NUMBER));
origPayerRecords.add(expirableRecord(ResponseCodeEnum.INSUFFICIENT_TX_FEE));
final boolean newIsDeleted = true;
final boolean newIsReceiverSigReq = true;
final boolean newIsContract = true;
final long newBalance = 2L;
final long newAutoRenew = 2L;
final long newExpiry = 2L;
final long newNumNfts = 321L;
final int newMaxAutoAssociations = 15;
final int newAlreadyUsedAutoAssociations = 11;
final JKey newKey = new JKeyList();
final String newMemo = "b";
final EntityId newProxy = new EntityId(0, 0, 2);
final var oldAlias = ByteString.copyFromUtf8("then");
final var newAlias = ByteString.copyFromUtf8("now");
final int oldNumKvPairs = 123;
final int newNumKvPairs = 123;
final long initialAllowance = 100L;
final AccountID payer = AccountID.newBuilder().setAccountNum(12345L).build();
final AccountID owner = AccountID.newBuilder().setAccountNum(12347L).build();
final EntityNum payerNum = EntityNum.fromAccountId(payer);
final TokenID fungibleTokenID = TokenID.newBuilder().setTokenNum(1234L).build();
final TokenID nonFungibleTokenID = TokenID.newBuilder().setTokenNum(1235L).build();
final FcTokenAllowanceId fungibleAllowanceId = FcTokenAllowanceId.from(EntityNum.fromTokenId(fungibleTokenID), payerNum);
final FcTokenAllowanceId nftAllowanceId = FcTokenAllowanceId.from(EntityNum.fromTokenId(nonFungibleTokenID), payerNum);
final TreeMap<EntityNum, Long> cryptoAllowances = new TreeMap<>() {
{
put(payerNum, initialAllowance);
}
};
final TreeMap<FcTokenAllowanceId, Long> fungibleAllowances = new TreeMap<>() {
{
put(fungibleAllowanceId, initialAllowance);
}
};
final TreeMap<FcTokenAllowanceId, FcTokenAllowance> nftAllowances = new TreeMap<>() {
{
put(fungibleAllowanceId, FcTokenAllowance.from(true));
put(nftAllowanceId, FcTokenAllowance.from(List.of(1L, 2L)));
}
};
final var account = new HederaAccountCustomizer().key(JKey.mapKey(origKey)).expiry(origExpiry).proxy(EntityId.fromGrpcAccountId(origProxy)).autoRenewPeriod(origAutoRenew).isDeleted(origIsDeleted).alias(oldAlias).memo(origMemo).isSmartContract(origIsContract).isReceiverSigRequired(origIsReceiverSigReq).customizing(new MerkleAccount());
account.setNumContractKvPairs(oldNumKvPairs);
account.setNftsOwned(origNumNfts);
account.setBalance(origBalance);
account.records().offer(origPayerRecords.get(0));
account.records().offer(origPayerRecords.get(1));
account.setMaxAutomaticAssociations(origMaxAutoAssociations);
account.setAlreadyUsedAutomaticAssociations(origAlreadyUsedAutoAssociations);
final var adminKey = TOKEN_ADMIN_KT.asJKeyUnchecked();
final var unfrozenToken = new MerkleToken(Long.MAX_VALUE, 100, 1, "UnfrozenToken", "UnfrozenTokenName", false, true, new EntityId(1, 2, 3));
unfrozenToken.setFreezeKey(adminKey);
unfrozenToken.setKycKey(adminKey);
final var frozenToken = new MerkleToken(Long.MAX_VALUE, 100, 1, "FrozenToken", "FrozenTokenName", true, false, new EntityId(1, 2, 3));
frozenToken.setFreezeKey(adminKey);
frozenToken.setKycKey(adminKey);
ALIAS.setter().accept(account, newAlias);
IS_DELETED.setter().accept(account, newIsDeleted);
IS_RECEIVER_SIG_REQUIRED.setter().accept(account, newIsReceiverSigReq);
IS_SMART_CONTRACT.setter().accept(account, newIsContract);
BALANCE.setter().accept(account, newBalance);
AUTO_RENEW_PERIOD.setter().accept(account, newAutoRenew);
EXPIRY.setter().accept(account, newExpiry);
KEY.setter().accept(account, newKey);
MEMO.setter().accept(account, newMemo);
PROXY.setter().accept(account, newProxy);
NUM_NFTS_OWNED.setter().accept(account, newNumNfts);
MAX_AUTOMATIC_ASSOCIATIONS.setter().accept(account, newMaxAutoAssociations);
ALREADY_USED_AUTOMATIC_ASSOCIATIONS.setter().accept(account, newAlreadyUsedAutoAssociations);
NUM_CONTRACT_KV_PAIRS.setter().accept(account, newNumKvPairs);
CRYPTO_ALLOWANCES.setter().accept(account, cryptoAllowances);
FUNGIBLE_TOKEN_ALLOWANCES.setter().accept(account, fungibleAllowances);
NFT_ALLOWANCES.setter().accept(account, nftAllowances);
assertEquals(newIsDeleted, IS_DELETED.getter().apply(account));
assertEquals(newIsReceiverSigReq, IS_RECEIVER_SIG_REQUIRED.getter().apply(account));
assertEquals(newIsContract, IS_SMART_CONTRACT.getter().apply(account));
assertEquals(newBalance, BALANCE.getter().apply(account));
assertEquals(newAutoRenew, AUTO_RENEW_PERIOD.getter().apply(account));
assertEquals(newExpiry, EXPIRY.getter().apply(account));
assertEquals(newKey, KEY.getter().apply(account));
assertEquals(newMemo, MEMO.getter().apply(account));
assertEquals(newProxy, PROXY.getter().apply(account));
assertEquals(newNumNfts, NUM_NFTS_OWNED.getter().apply(account));
assertEquals(newAlreadyUsedAutoAssociations, ALREADY_USED_AUTOMATIC_ASSOCIATIONS.getter().apply(account));
assertEquals(newMaxAutoAssociations, MAX_AUTOMATIC_ASSOCIATIONS.getter().apply(account));
assertEquals(newAlias, ALIAS.getter().apply(account));
assertEquals(newNumKvPairs, NUM_CONTRACT_KV_PAIRS.getter().apply(account));
assertEquals(cryptoAllowances, CRYPTO_ALLOWANCES.getter().apply(account));
assertEquals(fungibleAllowances, FUNGIBLE_TOKEN_ALLOWANCES.getter().apply(account));
assertEquals(nftAllowances, NFT_ALLOWANCES.getter().apply(account));
}
use of com.hedera.services.state.merkle.MerkleToken in project hedera-services by hashgraph.
the class TokenPropertyTest method gettersWork.
@Test
void gettersWork() {
// given:
final MerkleToken target = new MerkleToken();
TOTAL_SUPPLY.setter().accept(target, totalSupply);
DECIMALS.setter().accept(target, decimals);
ADMIN_KEY.setter().accept(target, adminKey);
FREEZE_KEY.setter().accept(target, freezeKey);
KYC_KEY.setter().accept(target, kycKey);
PAUSE_KEY.setter().accept(target, pauseKey);
SUPPLY_KEY.setter().accept(target, supplyKey);
FEE_SCHEDULE_KEY.setter().accept(target, feeScheduleKey);
WIPE_KEY.setter().accept(target, wipeKey);
IS_DELETED.setter().accept(target, deleted);
IS_PAUSED.setter().accept(target, paused);
SYMBOL.setter().accept(target, symbol);
NAME.setter().accept(target, name);
TREASURY.setter().accept(target, treasury);
ACC_FROZEN_BY_DEFAULT.setter().accept(target, accountsFrozenByDefault);
EXPIRY.setter().accept(target, expiry);
AUTO_RENEW_PERIOD.setter().accept(target, autoRenewPeriod);
AUTO_RENEW_ACCOUNT.setter().accept(target, autoRenewAccount);
MEMO.setter().accept(target, memo);
LAST_USED_SERIAL_NUMBER.setter().accept(target, lastUsedSerialNumber);
TOKEN_TYPE.setter().accept(target, tokenType);
SUPPLY_TYPE.setter().accept(target, supplyType);
MAX_SUPPLY.setter().accept(target, maxSupply);
FEE_SCHEDULE.setter().accept(target, feeSchedule);
// and:
final var totalSupplyGetter = TOTAL_SUPPLY.getter();
final var adminKeyGetter = ADMIN_KEY.getter();
final var freezeKeyGetter = FREEZE_KEY.getter();
final var kycKeyGetter = KYC_KEY.getter();
final var pauseKeyGetter = PAUSE_KEY.getter();
final var supplyKeyGetter = SUPPLY_KEY.getter();
final var feeScheduleKeyGetter = FEE_SCHEDULE_KEY.getter();
final var wipeKeyGetter = WIPE_KEY.getter();
final var deletedGetter = IS_DELETED.getter();
final var pausedGetter = IS_PAUSED.getter();
final var symbolGetter = SYMBOL.getter();
final var nameGetter = NAME.getter();
final var treasuryGetter = TREASURY.getter();
final var accountsFrozenByDefaultGetter = ACC_FROZEN_BY_DEFAULT.getter();
final var expiryGetter = EXPIRY.getter();
final var autoRenewPeriodGetter = AUTO_RENEW_PERIOD.getter();
final var autoRenewAccountGetter = AUTO_RENEW_ACCOUNT.getter();
final var memoGetter = MEMO.getter();
final var lastUsedSerialNumberGetter = LAST_USED_SERIAL_NUMBER.getter();
final var tokenTypeGetter = TOKEN_TYPE.getter();
final var supplyTypeGetter = SUPPLY_TYPE.getter();
final var maxSupplyGetter = MAX_SUPPLY.getter();
final var feeScheduleGetter = FEE_SCHEDULE.getter();
final var decimalsGetter = DECIMALS.getter();
// expect:
assertEquals(totalSupply, totalSupplyGetter.apply(target));
assertEquals(adminKey, adminKeyGetter.apply(target));
assertEquals(freezeKey, freezeKeyGetter.apply(target));
assertEquals(kycKey, kycKeyGetter.apply(target));
assertEquals(pauseKey, pauseKeyGetter.apply(target));
assertEquals(supplyKey, supplyKeyGetter.apply(target));
assertEquals(feeScheduleKey, feeScheduleKeyGetter.apply(target));
assertEquals(wipeKey, wipeKeyGetter.apply(target));
assertEquals(deleted, deletedGetter.apply(target));
assertEquals(paused, pausedGetter.apply(target));
assertEquals(symbol, symbolGetter.apply(target));
assertEquals(name, nameGetter.apply(target));
assertEquals(treasury, treasuryGetter.apply(target));
assertEquals(accountsFrozenByDefault, accountsFrozenByDefaultGetter.apply(target));
assertEquals(expiry, expiryGetter.apply(target));
assertEquals(autoRenewPeriod, autoRenewPeriodGetter.apply(target));
assertEquals(autoRenewAccount, autoRenewAccountGetter.apply(target));
assertEquals(memo, memoGetter.apply(target));
assertEquals(lastUsedSerialNumber, lastUsedSerialNumberGetter.apply(target));
assertEquals(tokenType, tokenTypeGetter.apply(target));
assertEquals(supplyType, supplyTypeGetter.apply(target));
assertEquals(maxSupply, maxSupplyGetter.apply(target));
assertEquals(feeSchedule, feeScheduleGetter.apply(target));
assertEquals(decimals, decimalsGetter.apply(target));
}
use of com.hedera.services.state.merkle.MerkleToken in project hedera-services by hashgraph.
the class StateViewTest method setup.
@BeforeEach
@SuppressWarnings("unchecked")
private void setup() throws Throwable {
metadata = new HFileMeta(false, TxnHandlingScenario.MISC_FILE_WACL_KT.asJKey(), expiry, fileMemo);
immutableMetadata = new HFileMeta(false, StateView.EMPTY_WACL, expiry);
expectedImmutable = FileGetInfoResponse.FileInfo.newBuilder().setLedgerId(ledgerId).setDeleted(false).setExpirationTime(Timestamp.newBuilder().setSeconds(expiry)).setFileID(target).setSize(data.length).build();
expected = expectedImmutable.toBuilder().setKeys(TxnHandlingScenario.MISC_FILE_WACL_KT.asKey().getKeyList()).setMemo(fileMemo).build();
tokenAccount = MerkleAccountFactory.newAccount().isSmartContract(false).tokens(tokenId).get();
tokenAccount.setNftsOwned(10);
tokenAccount.setMaxAutomaticAssociations(123);
tokenAccount.setAlias(TxnHandlingScenario.TOKEN_ADMIN_KT.asKey().getEd25519());
contract = MerkleAccountFactory.newAccount().alias(create2Address).memo("Stay cold...").numKvPairs(wellKnownNumKvPairs).isSmartContract(true).accountKeys(COMPLEX_KEY_ACCOUNT_KT).proxy(asAccount("0.0.3")).senderThreshold(1_234L).receiverThreshold(4_321L).receiverSigRequired(true).balance(555L).autoRenewPeriod(1_000_000L).deleted(true).expirationTime(9_999_999L).get();
contracts = (MerkleMap<EntityNum, MerkleAccount>) mock(MerkleMap.class);
topics = (MerkleMap<EntityNum, MerkleTopic>) mock(MerkleMap.class);
tokenRels = new MerkleMap<>();
tokenRels.put(EntityNumPair.fromLongs(tokenAccountId.getAccountNum(), tokenId.getTokenNum()), new MerkleTokenRelStatus(123L, false, true, true));
tokenStore = mock(TokenStore.class);
token = new MerkleToken(Long.MAX_VALUE, 100, 1, "UnfrozenToken", "UnfrozenTokenName", true, true, new EntityId(0, 0, 3));
token.setMemo(tokenMemo);
token.setAdminKey(TxnHandlingScenario.TOKEN_ADMIN_KT.asJKey());
token.setFreezeKey(TxnHandlingScenario.TOKEN_FREEZE_KT.asJKey());
token.setKycKey(TxnHandlingScenario.TOKEN_KYC_KT.asJKey());
token.setSupplyKey(COMPLEX_KEY_ACCOUNT_KT.asJKey());
token.setWipeKey(MISC_ACCOUNT_KT.asJKey());
token.setFeeScheduleKey(MISC_ACCOUNT_KT.asJKey());
token.setPauseKey(TxnHandlingScenario.TOKEN_PAUSE_KT.asJKey());
token.setAutoRenewAccount(EntityId.fromGrpcAccountId(autoRenew));
token.setExpiry(expiry);
token.setAutoRenewPeriod(autoRenewPeriod);
token.setDeleted(true);
token.setPaused(true);
token.setTokenType(TokenType.FUNGIBLE_COMMON);
token.setSupplyType(TokenSupplyType.FINITE);
token.setFeeScheduleFrom(grpcCustomFees);
scheduleStore = mock(ScheduleStore.class);
final var scheduleMemo = "For what but eye and ear";
parentScheduleCreate = scheduleCreateTxnWith(SCHEDULE_ADMIN_KT.asKey(), scheduleMemo, payerAccountId, creatorAccountID, MiscUtils.asTimestamp(now.toJava()));
schedule = MerkleSchedule.from(parentScheduleCreate.toByteArray(), expiry);
schedule.witnessValidSignature("01234567890123456789012345678901".getBytes());
schedule.witnessValidSignature("_123456789_123456789_123456789_1".getBytes());
schedule.witnessValidSignature("_o23456789_o23456789_o23456789_o".getBytes());
contents = mock(Map.class);
attrs = mock(Map.class);
bytecode = mock(Map.class);
specialFiles = mock(MerkleSpecialFiles.class);
mockTokenRelsFn = (BiFunction<StateView, EntityNum, List<TokenRelationship>>) mock(BiFunction.class);
StateView.tokenRelsFn = mockTokenRelsFn;
final var uniqueTokens = new MerkleMap<EntityNumPair, MerkleUniqueToken>();
uniqueTokens.put(targetNftKey, targetNft);
uniqueTokens.put(treasuryNftKey, treasuryNft);
storage = (VirtualMap<VirtualBlobKey, VirtualBlobValue>) mock(VirtualMap.class);
contractStorage = (VirtualMap<ContractKey, ContractValue>) mock(VirtualMap.class);
children = new MutableStateChildren();
children.setUniqueTokens(uniqueTokens);
children.setAccounts(contracts);
children.setTokenAssociations(tokenRels);
children.setSpecialFiles(specialFiles);
networkInfo = mock(NetworkInfo.class);
subject = new StateView(tokenStore, scheduleStore, children, networkInfo);
subject.fileAttrs = attrs;
subject.fileContents = contents;
subject.contractBytecode = bytecode;
}
use of com.hedera.services.state.merkle.MerkleToken in project hedera-services by hashgraph.
the class TokenMetaUtilsTest method classifiesRoyaltyWithFallback.
@Test
void classifiesRoyaltyWithFallback() {
// setup:
final var treasury = new EntityId(1, 2, 4);
var royaltyFeeWithFallbackToken = new MerkleToken(Long.MAX_VALUE, 100, 1, "ZPHYR", "West Wind Art", false, true, treasury);
royaltyFeeWithFallbackToken.setTokenType(NON_FUNGIBLE_UNIQUE);
royaltyFeeWithFallbackToken.setFeeSchedule(List.of(FcCustomFee.royaltyFee(1, 2, new FixedFeeSpec(1, null), new EntityId(1, 2, 5))));
// given:
final var meta = TokenMetaUtils.signingMetaFrom(royaltyFeeWithFallbackToken);
// expect:
assertTrue(meta.hasRoyaltyWithFallback());
assertSame(treasury, meta.treasury());
}
Aggregations