Search in sources :

Example 86 with HapiApiSpec

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

the class DissociatePrecompileSuite method dissociatePrecompileHasExpectedSemanticsForDeletedTokens.

/* -- Not specifically required in the HTS Precompile Test Plan -- */
public HapiApiSpec dissociatePrecompileHasExpectedSemanticsForDeletedTokens() {
    final String tbdUniqToken = "UniqToBeDeleted";
    final String zeroBalanceFrozen = "0bFrozen";
    final String zeroBalanceUnfrozen = "0bUnfrozen";
    final String nonZeroBalanceFrozen = "1bFrozen";
    final String nonZeroBalanceUnfrozen = "1bUnfrozen";
    final long initialSupply = 100L;
    final long nonZeroXfer = 10L;
    final var firstMeta = ByteString.copyFrom("FIRST".getBytes(StandardCharsets.UTF_8));
    final var secondMeta = ByteString.copyFrom("SECOND".getBytes(StandardCharsets.UTF_8));
    final var thirdMeta = ByteString.copyFrom("THIRD".getBytes(StandardCharsets.UTF_8));
    final AtomicReference<AccountID> accountID = new AtomicReference<>();
    final AtomicReference<AccountID> treasuryID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdTokenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdUniqueTokenID = new AtomicReference<>();
    return defaultHapiSpec("DissociatePrecompileHasExpectedSemanticsForDeletedTokens").given(newKeyNamed(MULTI_KEY), cryptoCreate(ACCOUNT).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(accountID::set), fileCreate(THE_CONTRACT), updateLargeFile(ACCOUNT, THE_CONTRACT, extractByteCode(ContractResources.ASSOCIATE_DISSOCIATE_CONTRACT)), cryptoCreate(TOKEN_TREASURY).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(treasuryID::set), tokenCreate(TBD_TOKEN).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(initialSupply).treasury(TOKEN_TREASURY).freezeKey(MULTI_KEY).freezeDefault(true).exposingCreatedIdTo(id -> tbdTokenID.set(asToken(id))), tokenCreate(tbdUniqToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(0).exposingCreatedIdTo(id -> tbdUniqueTokenID.set(asToken(id))), cryptoCreate(zeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceFrozenID::set), cryptoCreate(zeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceUnfrozenID::set), cryptoCreate(nonZeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceFrozenID::set), cryptoCreate(nonZeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceUnfrozenID::set)).when(withOpContext((spec, opLog) -> allRunFor(spec, contractCreate(THE_CONTRACT).bytecode(THE_CONTRACT).gas(GAS_TO_OFFER), tokenAssociate(zeroBalanceFrozen, TBD_TOKEN), tokenAssociate(zeroBalanceUnfrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceFrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceUnfrozen, TBD_TOKEN), mintToken(tbdUniqToken, List.of(firstMeta, secondMeta, thirdMeta)), getAccountInfo(TOKEN_TREASURY).hasOwnedNfts(3), tokenUnfreeze(TBD_TOKEN, zeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceFrozen), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceFrozen)), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceUnfrozen)), tokenFreeze(TBD_TOKEN, nonZeroBalanceFrozen), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer), tokenDelete(TBD_TOKEN), tokenDelete(tbdUniqToken), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceFrozenTxn"), getTxnRecord("dissociateZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceFrozenTxn"), getTxnRecord("dissociateNonZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateNonZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(treasuryID.get()), asAddress(tbdUniqueTokenID.get())).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).payingWith(TOKEN_TREASURY)))).then(childRecordsCheck("dissociateZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), getAccountInfo(zeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(zeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(TOKEN_TREASURY).hasToken(relationshipWith(TBD_TOKEN)).hasNoTokenRelationship(tbdUniqToken).hasOwnedNfts(0), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer));
}
Also used : SINGLE_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_DISSOCIATE) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TBD_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.TBD_TOKEN) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) MULTIPLE_TOKENS_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPLE_TOKENS_DISSOCIATE) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) StandardCharsets(java.nio.charset.StandardCharsets) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) FREEZABLE_TOKEN_ON_BY_DEFAULT(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.FREEZABLE_TOKEN_ON_BY_DEFAULT) NESTED_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.NESTED_TOKEN_DISSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) 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) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) VANILLA_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.VANILLA_TOKEN) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) KNOWABLE_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.KNOWABLE_TOKEN) TokenID(com.hederahashgraph.api.proto.java.TokenID) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) LogManager(org.apache.logging.log4j.LogManager) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AccountID(com.hederahashgraph.api.proto.java.AccountID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 87 with HapiApiSpec

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

the class CongestionPricingSuite method canUpdateMultipliersDynamically.

private HapiApiSpec canUpdateMultipliersDynamically() {
    var artificialLimits = protoDefsFromResource("testSystemFiles/artificial-limits.json");
    var defaultThrottles = protoDefsFromResource("testSystemFiles/throttles-dev.json");
    String tmpMinCongestionPeriod = "1";
    AtomicLong normalPrice = new AtomicLong();
    AtomicLong sevenXPrice = new AtomicLong();
    return defaultHapiSpec("CanUpdateMultipliersDynamically").given(cryptoCreate("civilian").payingWith(GENESIS).balance(ONE_MILLION_HBARS), fileCreate("bytecode").path(ContractResources.MULTIPURPOSE_BYTECODE_PATH).payingWith(GENESIS), contractCreate("scMulti").bytecode("bytecode").payingWith(GENESIS), contractCall("scMulti").payingWith("civilian").fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("cheapCall"), getTxnRecord("cheapCall").providingFeeTo(normalFee -> {
        log.info("Normal fee is {}", normalFee);
        normalPrice.set(normalFee);
    })).when(fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", "1,7x", "fees.minCongestionPeriod", tmpMinCongestionPeriod)), fileUpdate(THROTTLE_DEFS).payingWith(EXCHANGE_RATE_CONTROL).contents(artificialLimits.toByteArray()), blockingOrder(IntStream.range(0, 10).mapToObj(i -> contractCall("scMulti").payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR)).toArray(HapiSpecOperation[]::new)), contractCall("scMulti").payingWith("civilian").fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("pricyCall")).then(getTxnRecord("pricyCall").payingWith(GENESIS).providingFeeTo(congestionFee -> {
        log.info("Congestion fee is {}", congestionFee);
        sevenXPrice.set(congestionFee);
    }), withOpContext((spec, opLog) -> {
        Assertions.assertEquals(7.0, (1.0 * sevenXPrice.get()) / normalPrice.get(), 0.1, "~7x multiplier should be in affect!");
    }), fileUpdate(THROTTLE_DEFS).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).contents(defaultThrottles.toByteArray()), fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", defaultCongestionMultipliers, "fees.minCongestionPeriod", defaultMinCongestionPeriod)), /* Make sure the multiplier is reset before the next spec runs */
    cryptoTransfer(HapiCryptoTransfer.tinyBarsFromTo(GENESIS, FUNDING, 1)).payingWith(GENESIS));
}
Also used : IntStream(java.util.stream.IntStream) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ThrottleDefsLoader.protoDefsFromResource(com.hedera.services.bdd.suites.utils.sysfiles.serdes.ThrottleDefsLoader.protoDefsFromResource) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) UtilVerbs.blockingOrder(com.hedera.services.bdd.spec.utilops.UtilVerbs.blockingOrder) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Assertions(org.junit.jupiter.api.Assertions) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) HapiCryptoTransfer(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Example 88 with HapiApiSpec

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

the class CreateAndUpdateOps method variousCryptoMutations.

HapiApiSpec variousCryptoMutations() {
    KeyShape smallKey = SIMPLE;
    KeyShape largeKey = listOf(3);
    long shortExpiry = 100_000L;
    long mediumExpiry = 10 * shortExpiry;
    long eternalExpiry = 10 * mediumExpiry;
    AtomicLong consensusNow = new AtomicLong();
    return customHapiSpec("VariousCryptoMutations").withProperties(Map.of("cost.snapshot.mode", costSnapshotMode.toString())).given(newKeyNamed("sk").shape(smallKey), newKeyNamed("lk").shape(largeKey), 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());
    }), cryptoCreate("proxy").fee(feeToOffer)).when(cryptoCreate("sksenp").fee(feeToOffer).payingWith("payer").key("sk").autoRenewSecs(shortExpiry), cryptoCreate("sksep").fee(feeToOffer).payingWith("payer").proxy("0.0.2").key("sk").autoRenewSecs(shortExpiry), cryptoCreate("skmenp").fee(feeToOffer).payingWith("payer").key("sk").autoRenewSecs(mediumExpiry), cryptoCreate("skmep").fee(feeToOffer).payingWith("payer").proxy("0.0.2").key("sk").autoRenewSecs(mediumExpiry), cryptoCreate("skeenp").fee(feeToOffer).payingWith("payer").key("sk").autoRenewSecs(eternalExpiry), cryptoCreate("skeep").fee(feeToOffer).payingWith("payer").proxy("0.0.2").key("sk").autoRenewSecs(eternalExpiry)).then(sourcing(() -> cryptoUpdate("sksenp").fee(feeToOffer).payingWith("payer").newProxy("proxy").key("lk").expiring(consensusNow.get() + mediumExpiry)), sourcing(() -> cryptoUpdate("skmenp").fee(feeToOffer).payingWith("payer").newProxy("proxy").key("lk").expiring(consensusNow.get() + eternalExpiry)), sourcing(() -> cryptoUpdate("skeenp").fee(feeToOffer).payingWith("payer").newProxy("proxy").key("lk")), getAccountInfo("sksenp"), getAccountInfo("skmenp"), getAccountInfo("skeenp"));
}
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 89 with HapiApiSpec

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

