use of com.hedera.services.bdd.spec.HapiApiSpec 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());
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractCreateSuite method childCreationsHaveExpectedKeysWithOmittedAdminKey.
private HapiApiSpec childCreationsHaveExpectedKeysWithOmittedAdminKey() {
final AtomicLong firstStickId = new AtomicLong();
final AtomicLong secondStickId = new AtomicLong();
final AtomicLong thirdStickId = new AtomicLong();
final String txn = "creation";
return defaultHapiSpec("ChildCreationsHaveExpectedKeysWithOmittedAdminKey").given(fileCreate("bytecode").path(ContractResources.FUSE_BYTECODE_PATH), contractCreate("fuse").bytecode("bytecode").omitAdminKey().gas(300_000).via(txn), withOpContext((spec, opLog) -> {
final var op = getTxnRecord(txn);
allRunFor(spec, op);
final var record = op.getResponseRecord();
final var creationResult = record.getContractCreateResult();
final var createdIds = creationResult.getCreatedContractIDsList();
assertEquals(4, createdIds.size(), "Expected four creations but got " + createdIds);
firstStickId.set(createdIds.get(1).getContractNum());
secondStickId.set(createdIds.get(2).getContractNum());
thirdStickId.set(createdIds.get(3).getContractNum());
})).when(sourcing(() -> getContractInfo("0.0." + firstStickId.get()).has(contractWith().immutableContractKey("0.0." + firstStickId.get())).logged()), sourcing(() -> getContractInfo("0.0." + secondStickId.get()).has(contractWith().immutableContractKey("0.0." + secondStickId.get())).logged()), sourcing(() -> getContractInfo("0.0." + thirdStickId.get()).logged()), contractCall("fuse", ContractResources.LIGHT_ABI).via("lightTxn")).then(sourcing(() -> getContractInfo("0.0." + firstStickId.get()).has(contractWith().isDeleted())), sourcing(() -> getContractInfo("0.0." + secondStickId.get()).has(contractWith().isDeleted())), sourcing(() -> getContractInfo("0.0." + thirdStickId.get()).has(contractWith().isDeleted())));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method callForMintWithContractKey.
private HapiApiSpec callForMintWithContractKey() {
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("callForMintWithContractKey").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("contractKey").shape(CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("contractKey"), 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 PermissionSemanticsSpec method supportsImmutableFiles.
private HapiApiSpec supportsImmutableFiles() {
long extensionSecs = 666L;
AtomicLong approxExpiry = new AtomicLong();
return defaultHapiSpec("SupportsImmutableFiles").given(newKeyNamed("neverToBeUsed").type(KeyFactory.KeyType.LIST), cryptoCreate("civilian"), fileCreate("eternal").payingWith("civilian").unmodifiable()).when(fileDelete("eternal").payingWith("civilian").signedBy("civilian").hasKnownStatus(UNAUTHORIZED), fileAppend("eternal").payingWith("civilian").signedBy("civilian").content("Ignored.").hasKnownStatus(UNAUTHORIZED), fileUpdate("eternal").payingWith("civilian").signedBy("civilian").contents("Ignored.").hasKnownStatus(UNAUTHORIZED), fileUpdate("eternal").payingWith("civilian").signedBy("civilian", "neverToBeUsed").wacl("neverToBeUsed").hasKnownStatus(UNAUTHORIZED)).then(withOpContext((spec, opLog) -> {
approxExpiry.set(spec.registry().getTimestamp("eternal").getSeconds());
}), fileUpdate("eternal").payingWith("civilian").signedBy("civilian").extendingExpiryBy(extensionSecs), getFileInfo("eternal").isUnmodifiable().hasExpiryPassing(l -> Math.abs(l - approxExpiry.get() - extensionSecs) < 5));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ContractMintHTSSuite method helloWorldFungibleMint.
private HapiApiSpec helloWorldFungibleMint() {
final var hwMintInitcode = "hwMintInitcode";
final var amount = 1_234_567L;
final var fungibleToken = "fungibleToken";
final var multiKey = "purpose";
final var contractKey = "meaning";
final var hwMint = "hwMint";
final var firstMintTxn = "firstMintTxn";
final var secondMintTxn = "secondMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("HelloWorldFungibleMint").given(newKeyNamed(multiKey), fileCreate(hwMintInitcode).path(ContractResources.HW_MINT_PATH), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(0).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(hwMint, HW_MINT_CONS_ABI, fungibleNum.get()).bytecode(hwMintInitcode).gas(GAS_TO_OFFER))).then(contractCall(hwMint, HW_BRRR_CALL_ABI, amount).via(firstMintTxn).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTokenInfo(fungibleToken).hasTotalSupply(amount), /* And now make the token contract-controlled so no explicit supply sig is required */
newKeyNamed(contractKey).shape(DELEGATE_CONTRACT.signedWith(hwMint)), tokenUpdate(fungibleToken).supplyKey(contractKey), getTokenInfo(fungibleToken).logged(), contractCall(hwMint, HW_BRRR_CALL_ABI, amount).via(secondMintTxn), getTxnRecord(secondMintTxn).andAllChildRecords().logged(), getTokenInfo(fungibleToken).hasTotalSupply(2 * amount), childRecordsCheck(secondMintTxn, SUCCESS, recordWith().status(SUCCESS).newTotalSupply(2469134L).tokenTransfers(changingFungibleBalances().including(fungibleToken, DEFAULT_PAYER, amount))));
}
Aggregations