Search in sources :

Example 6 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class ContractMintHTSSuite method helloWorldNftMint.

private HapiApiSpec helloWorldNftMint() {
    final var hwMintInitCode = "hwMintInitCode";
    final var nonFungibleToken = "nonFungibleToken";
    final var multiKey = "purpose";
    final var contractKey = "meaning";
    final var hwMint = "hwMint";
    final var firstMintTxn = "firstMintTxn";
    final var secondMintTxn = "secondMintTxn";
    final AtomicLong nonFungibleNum = new AtomicLong();
    return defaultHapiSpec("HelloWorldNftMint").given(newKeyNamed(multiKey), fileCreate(hwMintInitCode).path(ContractResources.HW_MINT_PATH), tokenCreate(nonFungibleToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).initialSupply(0).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> nonFungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(hwMint, HW_MINT_CONS_ABI, nonFungibleNum.get()).bytecode(hwMintInitCode).gas(GAS_TO_OFFER))).then(contractCall(hwMint, HW_MINT_CALL_ABI).via(firstMintTxn).gas(GAS_TO_OFFER).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTokenInfo(nonFungibleToken).hasTotalSupply(1), /* And now make the token contract-controlled so no explicit supply sig is required */
    newKeyNamed(contractKey).shape(DELEGATE_CONTRACT.signedWith(hwMint)), tokenUpdate(nonFungibleToken).supplyKey(contractKey), getTokenInfo(nonFungibleToken).logged(), contractCall(hwMint, HW_MINT_CALL_ABI).via(secondMintTxn).gas(GAS_TO_OFFER), getTxnRecord(secondMintTxn).andAllChildRecords().logged(), getTokenInfo(nonFungibleToken).hasTotalSupply(2), getTokenNftInfo(nonFungibleToken, 2L).logged());
}
Also used : QueryVerbs.getTokenNftInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenNftInfo) Arrays(java.util.Arrays) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) ContractLogAsserts.logWith(com.hedera.services.bdd.spec.assertions.ContractLogAsserts.logWith) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) NonFungibleTransfers(com.hedera.services.bdd.spec.assertions.NonFungibleTransfers) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnVerbs.tokenUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) HW_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_MINT_CALL_ABI) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) MINT_CONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_CONS_ABI) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) MINT_FUNGIBLE_WITH_EVENT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_FUNGIBLE_WITH_EVENT_CALL_ABI) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiPropertySource.asDotDelimitedLongArray(com.hedera.services.bdd.spec.HapiPropertySource.asDotDelimitedLongArray) HW_MINT_CONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_MINT_CONS_ABI) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) HTSPrecompileResult.htsPrecompileResult(com.hedera.services.bdd.suites.utils.contracts.precompile.HTSPrecompileResult.htsPrecompileResult) HW_BRRR_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_BRRR_CALL_ABI) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) HTSPrecompileResult(com.hedera.services.bdd.suites.utils.contracts.precompile.HTSPrecompileResult) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MINT_NON_FUNGIBLE_WITH_EVENT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_NON_FUNGIBLE_WITH_EVENT_CALL_ABI) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) Utils.parsedToByteString(com.hedera.services.bdd.suites.contract.Utils.parsedToByteString) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) LogManager(org.apache.logging.log4j.LogManager) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 7 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class ContractMintHTSSuite method happyPathFungibleTokenMint.

