Search in sources :

Example 1 with KeyShape

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

the class FileCreateSuite method createFailsWithMissingSigs.

private HapiApiSpec createFailsWithMissingSigs() {
    KeyShape shape = listOf(SIMPLE, threshOf(2, 3), threshOf(1, 3));
    SigControl validSig = shape.signedWith(sigs(ON, sigs(ON, ON, OFF), sigs(OFF, OFF, ON)));
    SigControl invalidSig = shape.signedWith(sigs(OFF, sigs(ON, ON, OFF), sigs(OFF, OFF, ON)));
    return defaultHapiSpec("CreateFailsWithMissingSigs").given().when().then(fileCreate("test").waclShape(shape).sigControl(forKey("test", invalidSig)).hasKnownStatus(INVALID_SIGNATURE), fileCreate("test").waclShape(shape).sigControl(forKey("test", validSig)));
}
Also used : SigControl(com.hedera.services.bdd.spec.keys.SigControl) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 2 with KeyShape

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

the class FileCreateSuite method createFailsWithPayerAccountNotFound.

private HapiApiSpec createFailsWithPayerAccountNotFound() {
    KeyShape shape = listOf(SIMPLE, threshOf(2, 3), threshOf(1, 3));
    SigControl validSig = shape.signedWith(sigs(ON, sigs(ON, ON, OFF), sigs(OFF, OFF, ON)));
    return defaultHapiSpec("CreateFailsWithPayerAccountNotFound").given().when().then(fileCreate("test").withLegacyProtoStructure().waclShape(shape).sigControl(forKey("test", validSig)).scrambleTxnBody(FileCreateSuite::replaceTxnNodeAccount).hasPrecheckFrom(INVALID_NODE_ACCOUNT));
}
Also used : SigControl(com.hedera.services.bdd.spec.keys.SigControl) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 3 with KeyShape

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

the class FileDeleteSuite method canDeleteWithAnyOneOfTopLevelKeyList.

private HapiApiSpec canDeleteWithAnyOneOfTopLevelKeyList() {
    KeyShape shape = listOf(SIMPLE, threshOf(1, 2), listOf(2));
    SigControl deleteSigs = shape.signedWith(sigs(ON, sigs(OFF, OFF), sigs(ON, OFF)));
    return defaultFailingHapiSpec("CanDeleteWithAnyOneOfTopLevelKeyList").given(fileCreate("test").waclShape(shape)).when().then(fileDelete("test").sigControl(forKey("test", deleteSigs)));
}
Also used : SigControl(com.hedera.services.bdd.spec.keys.SigControl) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape)

Example 4 with KeyShape

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

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

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