Search in sources :

Example 21 with KeyShape

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

the class CryptoCreateSuite method createAnAccountEmptyThresholdKey.

private HapiApiSpec createAnAccountEmptyThresholdKey() {
    KeyShape shape = threshOf(0, 0);
    long initialBalance = 10_000L;
    return defaultHapiSpec("createAnAccountEmptyThresholdKey").given().when().then(cryptoCreate("noKeys").keyShape(shape).balance(initialBalance).logged().hasPrecheck(KEY_REQUIRED));
}
Also used : KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 22 with KeyShape

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

the class CryptoGetInfoRegression method succeedsNormally.

private HapiApiSpec succeedsNormally() {
    long balance = 1_234_567L;
    long autoRenew = 5_555_555L;
    long sendThresh = 1_111L;
    long receiveThresh = 2_222L;
    long expiry = Instant.now().getEpochSecond() + autoRenew;
    KeyShape misc = listOf(SIMPLE, listOf(2));
    return defaultHapiSpec("SucceedsNormally").given(newKeyNamed("misc").shape(misc)).when(cryptoCreate("target").key("misc").proxy("1.2.3").balance(balance).sendThreshold(sendThresh).receiveThreshold(receiveThresh).receiverSigRequired(true).autoRenewSecs(autoRenew)).then(getAccountInfo("target").has(accountWith().accountId("target").solidityId("target").proxy("1.2.3").key("misc").balance(balance).sendThreshold(sendThresh).receiveThreshold(receiveThresh).expiry(expiry, 5L).autoRenew(autoRenew)).logged());
}
Also used : KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 23 with KeyShape

use of com.hedera.services.bdd.spec.keys.KeyShape 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 24 with KeyShape

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

the class KeyExport method exportGenesisKey.

private HapiApiSpec exportGenesisKey() {
    final var r = new Random();
    final int passphraseLength = 24;
    final char[] choices = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
    final KeyShape listOfSizeOne = listOf(1);
    KeyFactory.PEM_PASSPHRASE = IntStream.range(0, passphraseLength).map(ignore -> r.nextInt(choices.length)).mapToObj(i -> Character.valueOf(choices[i]).toString()).collect(Collectors.joining(""));
    return defaultHapiSpec("ExportGenesisKey").given(newKeyNamed("ab-initio").shape(listOfSizeOne)).when().then(withOpContext((spec, opLog) -> {
        opLog.info("Passphrase is: {}", KeyFactory.PEM_PASSPHRASE);
        spec.keys().exportSimpleWacl(PEM_FILE_NAME, "ab-initio");
    }));
}
Also used : IntStream(java.util.stream.IntStream) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Set(java.util.Set) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) Random(java.util.Random) HapiApiSpec.customHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) Collectors(java.util.stream.Collectors) UtilVerbs.keyFromPem(com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromPem) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) 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) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Random(java.util.Random) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 25 with KeyShape

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

the class R5BugChecks method enforcesSigRequirements.

private HapiApiSpec enforcesSigRequirements() {
    KeyShape complexSrShape = listOf(SIMPLE, threshOf(1, 3));
    SigControl activeSig = complexSrShape.signedWith(sigs(ON, sigs(OFF, OFF, ON)));
    SigControl inactiveSig = complexSrShape.signedWith(sigs(OFF, sigs(ON, ON, ON)));
    return defaultHapiSpec("EnforcesSigRequirements").given(newKeyNamed("srKey").shape(complexSrShape), fileCreate("bytecode").path(ContractResources.LAST_TRACKING_SENDER_BYTECODE_PATH), contractCreate("sponsor").bytecode("bytecode").balance(10), cryptoCreate("noSr").balance(0L), cryptoCreate("sr").key("srKey").balance(0L).receiverSigRequired(true)).when(contractCall("sponsor", ContractResources.TRACKING_SEND_ABI, spec -> new Object[] { (int) spec.registry().getAccountID("sr").getAccountNum(), 5 }).hasKnownStatus(INVALID_SIGNATURE), contractCall("sponsor", ContractResources.TRACKING_SEND_ABI, spec -> new Object[] { (int) spec.registry().getAccountID("sr").getAccountNum(), 5 }).signedBy(GENESIS, "sr").sigControl(ControlForKey.forKey("sr", inactiveSig)).hasKnownStatus(INVALID_SIGNATURE), contractCallLocal("sponsor", ContractResources.HOW_MUCH_ABI).has(resultWith().resultThruAbi(ContractResources.HOW_MUCH_ABI, isLiteralResult(new Object[] { BigInteger.valueOf(0) }))), getAccountBalance("sr").hasTinyBars(0L)).then(contractCall("sponsor", ContractResources.TRACKING_SEND_ABI, spec -> new Object[] { (int) spec.registry().getAccountID("noSr").getAccountNum(), 1 }), contractCall("sponsor", ContractResources.TRACKING_SEND_ABI, spec -> new Object[] { (int) spec.registry().getAccountID("sr").getAccountNum(), 5 }).signedBy(GENESIS, "sr").sigControl(ControlForKey.forKey("sr", activeSig)), contractCallLocal("sponsor", ContractResources.HOW_MUCH_ABI).has(resultWith().resultThruAbi(ContractResources.HOW_MUCH_ABI, isLiteralResult(new Object[] { BigInteger.valueOf(5) }))), getAccountBalance("sr").hasTinyBars(5L), getAccountBalance("noSr").hasTinyBars(1L));
}
Also used : OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) SigControl(com.hedera.services.bdd.spec.keys.SigControl) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) AccountInfoAsserts.changeFromSnapshot(com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.changeFromSnapshot) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) BigInteger(java.math.BigInteger) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ControlForKey(com.hedera.services.bdd.spec.keys.ControlForKey) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) ByteString(com.google.protobuf.ByteString) INVALID_ACCOUNT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ACCOUNT_ID) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) TxnVerbs.fileDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileDelete) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UtilVerbs.balanceSnapshot(com.hedera.services.bdd.spec.utilops.UtilVerbs.balanceSnapshot) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TxnVerbs.cryptoDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoDelete) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) TransferList(com.hederahashgraph.api.proto.java.TransferList) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) FEE_SCHEDULE_FILE_PART_UPLOADED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FEE_SCHEDULE_FILE_PART_UPLOADED) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) ContractFnResultAsserts.isLiteralResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Collectors.toList(java.util.stream.Collectors.toList) UtilVerbs.freezeOnly(com.hedera.services.bdd.spec.utilops.UtilVerbs.freezeOnly) OFF(com.hedera.services.bdd.spec.keys.SigControl.OFF) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) SigControl(com.hedera.services.bdd.spec.keys.SigControl) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Aggregations

KeyShape (com.hedera.services.bdd.spec.keys.KeyShape)30 SigControl (com.hedera.services.bdd.spec.keys.SigControl)11 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)9 KeyShape.listOf (com.hedera.services.bdd.spec.keys.KeyShape.listOf)9 List (java.util.List)9 LogManager (org.apache.logging.log4j.LogManager)9 Logger (org.apache.logging.log4j.Logger)9 SIMPLE (com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE)8 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)8 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)8 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)7 KeyShape.threshOf (com.hedera.services.bdd.spec.keys.KeyShape.threshOf)6 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)6 Map (java.util.Map)6 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)5 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)5 TxnVerbs.fileUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate)5 HapiApiSpec.customHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec)4 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)4 QueryVerbs.getFileInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo)4