private HapiApiSpec happyPathFungibleTokenMint() {
    final var theAccount = "anybody";
    final var mintContractByteCode = "mintContractByteCode";
    final var amount = 10L;
    final var fungibleToken = "fungibleToken";
    final var multiKey = "purpose";
    final var theContract = "mintContract";
    final var firstMintTxn = "firstMintTxn";
    final AtomicLong fungibleNum = new AtomicLong();
    return defaultHapiSpec("FungibleMint").given(newKeyNamed(multiKey), cryptoCreate(theAccount).balance(ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.MINT_CONTRACT)), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract, MINT_CONS_ABI, fungibleNum.get()).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(contractCall(theContract, MINT_FUNGIBLE_WITH_EVENT_CALL_ABI, amount).via(firstMintTxn).payingWith(theAccount).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTxnRecord(firstMintTxn).hasPriority(recordWith().contractCallResult(resultWith().logs(inOrder(logWith().noData().withTopicsInOrder(List.of(parsedToByteString(amount), parsedToByteString(0))))))), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
Also used : QueryVerbs.getTokenNftInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenNftInfo) Arrays(java.util.Arrays) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) ContractLogAsserts.logWith(com.hedera.services.bdd.spec.assertions.ContractLogAsserts.logWith) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) NonFungibleTransfers(com.hedera.services.bdd.spec.assertions.NonFungibleTransfers) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnVerbs.tokenUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) HW_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_MINT_CALL_ABI) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) MINT_CONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_CONS_ABI) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) MINT_FUNGIBLE_WITH_EVENT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_FUNGIBLE_WITH_EVENT_CALL_ABI) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiPropertySource.asDotDelimitedLongArray(com.hedera.services.bdd.spec.HapiPropertySource.asDotDelimitedLongArray) HW_MINT_CONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_MINT_CONS_ABI) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) HTSPrecompileResult.htsPrecompileResult(com.hedera.services.bdd.suites.utils.contracts.precompile.HTSPrecompileResult.htsPrecompileResult) HW_BRRR_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.HW_BRRR_CALL_ABI) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) HTSPrecompileResult(com.hedera.services.bdd.suites.utils.contracts.precompile.HTSPrecompileResult) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MINT_NON_FUNGIBLE_WITH_EVENT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_NON_FUNGIBLE_WITH_EVENT_CALL_ABI) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) Utils.parsedToByteString(com.hedera.services.bdd.suites.contract.Utils.parsedToByteString) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) LogManager(org.apache.logging.log4j.LogManager) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 8 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class FileUpdateSuite method vanillaUpdateSucceeds.

private HapiApiSpec vanillaUpdateSucceeds() {
    final byte[] old4K = randomUtf8Bytes(BYTES_4K);
    final byte[] new4k = randomUtf8Bytes(BYTES_4K);
    final String firstMemo = "Originally";
    final String secondMemo = "Subsequently";
    return defaultHapiSpec("VanillaUpdateSucceeds").given(fileCreate("test").entityMemo(firstMemo).contents(old4K)).when(fileUpdate("test").entityMemo(ZERO_BYTE_MEMO).contents(new4k).hasPrecheck(INVALID_ZERO_BYTE_IN_STRING), fileUpdate("test").entityMemo(secondMemo).contents(new4k)).then(getFileContents("test").hasContents(ignore -> new4k), getFileInfo("test").hasMemo(secondMemo));
}
Also used : IMAP_USER_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_BYTECODE_PATH) QueryVerbs.getAliasedAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAliasedAccountInfo) MAX_CONTRACT_STORAGE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_CONTRACT_STORAGE_EXCEEDED) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) HapiCryptoTransfer.tinyBarsFromAccountToAlias(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromAccountToAlias) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) CustomFeeSpecs.fixedHtsFee(com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.fixedHtsFee) NOT_SUPPORTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.NOT_SUPPORTED) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) CUSTOM_FEES_LIST_TOO_LONG(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CUSTOM_FEES_LIST_TOO_LONG) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) Set(java.util.Set) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) UtilVerbs.resetAppPropertiesTo(com.hedera.services.bdd.spec.utilops.UtilVerbs.resetAppPropertiesTo) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) IMAP_USER_INSERT(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_INSERT) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TxnVerbs.tokenDissociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDissociate) UtilVerbs.usableTxnIdNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.usableTxnIdNamed) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) BYTES_4K(com.hedera.services.bdd.spec.transactions.TxnUtils.BYTES_4K) UtilVerbs.overriding(com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) KycNotApplicable(com.hederahashgraph.api.proto.java.TokenKycStatus.KycNotApplicable) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Unfrozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Unfrozen) Revoked(com.hederahashgraph.api.proto.java.TokenKycStatus.Revoked) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TxnVerbs(com.hedera.services.bdd.spec.transactions.TxnVerbs) TxnVerbs.uncheckedSubmit(com.hedera.services.bdd.spec.transactions.TxnVerbs.uncheckedSubmit) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) MAX_GAS_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_GAS_LIMIT_EXCEEDED) TokenAssociationSpecs(com.hedera.services.bdd.suites.token.TokenAssociationSpecs) UtilVerbs.overridingTwo(com.hedera.services.bdd.spec.utilops.UtilVerbs.overridingTwo) MAX_STORAGE_IN_PRICE_REGIME_HAS_BEEN_USED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_STORAGE_IN_PRICE_REGIME_HAS_BEEN_USED) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UtilVerbs.updateSpecialFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateSpecialFile) FreezeNotApplicable(com.hederahashgraph.api.proto.java.TokenFreezeStatus.FreezeNotApplicable) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED) TOKEN_ID_REPEATED_IN_TOKEN_LIST(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ID_REPEATED_IN_TOKEN_LIST) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) CONSENSUS_GAS_EXHAUSTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONSENSUS_GAS_EXHAUSTED) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) CustomFeeSpecs.fixedHbarFee(com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.fixedHbarFee) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) ContractInfoAsserts.contractWith(com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith) LogManager(org.apache.logging.log4j.LogManager) ByteString(com.google.protobuf.ByteString)