the class ExtCodeCopyOperationSuite method verifiesExistence.

HapiApiSpec verifiesExistence() {
    final String CONTRACT = "extCodeCopyOpChecker";
    final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
    ByteString EMPTY_BYTECODE = ByteString.EMPTY;
    return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate("extCodeCopyOpChecker").bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
        AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
        ContractID contractID = spec.registry().getContractId(CONTRACT);
        String accountSolidityAddress = asHexedSolidityAddress(accountID);
        String contractAddress = asHexedSolidityAddress(contractID);
        final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).via("callRecord");
        final var callRecord = getTxnRecord("callRecord");
        final var accountCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).saveResultTo("accountCode");
        final var contractCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, contractAddress).saveResultTo("contractCode");
        final var getBytecodeCall = getContractBytecode(CONTRACT).saveResultTo("contractGetBytecode");
        allRunFor(spec, call, callRecord, accountCodeCallLocal, contractCodeCallLocal, getBytecodeCall);
        final var recordResult = callRecord.getResponseRecord().getContractCallResult();
        final var accountCode = spec.registry().getBytes("accountCode");
        final var contractCode = spec.registry().getBytes("contractCode");
        final var getBytecode = spec.registry().getBytes("contractGetBytecode");
        Assertions.assertEquals(EMPTY_BYTECODE, recordResult.getContractCallResult());
        Assertions.assertArrayEquals(EMPTY_BYTECODE.toByteArray(), accountCode);
        Assertions.assertArrayEquals(getBytecode, contractCode);
    }));
}
Also used : UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Assertions(org.junit.jupiter.api.Assertions) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) HapiPropertySource.asHexedSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress) 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) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) AccountID(com.hederahashgraph.api.proto.java.AccountID) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 90 with HapiApiSpec

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

