Search in sources :

Example 11 with HapiApiSpec

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

the class ExchangeRateControlSuite method acct57UpdatesMidnightRateAtMidNight.

private HapiApiSpec acct57UpdatesMidnightRateAtMidNight() throws ParseException {
    return defaultHapiSpec("Acct57UpdatesMidnightRateAtMidNight").given(resetRatesOp, cryptoTransfer(tinyBarsFromTo(GENESIS, EXCHANGE_RATE_CONTROL, ADEQUATE_FUNDS))).when(// should be done just before midnight
    UtilVerbs.waitUntil("23:58"), fileUpdate(EXCHANGE_RATES).contents(spec -> {
        ByteString newRates = spec.ratesProvider().rateSetWith(10, 147).toByteString();
        spec.registry().saveBytes("midnightRate", newRates);
        return newRates;
    }).payingWith(EXCHANGE_RATE_CONTROL)).then(// should be the first transaction after midnight
    UtilVerbs.sleepFor(300_000), fileUpdate(EXCHANGE_RATES).contents(spec -> {
        ByteString newRates = spec.ratesProvider().rateSetWith(10, 183).toByteString();
        spec.registry().saveBytes("newRates", newRates);
        return newRates;
    }).payingWith(EXCHANGE_RATE_CONTROL), getFileContents(EXCHANGE_RATES).hasContents(spec -> spec.registry().getBytes("newRates")), resetRatesOp);
}
Also used : QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) EXCHANGE_RATE_CHANGE_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.EXCHANGE_RATE_CHANGE_LIMIT_EXCEEDED) Arrays(java.util.Arrays) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) AUTHORIZATION_FAILED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTHORIZATION_FAILED) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) ParseException(java.text.ParseException) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) HapiFileUpdate(com.hedera.services.bdd.spec.transactions.file.HapiFileUpdate) LogManager(org.apache.logging.log4j.LogManager) ByteString(com.google.protobuf.ByteString)

Example 12 with HapiApiSpec

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

the class ContractCreateSuite method receiverSigReqTransferRecipientMustSignWithFullPubKeyPrefix.

