use of com.hederahashgraph.api.proto.java.TokenType 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.hederahashgraph.api.proto.java.TokenType 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.hederahashgraph.api.proto.java.TokenType 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));
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class ContractMintHTSSuite method helloWorldNftMint.
private HapiApiSpec helloWorldNftMint() {
final var hwMintInitCode = "hwMintInitCode";
final var nonFungibleToken = "nonFungibleToken";
final var multiKey = "purpose";
final var contractKey = "meaning";
final var hwMint = "hwMint";
final var firstMintTxn = "firstMintTxn";
final var secondMintTxn = "secondMintTxn";
final AtomicLong nonFungibleNum = new AtomicLong();
return defaultHapiSpec("HelloWorldNftMint").given(newKeyNamed(multiKey), fileCreate(hwMintInitCode).path(ContractResources.HW_MINT_PATH), tokenCreate(nonFungibleToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).initialSupply(0).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> nonFungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(hwMint, HW_MINT_CONS_ABI, nonFungibleNum.get()).bytecode(hwMintInitCode).gas(GAS_TO_OFFER))).then(contractCall(hwMint, HW_MINT_CALL_ABI).via(firstMintTxn).gas(GAS_TO_OFFER).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTokenInfo(nonFungibleToken).hasTotalSupply(1), /* And now make the token contract-controlled so no explicit supply sig is required */
newKeyNamed(contractKey).shape(DELEGATE_CONTRACT.signedWith(hwMint)), tokenUpdate(nonFungibleToken).supplyKey(contractKey), getTokenInfo(nonFungibleToken).logged(), contractCall(hwMint, HW_MINT_CALL_ABI).via(secondMintTxn).gas(GAS_TO_OFFER), getTxnRecord(secondMintTxn).andAllChildRecords().logged(), getTokenInfo(nonFungibleToken).hasTotalSupply(2), getTokenNftInfo(nonFungibleToken, 2L).logged());
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class ContractMintHTSSuite method happyPathFungibleTokenMint.
private HapiApiSpec happyPathFungibleTokenMint() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var amount = 10L;
final var fungibleToken = "fungibleToken";
final var multiKey = "purpose";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("FungibleMint").given(newKeyNamed(multiKey), cryptoCreate(theAccount).balance(ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.MINT_CONTRACT)), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract, MINT_CONS_ABI, fungibleNum.get()).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(contractCall(theContract, MINT_FUNGIBLE_WITH_EVENT_CALL_ABI, amount).via(firstMintTxn).payingWith(theAccount).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTxnRecord(firstMintTxn).hasPriority(recordWith().contractCallResult(resultWith().logs(inOrder(logWith().noData().withTopicsInOrder(List.of(parsedToByteString(amount), parsedToByteString(0))))))), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
Aggregations