the class ExtCodeHashOperationSuite method verifiesExistence.

HapiApiSpec verifiesExistence() {
    final String CONTRACT = "extCodeHashOpChecker";
    final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
    final ByteString EXPECTED_ACCOUNT_HASH = ByteString.copyFrom(Hash.keccak256(Bytes.EMPTY).toArray());
    return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate(CONTRACT).bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
        AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
        ContractID contractID = spec.registry().getContractId(CONTRACT);
        String accountSolidityAddress = asHexedSolidityAddress(accountID);
        String contractAddress = asHexedSolidityAddress(contractID);
        final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).via("callRecord");
        final var callRecord = getTxnRecord("callRecord");
        final var accountCodeHashCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).saveResultTo("accountCodeHash");
        final var contractCodeHash = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, contractAddress).saveResultTo("contractCodeHash");
        final var getBytecode = getContractBytecode(CONTRACT).saveResultTo("contractBytecode");
        allRunFor(spec, call, callRecord, accountCodeHashCallLocal, contractCodeHash, getBytecode);
        final var recordResult = callRecord.getResponseRecord().getContractCallResult();
        final var accountCodeHash = spec.registry().getBytes("accountCodeHash");
        final var contractCodeResult = spec.registry().getBytes("contractCodeHash");
        final var contractBytecode = spec.registry().getBytes("contractBytecode");
        final var expectedContractCodeHash = ByteString.copyFrom(Hash.keccak256(Bytes.of(contractBytecode)).toArray()).toByteArray();
        Assertions.assertEquals(EXPECTED_ACCOUNT_HASH, recordResult.getContractCallResult());
        Assertions.assertArrayEquals(EXPECTED_ACCOUNT_HASH.toByteArray(), accountCodeHash);
        Assertions.assertArrayEquals(expectedContractCodeHash, contractCodeResult);
    }));
}
Also used : UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) Bytes(org.apache.tuweni.bytes.Bytes) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) Hash(org.hyperledger.besu.crypto.Hash) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Assertions(org.junit.jupiter.api.Assertions) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) HapiPropertySource.asHexedSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress) 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) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) AccountID(com.hederahashgraph.api.proto.java.AccountID) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID)

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