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