-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...undation/rosetta/api/search/mapper/BlockTransactionsToSearchTransactionsResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.cardanofoundation.rosetta.api.search.mapper; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import org.cardanofoundation.rosetta.api.BaseMapperSetup; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.client.model.BlockIdentifier; | ||
import org.openapitools.client.model.BlockTransaction; | ||
import org.openapitools.client.model.SearchTransactionsResponse; | ||
import org.openapitools.client.model.Transaction; | ||
import org.openapitools.client.model.TransactionMetadata; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class BlockTransactionsToSearchTransactionsResponseTest extends BaseMapperSetup { | ||
|
||
@Autowired | ||
private SearchMapper my; | ||
|
||
@Test | ||
void mapToSearchResponse_test_Ok() { | ||
List<BlockTransaction> blockTransactions = List.of(BlockTransaction.builder() | ||
.blockIdentifier(BlockIdentifier.builder() | ||
.hash("hash") | ||
.index(1L) | ||
.build()) | ||
.transaction(Transaction.builder() | ||
.metadata(TransactionMetadata.builder() | ||
.size(10L) | ||
.scriptSize(11L) | ||
.build()) | ||
.build()) | ||
.build()); | ||
|
||
SearchTransactionsResponse searchTransactionsResponse = my.mapToSearchTransactionsResponse( | ||
blockTransactions, 2L); | ||
|
||
assertThat(searchTransactionsResponse.getTransactions().size() == 1); | ||
assertThat(searchTransactionsResponse.getNextOffset() == 2L); | ||
assertThat(searchTransactionsResponse.getTotalCount() == 1); | ||
assertThat(searchTransactionsResponse.getTransactions().get(0).getBlockIdentifier().getHash().equals("hash")); | ||
assertThat(searchTransactionsResponse.getTransactions().get(0).getBlockIdentifier().getIndex().equals(1L)); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...c/test/java/org/cardanofoundation/rosetta/api/search/service/SearchControllerIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.cardanofoundation.rosetta.api.search.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import org.cardanofoundation.rosetta.api.IntegrationTest; | ||
import org.cardanofoundation.rosetta.testgenerator.common.TestConstants; | ||
import org.cardanofoundation.rosetta.testgenerator.common.TransactionBlockDetails; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.client.model.BlockTransaction; | ||
import org.openapitools.client.model.CoinIdentifier; | ||
import org.openapitools.client.model.SearchTransactionsRequest; | ||
import org.openapitools.client.model.TransactionIdentifier; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class SearchControllerIntTest extends IntegrationTest { | ||
|
||
@Autowired | ||
private SearchService service; | ||
|
||
@Test | ||
void searchAddressTransactions() { | ||
SearchTransactionsRequest req = SearchTransactionsRequest.builder() | ||
.address(TestConstants.TEST_ACCOUNT_ADDRESS) | ||
.build(); | ||
|
||
List<BlockTransaction> blockTransactions = service.searchTransaction(req, 0L, 5L); | ||
assertThat(blockTransactions.size() == 5); | ||
} | ||
|
||
@Test | ||
void searchByTxHash() { | ||
TransactionBlockDetails stakeKeyDeregistration = generatedDataMap.get( | ||
"stake_key_deregistration"); | ||
SearchTransactionsRequest req = SearchTransactionsRequest.builder() | ||
.transactionIdentifier(TransactionIdentifier.builder() | ||
.hash(stakeKeyDeregistration.txHash()) | ||
.build()) | ||
.build(); | ||
List<BlockTransaction> blockTransactions = service.searchTransaction(req, 0L, 10L); | ||
assertThat(blockTransactions.size() == 1); | ||
BlockTransaction tx = blockTransactions.getFirst(); | ||
assertThat(tx.getBlockIdentifier().getHash().equals(stakeKeyDeregistration.blockHash())); | ||
assertThat(tx.getBlockIdentifier().getIndex() == stakeKeyDeregistration.blockNumber()); | ||
assertThat(tx.getTransaction().getTransactionIdentifier().getHash().equals(stakeKeyDeregistration.txHash())); | ||
assertThat(tx.getTransaction().getOperations().size() == 4); | ||
} | ||
|
||
@Test | ||
void searchByUtxo() { | ||
TransactionBlockDetails txDetails = generatedDataMap.get( | ||
"simple_transaction"); | ||
SearchTransactionsRequest req = SearchTransactionsRequest.builder() | ||
.transactionIdentifier(TransactionIdentifier.builder() | ||
.hash(txDetails.txHash()) | ||
.build()) | ||
.build(); | ||
|
||
List<BlockTransaction> blockTransactions = service.searchTransaction(req, 0L, 10L); | ||
assertThat(blockTransactions.size() == 1); | ||
String identifier = blockTransactions.getFirst().getTransaction().getOperations().getFirst() | ||
.getCoinChange().getCoinIdentifier().getIdentifier(); | ||
req = SearchTransactionsRequest.builder() | ||
.coinIdentifier(CoinIdentifier.builder() | ||
.identifier(identifier) | ||
.build()) | ||
.build(); | ||
|
||
blockTransactions = service.searchTransaction(req, 0L, 10L); | ||
assertThat(blockTransactions.size() == 2); | ||
} | ||
|
||
} |