Search in sources :

Example 1 with WORKING_HOURS_TAKE_TICKET

use of com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_TAKE_TICKET in project hedera-services by hashgraph.

the class ContractCallSuite method workingHoursDemo.

private HapiApiSpec workingHoursDemo() {
    final var initcode = "initcode";
    final var gasToOffer = 4_000_000;
    final var workingHours = "workingHours";
    final var ticketToken = "ticketToken";
    final var adminKey = "admin";
    final var treasury = "treasury";
    final var user = "user";
    final var newSupplyKey = "newSupplyKey";
    final var ticketTaking = "ticketTaking";
    final var ticketWorking = "ticketWorking";
    final var mint = "minting";
    final var burn = "burning";
    final var preMints = List.of(ByteString.copyFromUtf8("HELLO"), ByteString.copyFromUtf8("GOODBYE"));
    final AtomicLong ticketSerialNo = new AtomicLong();
    return defaultHapiSpec("WorkingHoursDemo").given(newKeyNamed(adminKey), cryptoCreate(treasury), // we need a new user, expiry to 1 Jan 2100 costs 11M gas for token associate
    cryptoCreate(user), cryptoTransfer(TokenMovement.movingHbar(ONE_HUNDRED_HBARS).between(GENESIS, user)), tokenCreate(ticketToken).treasury(treasury).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).initialSupply(0L).supplyType(TokenSupplyType.INFINITE).adminKey(adminKey).supplyKey(adminKey), mintToken(ticketToken, preMints).via(mint), burnToken(ticketToken, List.of(1L)).via(burn), fileCreate(initcode), updateLargeFile(GENESIS, initcode, extractByteCode(WORKING_HOURS_USER_BYTECODE_PATH))).when(withOpContext((spec, opLog) -> {
        final var registry = spec.registry();
        final var tokenId = registry.getTokenID(ticketToken);
        final var treasuryId = registry.getAccountID(treasury);
        final var creation = contractCreate(workingHours, WORKING_HOURS_CONS, tokenId.getTokenNum(), treasuryId.getAccountNum()).bytecode(initcode).gas(gasToOffer);
        allRunFor(spec, creation);
    }), newKeyNamed(newSupplyKey).shape(KeyShape.CONTRACT.signedWith(workingHours)), tokenUpdate(ticketToken).supplyKey(newSupplyKey)).then(/* Take a ticket */
    contractCall(workingHours, WORKING_HOURS_TAKE_TICKET).payingWith(user).gas(4_000_000).via(ticketTaking).alsoSigningWithFullPrefix(treasury).exposingResultTo(result -> {
        log.info("Explicit mint result is {}", result);
        ticketSerialNo.set(((BigInteger) result[0]).longValueExact());
    }), getTxnRecord(ticketTaking), getAccountBalance(user).hasTokenBalance(ticketToken, 1L), /* Our ticket number is 3 (b/c of the two pre-mints), so we must call
						 * work twice before the contract will actually accept our ticket. */
    sourcing(() -> contractCall(workingHours, WORKING_HOURS_WORK_TICKET, ticketSerialNo.get()).gas(2_000_000).payingWith(user)), getAccountBalance(user).hasTokenBalance(ticketToken, 1L), sourcing(() -> contractCall(workingHours, WORKING_HOURS_WORK_TICKET, ticketSerialNo.get()).gas(2_000_000).payingWith(user).via(ticketWorking)), getAccountBalance(user).hasTokenBalance(ticketToken, 0L), getTokenInfo(ticketToken).hasTotalSupply(1L), /* Review the history */
    getTxnRecord(ticketTaking).andAllChildRecords().logged(), getTxnRecord(ticketWorking).andAllChildRecords().logged());
}
Also used : IMAP_USER_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_BYTECODE_PATH) UtilVerbs.createLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.createLargeFile) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) QueryVerbs.getContractRecords(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractRecords) CallTransaction(org.ethereum.core.CallTransaction) TxnVerbs.contractDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractDelete) MINT_ADD_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_ADD_ABI) HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) OC_TOKEN_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.OC_TOKEN_BYTECODE_PATH) OBTAINER_SAME_CONTRACT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OBTAINER_SAME_CONTRACT_ID) TOKEN_ERC20_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.TOKEN_ERC20_CONSTRUCTOR_ABI) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) BigInteger(java.math.BigInteger) CONTRACT_DELETED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_DELETED) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) Logger(org.apache.logging.log4j.Logger) UtilVerbs.assertionsHold(com.hedera.services.bdd.spec.utilops.UtilVerbs.assertionsHold) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UtilVerbs.balanceSnapshot(com.hedera.services.bdd.spec.utilops.UtilVerbs.balanceSnapshot) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) Bytes(org.apache.tuweni.bytes.Bytes) WORKING_HOURS_USER_BYTECODE_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_USER_BYTECODE_PATH) BiConsumer(java.util.function.BiConsumer) UtilVerbs.newKeyListNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyListNamed) AccountID(com.hederahashgraph.api.proto.java.AccountID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractResources.literalInitcodeFor(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.literalInitcodeFor) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) TxnVerbs.burnToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.burnToken) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) QueryVerbs(com.hedera.services.bdd.spec.queries.QueryVerbs) HapiPropertySource.asSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asSolidityAddress) WORKING_HOURS_WORK_TICKET(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_WORK_TICKET) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) CommonUtils(com.swirlds.common.CommonUtils) DECIMALS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DECIMALS_ABI) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) ContractInfoAsserts.contractWith(com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith) INSUFFICIENT_TX_FEE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TX_FEE) WORKING_HOURS_TAKE_TICKET(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_TAKE_TICKET) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TxnVerbs.contractUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractUpdate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) ContractLogAsserts.logWith(com.hedera.services.bdd.spec.assertions.ContractLogAsserts.logWith) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) AccountInfoAsserts.changeFromSnapshot(com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.changeFromSnapshot) NOT_SUPPORTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.NOT_SUPPORTED) HapiPropertySource.asHexedSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress) JURISDICTION_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.JURISDICTION_ABI) IMAP_USER_REMOVE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_REMOVE) TRANSFER_FROM_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.TRANSFER_FROM_ABI) WORKING_HOURS_CONS(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_CONS) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) MINT_OWNER_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_OWNER_ABI) SYMBOL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SYMBOL_ABI) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) ByteString(com.google.protobuf.ByteString) List(java.util.List) IMAP_USER_INSERT(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_INSERT) TxnVerbs.tokenUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate) MINT_SEVEN_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_SEVEN_ABI) BALANCE_OF_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BALANCE_OF_ABI) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) TRANSFER_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.TRANSFER_ABI) FeeBuilder(com.hederahashgraph.fee.FeeBuilder) ContractGetInfoResponse(com.hederahashgraph.api.proto.java.ContractGetInfoResponse) 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) TxnVerbs(com.hedera.services.bdd.spec.transactions.TxnVerbs) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) MAX_GAS_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_GAS_LIMIT_EXCEEDED) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) JURISDICTION_ISVALID_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.JURISDICTION_ISVALID_ABI) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) APPROVE_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.APPROVE_ABI) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) ContractFnResultAsserts.isLiteralResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult) Key(com.hederahashgraph.api.proto.java.Key) UtilVerbs(com.hedera.services.bdd.spec.utilops.UtilVerbs) THRESHOLD(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType.THRESHOLD) INVALID_CONTRACT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_CONTRACT_ID) Assertions(org.junit.jupiter.api.Assertions) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) AssertUtils.inOrder(com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder) LogManager(org.apache.logging.log4j.LogManager) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) AtomicLong(java.util.concurrent.atomic.AtomicLong) BigInteger(java.math.BigInteger)

Aggregations

ByteString (com.google.protobuf.ByteString)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 HapiPropertySource.asHexedSolidityAddress (com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress)1 HapiPropertySource.asSolidityAddress (com.hedera.services.bdd.spec.HapiPropertySource.asSolidityAddress)1 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)1 AccountInfoAsserts.changeFromSnapshot (com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.changeFromSnapshot)1 AssertUtils.inOrder (com.hedera.services.bdd.spec.assertions.AssertUtils.inOrder)1 ContractFnResultAsserts.isLiteralResult (com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralResult)1 ContractFnResultAsserts.resultWith (com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith)1 ContractInfoAsserts.contractWith (com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith)1 ContractLogAsserts.logWith (com.hedera.services.bdd.spec.assertions.ContractLogAsserts.logWith)1 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)1 ContractResources (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources)1 APPROVE_ABI (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.APPROVE_ABI)1 BALANCE_OF_ABI (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BALANCE_OF_ABI)1 DECIMALS_ABI (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DECIMALS_ABI)1 IMAP_USER_BYTECODE_PATH (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_BYTECODE_PATH)1 IMAP_USER_INSERT (com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.IMAP_USER_INSERT)1