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)));
}
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));
}
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)));
}
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"));
}
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);
}));
}
Aggregations