private HapiApiSpec receiverSigReqTransferRecipientMustSignWithFullPubKeyPrefix() {
    final var justSendInitcode = "justSendInitcode";
    final var sendInternalAndDelegateInitcode = "sendInternalAndDelegateInitcode";
    final var justSend = "justSend";
    final var sendInternalAndDelegate = "sendInternalAndDelegate";
    final var beneficiary = "civilian";
    final var balanceToDistribute = 1_000L;
    final AtomicLong justSendContractNum = new AtomicLong();
    final AtomicLong beneficiaryAccountNum = new AtomicLong();
    return defaultHapiSpec("ReceiverSigReqTransferRecipientMustSignWithFullPubKeyPrefix").given(cryptoCreate(beneficiary).balance(0L).receiverSigRequired(true).exposingCreatedIdTo(id -> beneficiaryAccountNum.set(id.getAccountNum())), fileCreate(justSendInitcode).path(ContractResources.JUST_SEND_BYTECODE_PATH), fileCreate(sendInternalAndDelegateInitcode).path(ContractResources.SEND_INTERNAL_AND_DELEGATE_BYTECODE_PATH)).when(contractCreate(justSend).bytecode(justSendInitcode).gas(300_000L).exposingNumTo(justSendContractNum::set), contractCreate(sendInternalAndDelegate).bytecode(sendInternalAndDelegateInitcode).gas(300_000L).balance(balanceToDistribute)).then(/* Sending requires receiver signature */
    sourcing(() -> contractCall(sendInternalAndDelegate, SEND_REPEATEDLY_ABI, justSendContractNum.get(), beneficiaryAccountNum.get(), balanceToDistribute / 2).hasKnownStatus(INVALID_SIGNATURE)), /* But it's not enough to just sign using an incomplete prefix */
    sourcing(() -> contractCall(sendInternalAndDelegate, SEND_REPEATEDLY_ABI, justSendContractNum.get(), beneficiaryAccountNum.get(), balanceToDistribute / 2).signedBy(DEFAULT_PAYER, beneficiary).hasKnownStatus(INVALID_SIGNATURE)), /* We have to specify the full prefix so the sig can be verified async */
    getAccountInfo(beneficiary).logged(), sourcing(() -> contractCall(sendInternalAndDelegate, SEND_REPEATEDLY_ABI, justSendContractNum.get(), beneficiaryAccountNum.get(), balanceToDistribute / 2).alsoSigningWithFullPrefix(beneficiary)), getAccountBalance(beneficiary).logged());
}
Also used : Arrays(java.util.Arrays) ContractFnResultAsserts.isContractWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isContractWith) SEND_REPEATEDLY_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_REPEATEDLY_ABI) SigControl(com.hedera.services.bdd.spec.keys.SigControl) 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) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ContractID(com.hederahashgraph.api.proto.java.ContractID) EMPTY_CONSTRUCTOR(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.EMPTY_CONSTRUCTOR) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) FIBONACCI_PLUS_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI) CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.CONTRACT) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) BigInteger(java.math.BigInteger) Bytes32(org.apache.tuweni.bytes.Bytes32) Path(java.nio.file.Path) Longs(com.google.common.primitives.Longs) 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) TRANSACTION_OVERSIZE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_OVERSIZE) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) UncheckedIOException(java.io.UncheckedIOException) MEMO_TOO_LONG(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MEMO_TOO_LONG) List(java.util.List) ControlForKey.forKey(com.hedera.services.bdd.spec.keys.ControlForKey.forKey) Logger(org.apache.logging.log4j.Logger) CONSPICUOUS_DONATION_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CONSPICUOUS_DONATION_ABI) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) IntStream(java.util.stream.IntStream) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) SEND_THEN_REVERT_NESTED_SENDS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_THEN_REVERT_NESTED_SENDS_ABI) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) MAX_GAS_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_GAS_LIMIT_EXCEEDED) MULTIPURPOSE_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPURPOSE_BYTECODE_PATH) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) UtilVerbs.newKeyListNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyListNamed) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PROPAGATE_NESTED_CREATIONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.PROPAGATE_NESTED_CREATIONS_ABI) FIBONACCI_PLUS_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH) Files(java.nio.file.Files) ERROR_DECODING_BYTESTRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ERROR_DECODING_BYTESTRING) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) IOException(java.io.IOException) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) UtilVerbs.contractListWithPropertiesInheritedFrom(com.hedera.services.bdd.spec.utilops.UtilVerbs.contractListWithPropertiesInheritedFrom) ContractFnResultAsserts.isLiteralResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) HapiPropertySource.asSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asSolidityAddress) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) OFF(com.hedera.services.bdd.spec.keys.SigControl.OFF) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) THRESHOLD(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType.THRESHOLD) Assertions(org.junit.jupiter.api.Assertions) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) ADD_NTH_FIB_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) ContractInfoAsserts.contractWith(com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 13 with HapiApiSpec

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

the class ContractCreateSuite method canCallPendingContractSafely.

private HapiApiSpec canCallPendingContractSafely() {
    final int numSlots = 64;
    final int createBurstSize = 500;
    final int[] targets = { 19, 24 };
    final AtomicLong createdFileNum = new AtomicLong();
    final var callTxn = "callTxn";
    final var initcode = "initcode";
    return defaultHapiSpec("CanCallPendingContractSafely").given(UtilVerbs.overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(FIBONACCI_PLUS_PATH).payingWith(GENESIS).exposingNumTo(createdFileNum::set), inParallel(IntStream.range(0, createBurstSize).mapToObj(i -> contractCreate("contract" + i, FIBONACCI_PLUS_CONSTRUCTOR_ABI, numSlots).fee(ONE_HUNDRED_HBARS).gas(300_000L).payingWith(GENESIS).noLogging().deferStatusResolution().bytecode(initcode).adminKey(THRESHOLD)).toArray(HapiSpecOperation[]::new))).when().then(sourcing(() -> contractCall("0.0." + (createdFileNum.get() + createBurstSize), ADD_NTH_FIB_ABI, targets, 12).payingWith(GENESIS).gas(300_000L).via(callTxn)), UtilVerbs.resetAppPropertiesTo("src/main/resource/bootstrap.properties"));
}
Also used : Arrays(java.util.Arrays) ContractFnResultAsserts.isContractWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isContractWith) SEND_REPEATEDLY_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_REPEATEDLY_ABI) SigControl(com.hedera.services.bdd.spec.keys.SigControl) 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) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ContractID(com.hederahashgraph.api.proto.java.ContractID) EMPTY_CONSTRUCTOR(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.EMPTY_CONSTRUCTOR) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) FIBONACCI_PLUS_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI) CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.CONTRACT) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) BigInteger(java.math.BigInteger) Bytes32(org.apache.tuweni.bytes.Bytes32) Path(java.nio.file.Path) Longs(com.google.common.primitives.Longs) 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) TRANSACTION_OVERSIZE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_OVERSIZE) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) UncheckedIOException(java.io.UncheckedIOException) MEMO_TOO_LONG(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MEMO_TOO_LONG) List(java.util.List) ControlForKey.forKey(com.hedera.services.bdd.spec.keys.ControlForKey.forKey) Logger(org.apache.logging.log4j.Logger) CONSPICUOUS_DONATION_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CONSPICUOUS_DONATION_ABI) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) IntStream(java.util.stream.IntStream) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) SEND_THEN_REVERT_NESTED_SENDS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SEND_THEN_REVERT_NESTED_SENDS_ABI) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) MAX_GAS_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_GAS_LIMIT_EXCEEDED) MULTIPURPOSE_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPURPOSE_BYTECODE_PATH) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) UtilVerbs.newKeyListNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyListNamed) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PROPAGATE_NESTED_CREATIONS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.PROPAGATE_NESTED_CREATIONS_ABI) FIBONACCI_PLUS_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH) Files(java.nio.file.Files) ERROR_DECODING_BYTESTRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ERROR_DECODING_BYTESTRING) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) IOException(java.io.IOException) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) UtilVerbs.contractListWithPropertiesInheritedFrom(com.hedera.services.bdd.spec.utilops.UtilVerbs.contractListWithPropertiesInheritedFrom) ContractFnResultAsserts.isLiteralResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) HapiPropertySource.asSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asSolidityAddress) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) OFF(com.hedera.services.bdd.spec.keys.SigControl.OFF) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) THRESHOLD(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType.THRESHOLD) Assertions(org.junit.jupiter.api.Assertions) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) ADD_NTH_FIB_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) ContractInfoAsserts.contractWith(com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 14 with HapiApiSpec

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

the class CryptoCreateSuite method createAnAccountInvalidThresholdKey.

// One of element in threshold key is not valid
private HapiApiSpec createAnAccountInvalidThresholdKey() {
    KeyShape emptyListShape = listOf(0);
    KeyShape thresholdShape = threshOf(1, SIMPLE, SIMPLE, emptyListShape);
    long initialBalance = 10_000L;
    // build a threshold key with one of key is invalid
    Key randomKey1 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key randomKey2 = Key.newBuilder().setEd25519(ByteString.copyFrom(randomUtf8Bytes(32))).build();
    Key shortKey = Key.newBuilder().setEd25519(ByteString.copyFrom(new byte[10])).build();
    KeyList invalidKeyList = KeyList.newBuilder().addKeys(randomKey1).addKeys(randomKey2).addKeys(shortKey).build();
    ThresholdKey invalidThresholdKey = ThresholdKey.newBuilder().setThreshold(2).setKeys(invalidKeyList).build();
    Key regKey1 = Key.newBuilder().setThresholdKey(invalidThresholdKey).build();
    Key regKey2 = Key.newBuilder().setKeyList(invalidKeyList).build();
    return defaultHapiSpec("createAnAccountInvalidThresholdKey").given().when().then(withOpContext((spec, opLog) -> {
        spec.registry().saveKey("regKey1", regKey1);
        spec.registry().saveKey("regKey2", regKey2);
    }), cryptoCreate("badThresholdKeyAccount").keyShape(thresholdShape).balance(initialBalance).logged().hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount2").key("regKey1").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING), cryptoCreate("badThresholdKeyAccount3").key("regKey2").balance(initialBalance).logged().signedBy(GENESIS).hasPrecheck(BAD_ENCODING));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KEY_REQUIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_REQUIRED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) KeyList(com.hederahashgraph.api.proto.java.KeyList) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) UtilVerbs.validateChargedUsd(com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd) REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) KeyList(com.hederahashgraph.api.proto.java.KeyList) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey)

Example 15 with HapiApiSpec

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

the class CryptoCreateSuite method createAnAccountInvalidED25519.

private HapiApiSpec createAnAccountInvalidED25519() {
    long initialBalance = 10_000L;
    Key emptyKey = Key.newBuilder().setEd25519(ByteString.EMPTY).build();
    Key shortKey = Key.newBuilder().setEd25519(ByteString.copyFrom(new byte[10])).build();
    return defaultHapiSpec("createAnAccountInvalidED25519").given().when().then(withOpContext((spec, opLog) -> {
        spec.registry().saveKey("shortKey", shortKey);
        spec.registry().saveKey("emptyKey", emptyKey);
    }), cryptoCreate("shortKey").key("shortKey").balance(initialBalance).signedBy(GENESIS).logged().hasPrecheck(BAD_ENCODING), cryptoCreate("emptyKey").key("emptyKey").balance(initialBalance).signedBy(GENESIS).logged().hasPrecheck(BAD_ENCODING));
}
Also used : TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) KEY_REQUIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.KEY_REQUIRED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) KeyList(com.hederahashgraph.api.proto.java.KeyList) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) UtilVerbs.validateChargedUsd(com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd) REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Key(com.hederahashgraph.api.proto.java.Key) ThresholdKey(com.hederahashgraph.api.proto.java.ThresholdKey)

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