Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated scheduled tests #1846

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hedera-mirror-datagenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
ijungmann marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>com.hedera</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class ScheduleCreateTransactionSupplier implements TransactionSupplier<Sc
private String payerAccount;

@Getter(lazy = true)
private final AccountId payerAccountId = AccountId.fromString(payerAccount);
private final AccountId payerAccountId = createPayerAccountId();

@Getter(lazy = true)
private final List<PrivateKey> signingKeys = createSigningKeys();
Expand All @@ -103,9 +103,7 @@ public ScheduleCreateTransaction get() {

// set nodeAccountId and freeze inner transaction
TransactionId transactionId = TransactionId.generate(getOperatorId());
innerTransaction.setNodeAccountIds(Collections.singletonList(getNodeId()));
innerTransaction.setTransactionId(transactionId.setScheduled(true));
innerTransaction.freeze();

String scheduleMemo = Utility.getMemo("Mirror node created test schedule");
ScheduleCreateTransaction scheduleCreateTransaction = innerTransaction
Expand All @@ -125,9 +123,14 @@ public ScheduleCreateTransaction get() {

// add initial set of required signatures to ScheduleCreate transaction
if (totalSignatoryCount > 0) {
getSigningKeys().forEach(k -> scheduleCreateTransaction.addScheduleSignature(
k.getPublicKey(),
k.signTransaction(innerTransaction)));
scheduleCreateTransaction.setNodeAccountIds(Collections.singletonList(getNodeId()));
getSigningKeys().forEach(pk -> {
byte[] signature = pk.signTransaction(scheduleCreateTransaction);
scheduleCreateTransaction.addSignature(
pk.getPublicKey(),
signature);
});
log.debug("Added {} signatures to ScheduleCreate", totalSignatoryCount);
}

return scheduleCreateTransaction;
Expand Down Expand Up @@ -161,4 +164,8 @@ private List<PrivateKey> createSignatoryKeys() {

return keys;
}

private AccountId createPayerAccountId() {
return payerAccount == null ? null : AccountId.fromString(payerAccount);
}
}
2 changes: 1 addition & 1 deletion hedera-mirror-monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.hedera.hashgraph.sdk.AccountId;
import com.hedera.hashgraph.sdk.Client;
import com.hedera.hashgraph.sdk.PrivateKey;
import com.hedera.hashgraph.sdk.Transaction;
import com.hedera.hashgraph.sdk.TransactionId;
import com.hedera.hashgraph.sdk.TransactionResponse;
import com.hedera.mirror.monitor.MonitorProperties;
Expand Down Expand Up @@ -84,11 +85,8 @@ private Mono<PublishResponse> doPublish(PublishRequest request) {
log.trace("Publishing: {}", request);
int clientIndex = counter.getAndUpdate(n -> (n + 1 < clients.get().size()) ? n + 1 : 0);
Client client = clients.get().get(clientIndex);
int nodeIndex = secureRandom.nextInt(nodeAccountIds.get().size());
List<AccountId> nodeAccountId = List.of(nodeAccountIds.get().get(nodeIndex));

return Mono
.fromFuture(() -> request.getTransaction().setNodeAccountIds(nodeAccountId).executeAsync(client))
return getTransactionResponse(request, client)
.flatMap(transactionResponse -> processTransactionResponse(client, request, transactionResponse))
.map(PublishResponse.PublishResponseBuilder::build)
.doOnNext(response -> {
Expand All @@ -99,8 +97,22 @@ private Mono<PublishResponse> doPublish(PublishRequest request) {
.timeout(request.getTimeout());
}

private Mono<TransactionResponse> getTransactionResponse(PublishRequest request, Client client) {
Transaction transaction = request.getTransaction();

// set transaction node where applicable
if (transaction.getNodeAccountIds() == null) {
int nodeIndex = secureRandom.nextInt(nodeAccountIds.get().size());
List<AccountId> nodeAccountId = List.of(nodeAccountIds.get().get(nodeIndex));
transaction.setNodeAccountIds(nodeAccountId);
}

return Mono.fromFuture(transaction.executeAsync(client));
}

private Mono<PublishResponse.PublishResponseBuilder> processTransactionResponse(Client client,
PublishRequest request, TransactionResponse transactionResponse) {
PublishRequest request,
TransactionResponse transactionResponse) {
TransactionId transactionId = transactionResponse.transactionId;
PublishResponse.PublishResponseBuilder builder = PublishResponse.builder()
.request(request)
Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>com.hedera.hashgraph</groupId>
<artifactId>sdk</artifactId>
<version>2.0.5-beta.4</version>
<version>2.0.5-beta.7</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ public TransactionId executeTransaction(Transaction transaction, KeyList keyList
for (Key k : keyList) {
transaction = transaction.sign((PrivateKey) k);
}
log.debug("{} additional signatures added to transaction", keyList.size());
}

TransactionResponse transactionResponse = (TransactionResponse) transaction.execute(client);
TransactionId transactionId = transactionResponse.transactionId;
log.debug("Executed transaction {}.", transactionId);
log.debug("Executed transaction {} with {} signatures.", transactionId, keyList == null ? 0 : keyList.size());

return transactionId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
import lombok.Value;
import lombok.extern.log4j.Log4j2;

import com.hedera.hashgraph.sdk.KeyList;
import com.hedera.hashgraph.sdk.PrecheckStatusException;
import com.hedera.hashgraph.sdk.PrivateKey;
import com.hedera.hashgraph.sdk.ReceiptStatusException;
Expand All @@ -48,16 +48,12 @@ public ScheduleClient(SDKClient sdkClient) {
}

public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountId, Transaction transaction,
String memo, List<PrivateKey> innerSignatureKeyList) throws ReceiptStatusException,
String memo, KeyList signatureKeyList) throws ReceiptStatusException,
PrecheckStatusException, TimeoutException {

log.debug("Create new schedule");
TransactionId transactionId = TransactionId.generate(sdkClient.getOperatorId()).setScheduled(true);

// set nodeAccountId and freeze inner transaction
transaction.setNodeAccountIds(Collections.singletonList(sdkClient.getNodeId()));
transaction.setTransactionId(transactionId);
transaction.freeze();

ScheduleCreateTransaction scheduleCreateTransaction = transaction.schedule()
.setAdminKey(payerAccountId.getPublicKey())
Expand All @@ -67,11 +63,17 @@ public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountI
.setTransactionId(transactionId.setScheduled(false))
.setTransactionMemo(memo);

if (innerSignatureKeyList != null) {
if (signatureKeyList != null) {
scheduleCreateTransaction.setNodeAccountIds(Collections.singletonList(sdkClient.getNodeId()));

// add initial set of required signatures to ScheduleCreate transaction
innerSignatureKeyList.forEach(k -> scheduleCreateTransaction.addScheduleSignature(
k.getPublicKey(),
k.signTransaction(transaction)));
signatureKeyList.forEach(k -> {
PrivateKey pk = (PrivateKey) k;
byte[] signature = pk.signTransaction(scheduleCreateTransaction);
scheduleCreateTransaction.addSignature(
pk.getPublicKey(),
signature);
});
}

NetworkTransactionResponse networkTransactionResponse =
Expand All @@ -83,20 +85,16 @@ public NetworkTransactionResponse createSchedule(ExpandedAccountId payerAccountI
}

public NetworkTransactionResponse signSchedule(ExpandedAccountId expandedAccountId,
Transaction scheduledTransaction,
ScheduleId scheduleId) throws ReceiptStatusException,
PrecheckStatusException, TimeoutException {

log.debug("Sign schedule {}", scheduleId);
byte[] signature = expandedAccountId.getPrivateKey().signTransaction(scheduledTransaction);

ScheduleSignTransaction scheduleSignTransaction = new ScheduleSignTransaction()
.setMaxTransactionFee(sdkClient.getMaxTransactionFee())
.setScheduleId(scheduleId)
.addScheduleSignature(expandedAccountId.getPublicKey(), signature);
.setScheduleId(scheduleId);

NetworkTransactionResponse networkTransactionResponse =
executeTransactionAndRetrieveReceipt(scheduleSignTransaction, null);
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(
scheduleSignTransaction,
KeyList.of(expandedAccountId.getPrivateKey()));
log.debug("Signed schedule {}", scheduleId);

return networkTransactionResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import lombok.Value;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ArrayUtils;

Expand All @@ -49,10 +48,10 @@
import com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse;

@Log4j2
@Value
public class TopicClient extends AbstractNetworkClient {
private static final Duration autoRenewPeriod = Duration.ofSeconds(8000000);
private final Map<Long, Instant> recordPublishInstants;
private TopicId defaultTopicId = null;

public TopicClient(SDKClient sdkClient) {
super(sdkClient);
Expand Down Expand Up @@ -151,6 +150,22 @@ public TopicMessageSubmitTransaction getTopicMessageSubmitTransaction(TopicId to
.setMessage(message);
}

public TopicId getDefaultTopicId() throws PrecheckStatusException, ReceiptStatusException, TimeoutException {
if (defaultTopicId == null) {
NetworkTransactionResponse networkTransactionResponse = createTopic(sdkClient
.getExpandedOperatorAccountId(), null);
defaultTopicId = networkTransactionResponse.getReceipt().topicId;
log.debug("Created TopicId: '{}' for use in current test session", defaultTopicId);
}

return defaultTopicId;
}

public void publishMessageToDefaultTopic() throws ReceiptStatusException, PrecheckStatusException,
TimeoutException {
publishMessagesToTopic(getDefaultTopicId(), "Background message", null, 1, false);
}

public TransactionId publishMessageToTopic(TopicId topicId, byte[] message, KeyList submitKeys) throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
TopicMessageSubmitTransaction consensusMessageSubmitTransaction = new TopicMessageSubmitTransaction()
.setTopicId(topicId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public void createNewAccount(long initialBalance) throws ReceiptStatusException,
assertNotNull(accountId);
}

@When("I send {long} tℏ to newly created account")
public void sendTinyHbars(long amount) throws TimeoutException, PrecheckStatusException,
ReceiptStatusException {
startingBalance = accountClient.getBalance(accountId);
TransactionReceipt receipt = accountClient.sendCryptoTransfer(accountId, Hbar.fromTinybars(amount));
assertNotNull(receipt);
}

@When("I send {long} tℏ to account {int}")
public void sendTinyHbars(long amount, int accountNum) throws TimeoutException, PrecheckStatusException,
ReceiptStatusException {
Expand Down
Loading