Skip to content

Commit

Permalink
refactor: RA-107 fix merge conflicts with main
Browse files Browse the repository at this point in the history
  • Loading branch information
shleger committed May 9, 2024
1 parent d30d153 commit 8d91f60
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ class AccountCoinsApiTest extends BaseSpringMvcTest {
private final String myAssetPolicyId = "55fb0efbf5721e95a05c3d9a13fa63421c83689b35de6247d9d371ef";
private final String latestTxHashOnZeroSlot = generatedDataMap.get(
TestTransactionNames.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION.getName()).txHash() + ":0";
private final String expectedTestAccountCoinAmount = "1635030";
private final String expectedTestAccountCoinAmount = "1636394";
private final Currency myAssetCurrency = getCurrency(TestConstants.MY_ASSET_SYMBOL,
myAssetPolicyId);
private final Currency myAssetCurrency =
getCurrency(TestConstants.MY_ASSET_SYMBOL,Constants.MULTI_ASSET_DECIMALS, myAssetPolicyId);
private final Currency ada = getCurrency(Constants.ADA, Constants.ADA_DECIMALS);
private final Currency lovelace = getCurrency(Constants.LOVELACE, Constants.MULTI_ASSET_DECIMALS);

@Test
void accountCoins2Ada_Test() {
AccountCoinsResponse accountCoinsResponse = post(newAccCoinsRequest(TEST_ACCOUNT_ADDRESS));
AccountCoinsResponse accountCoinsResponse = post(getAccountCoinsRequest(TEST_ACCOUNT_ADDRESS));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand All @@ -63,7 +62,7 @@ void accountCoins2Ada_Test() {

@Test
void accountCoins2Lovelace_Test() {
AccountCoinsResponse accountCoinsResponse = post(newAccCoinsRequest(RECEIVER_1));
AccountCoinsResponse accountCoinsResponse = post(getAccountCoinsRequest(RECEIVER_1));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand All @@ -86,7 +85,7 @@ void accountCoins2Lovelace_Test() {

@Test
void accountCoinsNoCoins_Test() {
AccountCoinsResponse accountCoinsResponse = post(newAccCoinsRequest(RECEIVER_2));
AccountCoinsResponse accountCoinsResponse = post(getAccountCoinsRequest(RECEIVER_2));

assertNotNull(accountCoinsResponse);
assertEquals(0, accountCoinsResponse.getCoins().size());
Expand All @@ -95,15 +94,15 @@ void accountCoinsNoCoins_Test() {
@Test
void accountCoinsNoCoinsForStakeAccount_Test() {
AccountCoinsResponse accountCoinsResponse =
post(newAccCoinsRequest(STAKE_ADDRESS_WITH_EARNED_REWARDS));
post(getAccountCoinsRequest(STAKE_ADDRESS_WITH_EARNED_REWARDS));

assertNotNull(accountCoinsResponse);
assertEquals(0, accountCoinsResponse.getCoins().size());
}

@Test
void accountCoinsDifferentCoins_Test() {
AccountCoinsResponse accountCoinsResponse = post(newAccCoinsRequest(TEST_ACCOUNT_ADDRESS));
AccountCoinsResponse accountCoinsResponse = post(getAccountCoinsRequest(TEST_ACCOUNT_ADDRESS));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand Down Expand Up @@ -133,16 +132,9 @@ void accountCoinsDifferentCoins_Test() {

@Test
void accountCoinsEmptyNameCoin_Test() {
final String emptyNamePolicyId = "b6d9dfb09401df509e565d42f0eff419ce58a020a9dbbe07754969d5";
AccountCoinsResponse accountCoinsResponse = post(
newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency("\\x", emptyNamePolicyId)));
ResponseEntity<AccountCoinsResponse> response = restTemplate.postForEntity(
getAccountCoinsUrl(),
getAccountCoinsRequestWithCurrencies(TestConstants.TEST_ACCOUNT_ADDRESS,
getCurrency("\\x", Constants.MULTI_ASSET_DECIMALS, myAssetPolicyId)),
AccountCoinsResponse.class);
AccountCoinsResponse accountCoinsResponse = response.getBody();
getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency("\\x", Constants.MULTI_ASSET_DECIMALS, myAssetPolicyId)));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand All @@ -169,7 +161,7 @@ void accountCoinsEmptyNameCoin_Test() {
@Test
void accountCoinsOneSpecifiedCurrency_Test() {
AccountCoinsResponse accountCoinsResponse =
post(newAccCoinsRequestWithCurrencies(RECEIVER_1, ada));
post(getAccountCoinsRequestWithCurrencies(RECEIVER_1, ada));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand All @@ -184,7 +176,7 @@ void accountCoinsOneSpecifiedCurrency_Test() {
@Test
void accountCoinsMultipleSpecifiedCurrencies_Test() {
AccountCoinsResponse accountCoinsResponse =
post(newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS, ada, myAssetCurrency));
post(getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS, ada, myAssetCurrency));

assertNotNull(accountCoinsResponse);
assertEquals(2, accountCoinsResponse.getCoins().size());
Expand All @@ -211,7 +203,7 @@ void accountCoinsMultipleSpecifiedCurrencies_Test() {

@Test
void accountCoinsException_Test() throws Exception {
AccountCoinsRequest accountCoinsRequest = newAccCoinsRequest(
AccountCoinsRequest accountCoinsRequest = getAccountCoinsRequest(
TEST_ACCOUNT_ADDRESS);
accountCoinsRequest.getAccountIdentifier().setAddress("invalid_address");

Expand All @@ -227,7 +219,7 @@ void accountCoinsException_Test() throws Exception {

@Test
void accountCoinsNonHexCurrencySymbolException_Test() throws Exception {
AccountCoinsRequest thisIsANonHexString = newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
AccountCoinsRequest thisIsANonHexString = getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency("thisIsANonHexString", Constants.MULTI_ASSET_DECIMALS));

mockMvc.perform(MockMvcRequestBuilders.post("/account/coins")
Expand All @@ -245,7 +237,8 @@ void accountCoinsLovelaceCurrencySymbolException_Test() throws Exception {

mockMvc.perform(MockMvcRequestBuilders.post("/account/coins")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(newAccCoinsRequestWithCurrencies(RECEIVER_1, lovelace))))
.content(objectMapper.writeValueAsString(
getAccountCoinsRequestWithCurrencies(RECEIVER_1, lovelace))))
.andDo(print())
.andExpect(jsonPath("$.code").value(4024))
.andExpect(jsonPath("$.message").value("Invalid token name"))
Expand All @@ -261,7 +254,7 @@ void accountCoinsTooLongCurrencyNameException_Test() throws Exception {
.collect(Collectors.joining());

AccountCoinsRequest request =
newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency(tooLongCurrencyName, Constants.MULTI_ASSET_DECIMALS));

mockMvc.perform(MockMvcRequestBuilders.post("/account/coins")
Expand All @@ -278,7 +271,7 @@ void accountCoinsTooLongCurrencyNameException_Test() throws Exception {
void accountCoinsTooLongPolicyIdException_Test() throws Exception {
String tooLongPolicyId = Stream.generate(() -> "w").limit(Constants.POLICY_ID_LENGTH + 2)
.collect(Collectors.joining());
AccountCoinsRequest request = newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
AccountCoinsRequest request = getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency(TestConstants.CURRENCY_HEX_SYMBOL, Constants.MULTI_ASSET_DECIMALS)
.metadata(new CurrencyMetadata(tooLongPolicyId)));

Expand All @@ -294,7 +287,7 @@ void accountCoinsTooLongPolicyIdException_Test() throws Exception {

@Test
void accountCoinsNonHexPolicyIdException_Test() throws Exception {
AccountCoinsRequest request = newAccCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
AccountCoinsRequest request = getAccountCoinsRequestWithCurrencies(TEST_ACCOUNT_ADDRESS,
getCurrency(TestConstants.CURRENCY_HEX_SYMBOL, Constants.MULTI_ASSET_DECIMALS)
.metadata(new CurrencyMetadata("thisIsNonHexPolicyId")));

Expand All @@ -309,7 +302,7 @@ void accountCoinsNonHexPolicyIdException_Test() throws Exception {
}


private AccountCoinsRequest newAccCoinsRequest(String accountAddress) {
private AccountCoinsRequest getAccountCoinsRequest(String accountAddress) {
return AccountCoinsRequest.builder()
.networkIdentifier(NetworkIdentifier.builder()
.blockchain(TestConstants.TEST_BLOCKCHAIN)
Expand All @@ -322,7 +315,7 @@ private AccountCoinsRequest newAccCoinsRequest(String accountAddress) {
.build();
}

private AccountCoinsRequest newAccCoinsRequestWithCurrencies(String accountAddress,
private AccountCoinsRequest getAccountCoinsRequestWithCurrencies(String accountAddress,
Currency... currencies) {
return AccountCoinsRequest.builder()
.networkIdentifier(NetworkIdentifier.builder()
Expand All @@ -344,15 +337,15 @@ private Currency getCurrency(String symbol, int decimals) {
.build();
}

private Currency getCurrency(String symbol, String policyId) {
private Currency getCurrency(String symbol, int decimals, String policyId) {
return Currency.builder()
.symbol(symbol)
.decimals(Constants.MULTI_ASSET_DECIMALS)
.decimals(decimals)
.metadata(CurrencyMetadata.builder().policyId(policyId).build())
.build();
}

private AccountCoinsResponse post(AccountCoinsRequest accountBalanceRequest) {
private AccountCoinsResponse post(AccountCoinsRequest accountBalanceRequest) {
try {
var resp = mockMvc.perform(MockMvcRequestBuilders.post("/account/coins")
.contentType(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit 8d91f60

Please sign in to comment.