Example 9 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class CreateAndUpdateOps method variousFileMutations.

HapiApiSpec variousFileMutations() {
    KeyShape smallWacl = listOf(1);
    KeyShape largeWacl = listOf(3);
    byte[] smallContents = TxnUtils.randomUtf8Bytes(1_024);
    byte[] mediumContents = TxnUtils.randomUtf8Bytes(2_048);
    byte[] largeContents = TxnUtils.randomUtf8Bytes(4_096);
    long shortExpiry = 100_000L;
    long mediumExpiry = 10 * shortExpiry;
    long eternalExpiry = 10 * mediumExpiry;
    AtomicLong consensusNow = new AtomicLong();
    return customHapiSpec("VariousFileMutations").withProperties(Map.of("cost.snapshot.mode", costSnapshotMode.toString())).given(newKeyNamed("sk").shape(smallWacl), newKeyNamed("lk").shape(largeWacl), cryptoCreate("payer").via("payerCreation").fee(feeToOffer).balance(payerBalance), withOpContext((spec, opLog) -> {
        var lookup = getTxnRecord("payerCreation").nodePayment(paymentToOffer);
        allRunFor(spec, lookup);
        var record = lookup.getResponseRecord();
        consensusNow.set(record.getConsensusTimestamp().getSeconds());
    })).when(sourcing(() -> fileCreate("sksc").fee(feeToOffer).payingWith("payer").key("sk").contents(smallContents).expiry(consensusNow.get() + shortExpiry)), sourcing(() -> fileCreate("skmc").fee(feeToOffer).payingWith("payer").key("sk").contents(mediumContents).expiry(consensusNow.get() + mediumExpiry)), sourcing(() -> fileCreate("sklc").fee(feeToOffer).payingWith("payer").key("sk").contents(largeContents).expiry(consensusNow.get() + eternalExpiry))).then(fileUpdate("sksc").fee(feeToOffer).payingWith("payer").wacl("lk").extendingExpiryBy(mediumExpiry - shortExpiry), fileUpdate("skmc").fee(feeToOffer).payingWith("payer").wacl("lk").extendingExpiryBy(eternalExpiry - mediumExpiry), getFileInfo("sksc"), getFileInfo("skmc"), getFileInfo("sklc"));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TAKE(com.hedera.services.bdd.spec.HapiApiSpec.CostSnapshotMode.TAKE) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) CostSnapshotMode(com.hedera.services.bdd.spec.HapiApiSpec.CostSnapshotMode) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) HapiApiSpec.customHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 10 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class DiverseStateCreation method createDiverseState.

