Skip to content

Commit

Permalink
chore: adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kammerlo committed Aug 14, 2024
1 parent f9850d1 commit f61c235
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void before() {
@ComponentScan(basePackages = {
"org.cardanofoundation.rosetta.api.block.mapper",
"org.cardanofoundation.rosetta.api.account.mapper",
"org.cardanofoundation.rosetta.api.search.mapper",
"org.cardanofoundation.rosetta.common.mapper"})
public static class BaseMappersConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void getBlockTransaction_Test() {
assertEquals(blockTxHash, tx.getHash());
assertEquals(blockNo, tx.getBlockNo());
assertEquals(fee, tx.getFee());
assertEquals(385, tx.getSize());
assertEquals(284, tx.getSize());
assertEquals(0, tx.getScriptSize());
assertEquals(1, tx.getInputs().size());
assertEquals(2, tx.getOutputs().size());
Expand Down
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));
}

}
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);
}

}

0 comments on commit f61c235

Please sign in to comment.