AddressUtils.java

1
package org.cardanofoundation.explorer.api.util;
2
3
import com.bloxbean.cardano.client.address.util.AddressUtil;
4
5
import org.cardanofoundation.explorer.api.common.constant.CommonConstant;
6
import org.cardanofoundation.explorer.api.exception.BusinessCode;
7
import org.cardanofoundation.explorer.common.exception.BusinessException;
8
import org.cardanofoundation.explorer.common.model.address.ShelleyAddress;
9
10
public class AddressUtils {
11
12
  private AddressUtils() {
13
    throw new IllegalStateException("Utility class");
14
  }
15
16
  /**
17
   * Check address
18
   *
19
   * @param address address
20
   * @return stake address if exits, throw exception if not valid
21
   */
22
  public static String checkStakeAddress(String address) {
23
    String stakeAddress = null;
24
    try {
25 1 1. checkStakeAddress : negated conditional → KILLED
      if (address.startsWith(CommonConstant.ADDRESS_PREFIX)) {
26
        ShelleyAddress shelleyAddress = new ShelleyAddress(address);
27 1 1. checkStakeAddress : negated conditional → KILLED
        if (shelleyAddress.containStakeAddress()) {
28
          // TO-DO: Move to common
29
          byte[] addr = shelleyAddress.getStakeReference();
30
          shelleyAddress.getHexPaymentPart();
31
          ShelleyAddress stakeShelley = new ShelleyAddress(addr);
32
          stakeAddress = stakeShelley.getAddress();
33
        }
34 1 1. checkStakeAddress : negated conditional → SURVIVED
      } else if (address.startsWith(CommonConstant.STAKE_ADDRESS_PREFIX)) {
35
        throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND);
36 1 1. checkStakeAddress : negated conditional → NO_COVERAGE
      } else if (!AddressUtil.isValidAddress(address)) {
37
        throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND);
38
      }
39
    } catch (Exception e) {
40
      throw new BusinessException(BusinessCode.ADDRESS_NOT_FOUND);
41
    }
42 1 1. checkStakeAddress : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::checkStakeAddress → KILLED
    return stakeAddress;
43
  }
44
45
  /**
46
   * Get hex payment part (script hash) associated with the address
47
   *
48
   * @param address
49
   * @return hex payment part
50
   */
51
  public static String getHexPaymentPart(String address) {
52 1 1. getHexPaymentPart : negated conditional → KILLED
    if (address.startsWith(CommonConstant.ADDRESS_PREFIX)) {
53
      ShelleyAddress shelleyAddress = new ShelleyAddress(address);
54 1 1. getHexPaymentPart : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → KILLED
      return shelleyAddress.getHexPaymentPart();
55
    }
56 1 1. getHexPaymentPart : replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → NO_COVERAGE
    return null;
57
  }
58
}

Mutations

25

1.1
Location : checkStakeAddress
Killed by : org.cardanofoundation.explorer.api.service.StakeKeyServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.StakeKeyServiceTest]/[method:testGetStakeByAddressWhenRewardAvailable_thenReturn()]
negated conditional → KILLED

27

1.1
Location : checkStakeAddress
Killed by : org.cardanofoundation.explorer.api.service.AddressServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.AddressServiceTest]/[method:getAddressDetail_shouldReturnV2()]
negated conditional → KILLED

34

1.1
Location : checkStakeAddress
Killed by : none
negated conditional → SURVIVED

36

1.1
Location : checkStakeAddress
Killed by : none
negated conditional → NO_COVERAGE

42

1.1
Location : checkStakeAddress
Killed by : org.cardanofoundation.explorer.api.service.StakeKeyServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.StakeKeyServiceTest]/[method:testGetStakeByAddressWhenRewardAvailable_thenReturn()]
replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::checkStakeAddress → KILLED

52

1.1
Location : getHexPaymentPart
Killed by : org.cardanofoundation.explorer.api.service.AddressServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.AddressServiceTest]/[method:getAddressDetail_shouldAssociatedWithSmartContract()]
negated conditional → KILLED

54

1.1
Location : getHexPaymentPart
Killed by : org.cardanofoundation.explorer.api.service.AddressServiceTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.service.AddressServiceTest]/[method:getAddressDetail_shouldAssociatedWithSmartContract()]
replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → KILLED

56

1.1
Location : getHexPaymentPart
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/util/AddressUtils::getHexPaymentPart → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2