use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class DynamicGasCostSuite method inlineCreateCanFailSafely.
private HapiApiSpec inlineCreateCanFailSafely() {
final var tcValue = 1_234L;
final var creation = "creation";
final var initcode = "initcode";
final var inlineCreateFactory = "inlineCreateFactory";
final int foo = 22;
final int timesToFail = 7;
final AtomicLong factoryEntityNum = new AtomicLong();
final AtomicReference<String> factoryEvmAddress = new AtomicReference<>();
final AtomicReference<byte[]> testContractInitcode = new AtomicReference<>();
return defaultHapiSpec("InlineCreateCanFailSafely").given(overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(REVERTING_CREATE_FACTORY_PATH), contractCreate(inlineCreateFactory).payingWith(GENESIS).bytecode(initcode).via(creation).exposingNumTo(num -> {
factoryEntityNum.set(num);
factoryEvmAddress.set(asHexedSolidityAddress(0, 0, num));
})).when(sourcing(() -> contractCallLocal(inlineCreateFactory, CREATE_FACTORY_GET_BYTECODE_ABI, factoryEvmAddress.get(), foo).exposingTypedResultsTo(results -> {
final var tcInitcode = (byte[]) results[0];
testContractInitcode.set(tcInitcode);
log.info("Contract reported TestContract initcode is {} bytes", tcInitcode.length);
}).payingWith(GENESIS).nodePayment(ONE_HBAR))).then(inParallel(IntStream.range(0, timesToFail).mapToObj(i -> sourcing(() -> contractCall(inlineCreateFactory, NORMAL_DEPLOY_ABI, testContractInitcode.get()).payingWith(GENESIS).gas(4_000_000L).sending(tcValue).via(creation))).toArray(HapiSpecOperation[]::new)), sourcing(() -> cryptoCreate("nextUp").exposingCreatedIdTo(id -> log.info("Next entity num was {} instead of expected {}", id.getAccountNum(), factoryEntityNum.get() + 1))));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class DynamicGasCostSuite method inlineCreate2CanFailSafely.
// https://github.com/hashgraph/hedera-services/issues/2868
private HapiApiSpec inlineCreate2CanFailSafely() {
final var tcValue = 1_234L;
final var creation = "creation";
final var initcode = "initcode";
final var inlineCreate2Factory = "inlineCreate2Factory";
final int foo = 22;
final int salt = 23;
final int timesToFail = 7;
final AtomicLong factoryEntityNum = new AtomicLong();
final AtomicReference<String> factoryEvmAddress = new AtomicReference<>();
final AtomicReference<byte[]> testContractInitcode = new AtomicReference<>();
return defaultHapiSpec("InlineCreate2CanFailSafely").given(overriding("contracts.throttle.throttleByGas", "false"), fileCreate(initcode).path(REVERTING_CREATE2_FACTORY_PATH), contractCreate(inlineCreate2Factory).payingWith(GENESIS).bytecode(initcode).via(creation).exposingNumTo(num -> {
factoryEntityNum.set(num);
factoryEvmAddress.set(asHexedSolidityAddress(0, 0, num));
})).when(sourcing(() -> contractCallLocal(inlineCreate2Factory, CREATE2_FACTORY_GET_BYTECODE_ABI, factoryEvmAddress.get(), foo).exposingTypedResultsTo(results -> {
final var tcInitcode = (byte[]) results[0];
testContractInitcode.set(tcInitcode);
log.info("Contract reported TestContract initcode is {} bytes", tcInitcode.length);
}).payingWith(GENESIS).nodePayment(ONE_HBAR))).then(inParallel(IntStream.range(0, timesToFail).mapToObj(i -> sourcing(() -> contractCall(inlineCreate2Factory, CREATE2_FACTORY_DEPLOY_ABI, testContractInitcode.get(), salt).payingWith(GENESIS).gas(4_000_000L).sending(tcValue).via(creation))).toArray(HapiSpecOperation[]::new)), sourcing(() -> cryptoCreate("nextUp").exposingCreatedIdTo(id -> log.info("Next entity num was {} instead of expected {}", id.getAccountNum(), factoryEntityNum.get() + 1))));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method callForMintWithDelegateContractKey.
private HapiApiSpec callForMintWithDelegateContractKey() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var amount = 10L;
final var fungibleToken = "fungibleToken";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("callForMintWithDelegateContractKey").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, newKeyNamed("delegateContractKey").shape(DELEGATE_CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("delegateContractKey"), contractCall(theContract, MINT_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), amount, new byte[] {}).via(firstMintTxn).payingWith(theAccount))), childRecordsCheck(firstMintTxn, SUCCESS, recordWith().status(SUCCESS).tokenTransfers(changingFungibleBalances().including(fungibleToken, TOKEN_TREASURY, 10)).newTotalSupply(10)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method burnTokenWithFullPrefixAndPartialPrefixKeys.
private HapiApiSpec burnTokenWithFullPrefixAndPartialPrefixKeys() {
final var theAccount = "anybody";
final var burnContractByteCode = "burnContractByteCode";
final var amount = 99L;
final var fungibleToken = "fungibleToken";
final var theContract = "mintContract";
final var firstBurnTxn = "firstBurnTxn";
final var secondBurnTxn = "secondBurnTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("burnTokenWithFullPrefixAndPartialPrefixKeys").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(burnContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, burnContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(100).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(burnContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, contractCall(theContract, BURN_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), 1, new ArrayList<Long>()).via(firstBurnTxn).payingWith(theAccount).signedBy(MULTI_KEY).signedBy(theAccount).hasKnownStatus(SUCCESS), contractCall(theContract, BURN_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), 1, new ArrayList<Long>()).via(secondBurnTxn).payingWith(theAccount).alsoSigningWithFullPrefix(MULTI_KEY).hasKnownStatus(SUCCESS))), childRecordsCheck(firstBurnTxn, SUCCESS, recordWith().status(INVALID_SIGNATURE)), childRecordsCheck(secondBurnTxn, SUCCESS, recordWith().status(SUCCESS).newTotalSupply(99)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractMintHTSSuite method happyPathNonFungibleTokenMint.
private HapiApiSpec happyPathNonFungibleTokenMint() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var nonFungibleToken = "nonFungibleToken";
final var multiKey = "purpose";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final var totalSupply = 2;
final AtomicLong nonFungibleNum = new AtomicLong();
return defaultHapiSpec("NonFungibleMint").given(newKeyNamed(multiKey), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.MINT_CONTRACT)), tokenCreate(nonFungibleToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).supplyType(TokenSupplyType.INFINITE).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> nonFungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract, MINT_CONS_ABI, nonFungibleNum.get()).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(contractCall(theContract, MINT_NON_FUNGIBLE_WITH_EVENT_CALL_ABI, Arrays.asList("Test metadata 1", "Test metadata 2")).via(firstMintTxn).payingWith(theAccount).gas(GAS_TO_OFFER).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTxnRecord(firstMintTxn).hasPriority(recordWith().contractCallResult(resultWith().logs(inOrder(logWith().noData().withTopicsInOrder(List.of(parsedToByteString(totalSupply), parsedToByteString(1))))))), getTokenInfo(nonFungibleToken).hasTotalSupply(totalSupply), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(nonFungibleToken, totalSupply));
}
Aggregations