use of com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.WORKING_HOURS_USER_BYTECODE_PATH 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());
}
Aggregations