Skip to content

Commit

Permalink
Refactor: transaction names to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
BerezinD authored Apr 8, 2024
1 parent 3d913e1 commit 1f9497e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.cardanofoundation.rosetta.api.block.model.domain.Block;
import org.cardanofoundation.rosetta.api.block.model.domain.BlockTx;
import org.cardanofoundation.rosetta.testgenerator.common.TestConstants;
import org.cardanofoundation.rosetta.testgenerator.common.TestTransactionNames;
import org.cardanofoundation.rosetta.testgenerator.common.TransactionBlockDetails;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -18,7 +19,9 @@ class BlockServiceImplIntTest extends IntegrationTest {
@Autowired
@SuppressWarnings("unused")
private BlockService blockService;
final TransactionBlockDetails generatedTestData = generatedDataMap.get(TestConstants.SIMPLE_TRANSACTION_NAME);
final TransactionBlockDetails generatedTestData = generatedDataMap.get(
TestTransactionNames.SIMPLE_TRANSACTION.getName());

@Test
void getBlockWithTransaction_Test() {
//given
Expand Down Expand Up @@ -72,7 +75,8 @@ void getBlockTransaction_Test() {
Utxo outUtxo = tx.getOutputs().getFirst();
assertEquals(TestConstants.TEST_ACCOUNT_ADDRESS, outUtxo.getOwnerAddr());
assertEquals(blockTxHash, outUtxo.getTxHash());
assertEquals(TestConstants.ACCOUNT_BALANCE_LOVELACE_AMOUNT, outUtxo.getLovelaceAmount().toString());
assertEquals(TestConstants.ACCOUNT_BALANCE_LOVELACE_AMOUNT,
outUtxo.getLovelaceAmount().toString());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.cardanofoundation.rosetta.api.IntegrationTest;
import org.cardanofoundation.rosetta.common.util.Constants;
import org.cardanofoundation.rosetta.testgenerator.common.TestConstants;
import org.cardanofoundation.rosetta.testgenerator.common.TestTransactionNames;

import static org.cardanofoundation.rosetta.testgenerator.common.TestConstants.URL;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -27,9 +28,9 @@
class AccountBalanceApiTest extends IntegrationTest {

private final String upToBlockHash = generatedDataMap.get(
TestConstants.SIMPLE_LOVELACE_FIRST_TRANSACTION_NAME).blockHash();
TestTransactionNames.SIMPLE_LOVELACE_FIRST_TRANSACTION.getName()).blockHash();
private final Long upToBlockNumber = generatedDataMap.get(
TestConstants.SIMPLE_LOVELACE_FIRST_TRANSACTION_NAME).blockNumber();
TestTransactionNames.SIMPLE_LOVELACE_FIRST_TRANSACTION.getName()).blockNumber();

private final String currentAdaBalance = "1635030";
private final String currentLovelaceBalance = "1939500";
Expand Down Expand Up @@ -58,9 +59,11 @@ void accountBalance2Lovelace_Test() {
AccountBalanceResponse accountBalanceResponse = response.getBody();

assertEquals(HttpStatusCode.valueOf(200), response.getStatusCode());
assertNotNull(accountBalanceResponse); // TODO check if balances list should be size of 2
assertNotNull(accountBalanceResponse);
assertEquals(1, accountBalanceResponse.getBalances().size());
assertAdaCurrency(accountBalanceResponse);
assertEquals(currentLovelaceBalance, accountBalanceResponse.getBalances().getFirst().getValue());
assertEquals(currentLovelaceBalance,
accountBalanceResponse.getBalances().getFirst().getValue());
}

@Test
Expand Down Expand Up @@ -164,7 +167,7 @@ void accountBalanceUntilBlockException_Test() {

assertEquals(HttpStatusCode.valueOf(500), response.getStatusCode());
assertNotNull(accountBalanceError);
assertEquals("Block not found", accountBalanceError.getMessage()); // TODO check the message
assertEquals("Block not found", accountBalanceError.getMessage());
assertEquals(4001, accountBalanceError.getCode());
}

Expand Down Expand Up @@ -246,9 +249,9 @@ void accountBalanceStakeAddressWithMintedUtxo_Test() {
@Test
void accountBalanceBetweenTwoBlocksWithMintedCoins_Test() {
String upToBlockHashTestAccount = generatedDataMap.get(
TestConstants.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION_NAME).blockHash();
TestTransactionNames.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION.getName()).blockHash();
long upToBlockNumberTestAccount = generatedDataMap.get(
TestConstants.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION_NAME).blockNumber();
TestTransactionNames.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION.getName()).blockNumber();

AccountBalanceRequest accountBalanceRequest = getAccountBalanceRequestUntilBlock(
TestConstants.TEST_ACCOUNT_ADDRESS, upToBlockNumberTestAccount, null);
Expand All @@ -273,7 +276,8 @@ void accountBalanceBetweenTwoBlocksWithMintedCoins_Test() {
assertNotEquals(
accountBalanceResponseWith3Tokens.getBalances().getFirst().getCurrency().getSymbol(),
accountBalanceResponseWith3Tokens.getBalances().get(2).getCurrency().getSymbol());
assertEquals(upToBlockHashTestAccount, accountBalanceResponseWith3Tokens.getBlockIdentifier().getHash());
assertEquals(upToBlockHashTestAccount,
accountBalanceResponseWith3Tokens.getBlockIdentifier().getHash());
assertEquals(upToBlockNumberTestAccount,
accountBalanceResponseWith3Tokens.getBlockIdentifier().getIndex());
// Check the balance on the previous block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ public class TestConstants {
public static final String STAKE_ADDRESS_WITH_EARNED_REWARDS = "stake_test1uqjg6peuwpjaexgdd2vy2h69zn6pjz33pdsvekjcq88uxmgc6qc7u";
public static final String STAKE_ADDRESS_WITH_MINTED_TOKENS = "stake_test1uq54hxr3x4ssv9hnca8prj2dw7mva4wveya86uvulvf4qcsceluue";

// Transaction names for SimpleTransactions
public static final String SIMPLE_TRANSACTION_NAME = "simple_transaction";
public static final String SIMPLE_LOVELACE_FIRST_TRANSACTION_NAME = "simple_first_lovelace_transaction";
public static final String SIMPLE_LOVELACE_SECOND_TRANSACTION_NAME = "simple_second_lovelace_transaction";
public static final String SIMPLE_NEW_COINS_TRANSACTION_NAME = "simple_new_coins_transaction";
public static final String SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION_NAME = "simple_new_empty_name_coins_transaction";
public static final String STAKE_KEY_REGISTRATION_TRANSACTION_NAME = "stake_key_registration";
public static final String STAKE_KEY_DEREGISTRATION_TRANSACTION_NAME = "stake_key_deregistration";

// Transaction names for PoolTransactions
public static final String POOL_REGISTRATION_TRANSACTION_NAME = "pool_registration";
public static final String POOL_DELEGATION_TRANSACTION_NAME = "pool_delegation";
public static final String POOL_RETIREMENT_TRANSACTION_NAME = "pool_retirement";

private TestConstants() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cardanofoundation.rosetta.testgenerator.common;

public enum TestTransactionNames {
// Transaction names for SimpleTransactions
SIMPLE_TRANSACTION("simple_transaction"),
SIMPLE_LOVELACE_FIRST_TRANSACTION("simple_first_lovelace_transaction"),
SIMPLE_LOVELACE_SECOND_TRANSACTION("simple_second_lovelace_transaction"),
SIMPLE_NEW_COINS_TRANSACTION("simple_new_coins_transaction"),
SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION("simple_new_empty_name_coins_transaction"),
STAKE_KEY_REGISTRATION_TRANSACTION("stake_key_registration"),
STAKE_KEY_DEREGISTRATION_TRANSACTION("stake_key_deregistration"),

// Transaction names for PoolTransactions
POOL_REGISTRATION_TRANSACTION("pool_registration"),
POOL_DELEGATION_TRANSACTION("pool_delegation"),
POOL_RETIREMENT_TRANSACTION("pool_retirement");

private final String name;

TestTransactionNames(final String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.cardanofoundation.rosetta.testgenerator.common.BaseFunctions;
import org.cardanofoundation.rosetta.testgenerator.common.TestConstants;
import org.cardanofoundation.rosetta.testgenerator.common.TestTransactionNames;
import org.cardanofoundation.rosetta.testgenerator.common.TransactionBlockDetails;
import org.cardanofoundation.rosetta.testgenerator.transactions.TransactionRunner;

Expand All @@ -52,9 +53,11 @@ public void init() {
@Override
public Map<String, TransactionBlockDetails> runTransactions() {
Map<String, TransactionBlockDetails> generatedDataMap = HashMap.newHashMap(3);
generatedDataMap.put(TestConstants.POOL_REGISTRATION_TRANSACTION_NAME, registerPool());
generatedDataMap.put(TestConstants.POOL_DELEGATION_TRANSACTION_NAME, delegateStakeToPool());
generatedDataMap.put(TestConstants.POOL_RETIREMENT_TRANSACTION_NAME, retirePool());
generatedDataMap.put(TestTransactionNames.POOL_REGISTRATION_TRANSACTION.getName(),
registerPool());
generatedDataMap.put(TestTransactionNames.POOL_DELEGATION_TRANSACTION.getName(),
delegateStakeToPool());
generatedDataMap.put(TestTransactionNames.POOL_RETIREMENT_TRANSACTION.getName(), retirePool());
return generatedDataMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.cardanofoundation.rosetta.testgenerator.common.BaseFunctions;
import org.cardanofoundation.rosetta.testgenerator.common.TestConstants;
import org.cardanofoundation.rosetta.testgenerator.common.TestTransactionNames;
import org.cardanofoundation.rosetta.testgenerator.common.TransactionBlockDetails;
import org.cardanofoundation.rosetta.testgenerator.transactions.TransactionRunner;

Expand Down Expand Up @@ -55,18 +56,18 @@ public void init() {
@Override
public Map<String, TransactionBlockDetails> runTransactions() {
Map<String, TransactionBlockDetails> generatedDataMap = HashMap.newHashMap(6);
generatedDataMap.put(TestConstants.SIMPLE_TRANSACTION_NAME, simpleTransaction());
generatedDataMap.put(TestConstants.SIMPLE_LOVELACE_FIRST_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.SIMPLE_TRANSACTION.getName(), simpleTransaction());
generatedDataMap.put(TestTransactionNames.SIMPLE_LOVELACE_FIRST_TRANSACTION.getName(),
simpleLovelaceTransaction());
generatedDataMap.put(TestConstants.SIMPLE_LOVELACE_SECOND_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.SIMPLE_LOVELACE_SECOND_TRANSACTION.getName(),
simpleLovelaceTransaction());
generatedDataMap.put(TestConstants.SIMPLE_NEW_COINS_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.SIMPLE_NEW_COINS_TRANSACTION.getName(),
simpleNewCoinsTransaction());
generatedDataMap.put(TestConstants.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION.getName(),
simpleNewEmptyNameCoinsTransaction());
generatedDataMap.put(TestConstants.STAKE_KEY_REGISTRATION_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.STAKE_KEY_REGISTRATION_TRANSACTION.getName(),
stakeKeyRegistrationTransaction());
generatedDataMap.put(TestConstants.STAKE_KEY_DEREGISTRATION_TRANSACTION_NAME,
generatedDataMap.put(TestTransactionNames.STAKE_KEY_DEREGISTRATION_TRANSACTION.getName(),
stakeKeyDeregistrationTransaction());
return generatedDataMap;
}
Expand Down

0 comments on commit 1f9497e

Please sign in to comment.