use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-mirror-node by hashgraph.
the class TransferTransactionPayerMigrationTest method verifyEntityTimestampMigration.
@Test
void verifyEntityTimestampMigration() throws Exception {
Entity node = domainBuilder.entity().customize(e -> e.createdTimestamp(10L).timestampRange(Range.atLeast(10L))).get();
Entity treasury = domainBuilder.entity().customize(e -> e.createdTimestamp(20L).timestampRange(Range.atLeast(20L))).get();
Entity sender = domainBuilder.entity().customize(e -> e.createdTimestamp(30L).timestampRange(Range.atLeast(30L))).get();
Entity receiver = domainBuilder.entity().customize(e -> e.createdTimestamp(40L).timestampRange(Range.atLeast(40L))).get();
Entity contract = domainBuilder.entity().customize(e -> e.createdTimestamp(50L).timestampRange(Range.atLeast(50L)).type(EntityType.CONTRACT)).get();
Entity file = domainBuilder.entity().customize(e -> e.createdTimestamp(60L).timestampRange(Range.atLeast(60L)).type(EntityType.FILE)).get();
Entity topic = domainBuilder.entity().customize(e -> e.createdTimestamp(70L).timestampRange(Range.atLeast(70L)).type(EntityType.TOPIC)).get();
Entity token = domainBuilder.entity().customize(e -> e.createdTimestamp(80L).timestampRange(Range.atLeast(80L)).type(TOKEN)).get();
Entity schedule = domainBuilder.entity().customize(e -> e.createdTimestamp(90L).timestampRange(Range.atLeast(90L)).type(EntityType.SCHEDULE)).get();
// given
persistEntities(List.of(node, treasury, sender, receiver, contract, file, topic, token, schedule));
MigrationTransaction transfer1 = transaction(schedule.getCreatedTimestamp() + 200L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
MigrationTransaction transfer2 = transaction(schedule.getCreatedTimestamp() + 300L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
MigrationTransaction transfer3 = transaction(schedule.getCreatedTimestamp() + 400L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
MigrationTransaction transfer4 = transaction(schedule.getCreatedTimestamp() + 500L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
MigrationTransaction transfer5 = transaction(schedule.getCreatedTimestamp() + 600L, 0, SUCCESS, TransactionType.CRYPTOTRANSFER);
persistTransactions(List.of(transaction(contract.getCreatedTimestamp(), contract.getId(), SUCCESS, TransactionType.CONTRACTCREATEINSTANCE), transaction(contract.getCreatedTimestamp() + 1, contract.getId(), INSUFFICIENT_TX_FEE, TransactionType.CONTRACTUPDATEINSTANCE), transaction(file.getCreatedTimestamp(), file.getId(), SUCCESS, TransactionType.FILECREATE), transaction(file.getCreatedTimestamp() + 1, file.getId(), SUCCESS, TransactionType.FILEDELETE), transaction(topic.getCreatedTimestamp(), topic.getId(), SUCCESS, TransactionType.CONSENSUSCREATETOPIC), transaction(topic.getCreatedTimestamp() + 1, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 2, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(topic.getCreatedTimestamp() + 3, topic.getId(), SUCCESS, TransactionType.CONSENSUSUPDATETOPIC), transaction(token.getCreatedTimestamp(), token.getId(), SUCCESS, TransactionType.TOKENCREATION), transaction(schedule.getCreatedTimestamp(), schedule.getId(), SUCCESS, TransactionType.SCHEDULECREATE), transfer1, transfer2, transfer3, transfer4, transfer5));
EntityId nodeId = node.toEntityId();
EntityId treasuryId = treasury.toEntityId();
EntityId senderId = sender.toEntityId();
EntityId receiverId = receiver.toEntityId();
EntityId tokenId = token.toEntityId();
long senderPaymentAmount = -45L;
long receivedAmount = 30L;
long nodePaymentAmount = 10L;
long treasuryPaymentAmount = 5L;
AssessedCustomFee assessedCustomFee1 = new AssessedCustomFee();
assessedCustomFee1.setAmount(receivedAmount);
assessedCustomFee1.setEffectivePayerAccountIds(List.of(senderId.getId()));
assessedCustomFee1.setId(new AssessedCustomFee.Id(receiverId, transfer1.getConsensusTimestamp()));
assessedCustomFee1.setPayerAccountId(tokenId);
assessedCustomFee1.setTokenId(tokenId);
AssessedCustomFee assessedCustomFee2 = new AssessedCustomFee();
assessedCustomFee2.setAmount(receivedAmount);
assessedCustomFee2.setEffectivePayerAccountIds(List.of(senderId.getId()));
assessedCustomFee2.setId(new AssessedCustomFee.Id(receiverId, transfer5.getConsensusTimestamp()));
assessedCustomFee2.setPayerAccountId(tokenId);
assessedCustomFee2.setTokenId(tokenId);
persistAssessedCustomFees(List.of(// assessed custom fee transfer
assessedCustomFee1, // all transfers
assessedCustomFee2));
persistCryptoTransfers(List.of(// assessed custom fee transfer
new CryptoTransfer(transfer1.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer1.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer1.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer1.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // crypto only transfer
new CryptoTransfer(transfer2.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer2.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer2.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer2.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // nft transfer
new CryptoTransfer(transfer3.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer3.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer3.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer3.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // token transfer
new CryptoTransfer(transfer4.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer4.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer4.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer4.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId), // all transfers
new CryptoTransfer(transfer5.getConsensusTimestamp(), senderPaymentAmount, senderId), new CryptoTransfer(transfer5.getConsensusTimestamp(), receivedAmount, receiverId), new CryptoTransfer(transfer5.getConsensusTimestamp(), nodePaymentAmount, nodeId), new CryptoTransfer(transfer5.getConsensusTimestamp(), treasuryPaymentAmount, treasuryId)));
persistNonFeeTransfers(List.of(// assessed custom fee only transfer
domainBuilder.nonFeeTransfer().customize(n -> n.consensusTimestamp(transfer1.getConsensusTimestamp()).amount(senderPaymentAmount).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer1.getConsensusTimestamp()).entityId(receiverId)).get(), // crypto only transfer
domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer2.getConsensusTimestamp()).entityId(receiverId)).get(), // nft transfer
domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer3.getConsensusTimestamp()).entityId(receiverId)).get(), // token transfer
domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer4.getConsensusTimestamp()).entityId(receiverId)).get(), // all transfers
domainBuilder.nonFeeTransfer().customize(n -> n.amount(senderPaymentAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(senderId)).get(), domainBuilder.nonFeeTransfer().customize(n -> n.amount(receivedAmount).consensusTimestamp(transfer5.getConsensusTimestamp()).entityId(receiverId)).get()));
persistNftTransfers(List.of(// nft transfer
domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer3.getConsensusTimestamp(), 1L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get(), // all transfers
domainBuilder.nftTransfer().customize(n -> n.id(new NftTransferId(transfer5.getConsensusTimestamp(), 2L, tokenId)).payerAccountId(null).receiverAccountId(receiverId).senderAccountId(senderId)).get()));
persistTokenTransfers(List.of(// token transfer
new TokenTransfer(transfer4.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer4.getConsensusTimestamp(), receivedAmount, tokenId, receiverId), // all transfers
new TokenTransfer(transfer5.getConsensusTimestamp(), -receivedAmount, tokenId, senderId), new TokenTransfer(transfer5.getConsensusTimestamp(), receivedAmount, tokenId, receiverId)));
// when
migrate();
List<SharedTransfer> expectedAssessedCustomFeeTransfers = List.of(// assessed custom fee transfer
new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
List<SharedTransfer> expectedCryptoTransfers = List.of(// assessed custom fee transfer
new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // crypto only transfer
new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // nft transfer
new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // token transfer
new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, treasuryId, null), // all transfers
new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null), new SharedTransfer(nodePaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, nodeId, null), new SharedTransfer(treasuryPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, treasuryId, null));
List<SharedTransfer> expectedNftTransfers = List.of(// nft transfer
new SharedTransfer(1L, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, senderId), new SharedTransfer(2L, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, senderId));
List<SharedTransfer> expectedNonFeeTransfers = List.of(// assessed custom fee only transfer
new SharedTransfer(senderPaymentAmount, transfer1.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer1.getConsensusTimestamp(), PAYER_ID, receiverId, null), // crypto only transfer
new SharedTransfer(senderPaymentAmount, transfer2.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer2.getConsensusTimestamp(), PAYER_ID, receiverId, null), // nft transfer
new SharedTransfer(senderPaymentAmount, transfer3.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer3.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
new SharedTransfer(senderPaymentAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // token transfer
new SharedTransfer(senderPaymentAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
List<SharedTransfer> expectedTokenTransfers = List.of(// token transfer
new SharedTransfer(-receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer4.getConsensusTimestamp(), PAYER_ID, receiverId, null), // all transfer
new SharedTransfer(-receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, null, senderId), new SharedTransfer(receivedAmount, transfer5.getConsensusTimestamp(), PAYER_ID, receiverId, null));
// then
assertThat(findAssessedCustomFees()).containsExactlyInAnyOrderElementsOf(expectedAssessedCustomFeeTransfers);
assertThat(findCryptoTransfers()).containsExactlyInAnyOrderElementsOf(expectedCryptoTransfers);
assertThat(findNftTransfers()).containsExactlyInAnyOrderElementsOf(expectedNftTransfers);
assertThat(findNonFeeTransfersAsSharedTransfers()).containsExactlyInAnyOrderElementsOf(expectedNonFeeTransfers);
assertThat(findTokenTransfers()).containsExactlyInAnyOrderElementsOf(expectedTokenTransfers);
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.
the class FileCreateTransitionLogicTest method happyPathFlows.
@Test
void happyPathFlows() {
// setup:
InOrder inOrder = inOrder(hfs, txnCtx, sigImpactHistorian);
givenTxnCtxCreating(EnumSet.allOf(ValidProperty.class));
// and:
given(hfs.create(any(), any(), any())).willReturn(created);
// when:
subject.doStateTransition();
// then:
inOrder.verify(txnCtx).activePayer();
inOrder.verify(hfs).create(argThat(bytes -> Arrays.equals(contents, bytes)), argThat(info -> info.getWacl().toString().equals(hederaWacl.toString()) && info.getExpiry() == expiry && memo.equals(info.getMemo())), argThat(genesis::equals));
inOrder.verify(txnCtx).setCreated(created);
inOrder.verify(txnCtx).setStatus(SUCCESS);
inOrder.verify(sigImpactHistorian).markEntityChanged(created.getFileNum());
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.
the class FileUpdateTransitionLogicTest method happyPathFlows.
@Test
void happyPathFlows() {
// setup:
InOrder inOrder = inOrder(hfs, txnCtx, sigImpactHistorian);
givenTxnCtxUpdating(EnumSet.allOf(UpdateTarget.class));
// and:
given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, true, SUCCESS));
given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
given(hfs.getattr(nonSysFileTarget)).willReturn(oldAttr);
// when:
subject.doStateTransition();
// then:
inOrder.verify(hfs).overwrite(argThat(nonSysFileTarget::equals), argThat(bytes -> Arrays.equals(newContents, bytes)));
inOrder.verify(hfs).setattr(argThat(nonSysFileTarget::equals), argThat(attr -> newAttr.toString().equals(attr.toString())));
inOrder.verify(txnCtx).setStatus(SUCCESS);
inOrder.verify(sigImpactHistorian).markEntityChanged(nonSysFileTarget.getFileNum());
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS 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.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS 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