private HapiApiSpec createDiverseState() {
    final KeyShape SMALL_SHAPE = listOf(threshOf(1, 3));
    final KeyShape MEDIUM_SHAPE = listOf(SIMPLE, threshOf(2, 3));
    final KeyShape LARGE_SHAPE = listOf(SIMPLE, threshOf(1, listOf(SIMPLE, threshOf(1, 2), SIMPLE)), threshOf(2, threshOf(1, SIMPLE, listOf(SIMPLE, SIMPLE)), SIMPLE));
    final var smallKey = "smallKey";
    final var mediumKey = "mediumKey";
    final var largeKey = "largeKey";
    final var fuseInitcode = "fuseInitcode";
    final var multiInitcode = "multiInitcode";
    final var fuseContract = "fuseContract";
    final var multiContract = "multiContract";
    return defaultHapiSpec("CreateDiverseState").given(newKeyNamed(smallKey).shape(SMALL_SHAPE), newKeyNamed(mediumKey).shape(MEDIUM_SHAPE), newKeyNamed(largeKey).shape(LARGE_SHAPE)).when(/* Create some well-known files */
    fileCreate(SMALL_FILE).contents(SMALL_CONTENTS).key(smallKey).expiry(SMALL_EXPIRY_TIME).exposingNumTo(num -> entityNums.put(SMALL_FILE, num)), fileCreate(MEDIUM_FILE).contents("").key(mediumKey).expiry(MEDIUM_EXPIRY_TIME).exposingNumTo(num -> entityNums.put(MEDIUM_FILE, num)), updateLargeFile(GENESIS, MEDIUM_FILE, ByteString.copyFrom(MEDIUM_CONTENTS), false, OptionalLong.of(ONE_HBAR)), fileDelete(MEDIUM_FILE), fileCreate(LARGE_FILE).contents("").key(largeKey).expiry(LARGE_EXPIRY_TIME).exposingNumTo(num -> entityNums.put(LARGE_FILE, num)), updateLargeFile(GENESIS, LARGE_FILE, ByteString.copyFrom(LARGE_CONTENTS), false, OptionalLong.of(ONE_HBAR)), /* Create some bytecode files */
    fileCreate(fuseInitcode).expiry(FUSE_EXPIRY_TIME).path(ContractResources.FUSE_BYTECODE_PATH).exposingNumTo(num -> entityNums.put(FUSE_INITCODE, num)), fileCreate(multiInitcode).expiry(MULTI_EXPIRY_TIME).path(ContractResources.MULTIPURPOSE_BYTECODE_PATH).exposingNumTo(num -> entityNums.put(MULTI_INITCODE, num)), contractCreate(fuseContract).bytecode(fuseInitcode).exposingNumTo(num -> entityNums.put(FUSE_CONTRACT, num)), contractCreate(multiContract).bytecode(multiInitcode).exposingNumTo(num -> entityNums.put(MULTI_CONTRACT, num)), contractCall(multiContract, ContractResources.BELIEVE_IN_ABI, EXPECTED_LUCKY_NO)).then(systemFileDelete(fuseInitcode).payingWith(GENESIS), systemFileDelete(multiInitcode).payingWith(GENESIS), getFileInfo(SMALL_FILE).exposingKeyReprTo(repr -> keyReprs.put(SMALL_FILE, repr)), getFileInfo(MEDIUM_FILE).exposingKeyReprTo(repr -> keyReprs.put(MEDIUM_FILE, repr)), getFileInfo(LARGE_FILE).exposingKeyReprTo(repr -> keyReprs.put(LARGE_FILE, repr)), getContractBytecode(FUSE_CONTRACT).exposingBytecodeTo(code -> hexedBytecode.put(FUSE_BYTECODE, CommonUtils.hex(code))), withOpContext((spec, opLog) -> {
        final var toSerialize = Map.of(ENTITY_NUM_KEY, entityNums, KEY_REPRS_KEY, keyReprs, HEXED_BYTECODE_KEY, hexedBytecode);
        final var om = new ObjectMapper();
        om.writeValue(Files.newOutputStream(Paths.get(STATE_META_JSON_LOC)), toSerialize);
    }));
}
Also used : TxnVerbs.fileDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileDelete) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) HashMap(java.util.HashMap) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) OptionalLong(java.util.OptionalLong) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) TxnVerbs.systemFileDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.systemFileDelete) Files(java.nio.file.Files) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) IOException(java.io.IOException) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) UncheckedIOException(java.io.UncheckedIOException) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) CommonUtils(com.swirlds.common.CommonUtils) Paths(java.nio.file.Paths) QueryVerbs.getContractBytecode(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractBytecode) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)140 List (java.util.List)134 LogManager (org.apache.logging.log4j.LogManager)125 Logger (org.apache.logging.log4j.Logger)125 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)84 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)78 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)76 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)69 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)65 Function (java.util.function.Function)63 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)58 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)56 ByteString (com.google.protobuf.ByteString)53 Key (com.hederahashgraph.api.proto.java.Key)52 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)51 Optional (java.util.Optional)50 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)49 Consumer (java.util.function.Consumer)49 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)47 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)46