Skip to content

Commit 627877e

Browse files
authored
Merge branch 'main' into feat/RA-141-Remove-relative-paths-from-docker
2 parents b95ea99 + b12479c commit 627877e

File tree

13 files changed

+392
-34
lines changed

13 files changed

+392
-34
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: SonarCloud
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
build:
10+
name: Build and analyze
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '21'
20+
distribution: 'temurin'
21+
cache: maven
22+
- name: Build
23+
env:
24+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: mvn clean verify sonar:sonar -Dsonar.projectName=cardano-rosetta-java -Dsonar.organization=cardano-foundation -Dsonar.projectKey=cardano-foundation_cardano-rosetta-java -Dsonar.host.url=https://sonarcloud.io --file ./pom.xml

api/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
**/rosetta/common/exception/Details.java,
3131
**/rosetta/common/exception/ApiException.java
3232
</test.exclusions>
33+
<sonar.sources>src/main/java</sonar.sources>
3334
<sonar.coverage.exclusions>${test.exclusions}</sonar.coverage.exclusions>
3435
</properties>
3536

api/src/main/java/org/cardanofoundation/rosetta/common/mapper/CborMapToTransactionExtraData.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,37 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Objects;
56

67
import co.nstant.in.cbor.model.Array;
78
import co.nstant.in.cbor.model.DataItem;
89
import co.nstant.in.cbor.model.Map;
910
import co.nstant.in.cbor.model.UnicodeString;
1011
import org.openapitools.client.model.Operation;
1112

13+
import org.cardanofoundation.rosetta.common.exception.ExceptionFactory;
1214
import org.cardanofoundation.rosetta.common.model.cardano.transaction.TransactionExtraData;
1315
import org.cardanofoundation.rosetta.common.util.Constants;
1416

1517
public class CborMapToTransactionExtraData {
1618

17-
private CborMapToTransactionExtraData() {}
19+
private static final UnicodeString OPERATIONS = new UnicodeString(Constants.OPERATIONS);
20+
private static final UnicodeString TRANSACTION_METADATA_HEX = new UnicodeString(
21+
Constants.TRANSACTIONMETADATAHEX);
22+
23+
private CborMapToTransactionExtraData() {
24+
}
1825

1926
public static TransactionExtraData convertCborMapToTransactionExtraData(Map map) {
2027
String transactionMetadataHex = getTransactionMetadataHexFromMap(map);
2128

2229
List<Operation> operations = new ArrayList<>();
23-
List<DataItem> operationsListMap = ((Array) map.get(
24-
new UnicodeString(Constants.OPERATIONS))).getDataItems();
30+
Array dataItems = (Array) map.get(OPERATIONS);
31+
if (Objects.isNull(dataItems)) {
32+
throw ExceptionFactory.parseSignedTransactionError();
33+
}
34+
35+
List<DataItem> operationsListMap = dataItems.getDataItems();
2536
operationsListMap.forEach(oDataItem -> {
2637
Map operationMap = (Map) oDataItem;
2738
Operation operation = CborMapToOperation.cborMapToOperation(operationMap);
@@ -31,7 +42,7 @@ public static TransactionExtraData convertCborMapToTransactionExtraData(Map map)
3142
}
3243

3344
private static String getTransactionMetadataHexFromMap(Map map) {
34-
DataItem transactionMetadataHex = map.get(new UnicodeString(Constants.TRANSACTIONMETADATAHEX));
45+
DataItem transactionMetadataHex = map.get(TRANSACTION_METADATA_HEX);
3546
return transactionMetadataHex == null ? ""
3647
: ((UnicodeString) transactionMetadataHex).getString();
3748
}

api/src/main/java/org/cardanofoundation/rosetta/common/services/impl/CardanoAddressServiceImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lombok.extern.slf4j.Slf4j;
55

66
import org.springframework.stereotype.Service;
7-
import com.bloxbean.cardano.client.account.Account;
87
import com.bloxbean.cardano.client.address.Address;
98
import com.bloxbean.cardano.client.address.AddressProvider;
109
import com.bloxbean.cardano.client.crypto.bip32.key.HdPublicKey;
@@ -32,7 +31,6 @@ public String getCardanoAddress(AddressType addressType, PublicKey stakingCreden
3231
throw ExceptionFactory.missingStakingKeyError();
3332
log.debug("Deriving base address with staking credential: {}", stakingCredential);
3433
Address baseAddress = AddressProvider.getBaseAddress(getHdPublicKeyFromRosettaKey(publicKey), getHdPublicKeyFromRosettaKey(stakingCredential), networkEnum.getNetwork());
35-
new Account();
3634
address = baseAddress.getAddress();
3735
break;
3836
case REWARD:

api/src/test/java/org/cardanofoundation/rosetta/EntityGenerator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.openapitools.client.model.Version;
5050

5151
import static org.cardanofoundation.rosetta.common.util.Constants.*;
52+
import static org.openapitools.client.model.CurveType.EDWARDS25519;
5253

5354
@UtilityClass
5455
public class EntityGenerator {
@@ -302,4 +303,10 @@ public static ConstructionPreprocessResponse givenConstructionPreprocessResponse
302303
.build()))
303304
.build();
304305
}
306+
307+
public static PublicKey givenPublicKey() {
308+
return new PublicKey("1B400D60AAF34EAF6DCBAB9BBA46001A23497886CF11066F7846933D30E5AD3F",
309+
EDWARDS25519);
310+
311+
}
305312
}

api/src/test/java/org/cardanofoundation/rosetta/api/construction/service/CombineApiTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.io.IOException;
55

66
import org.springframework.beans.factory.annotation.Autowired;
7-
import co.nstant.in.cbor.CborException;
87
import com.fasterxml.jackson.databind.ObjectMapper;
98
import org.openapitools.client.model.ConstructionCombineRequest;
109
import org.openapitools.client.model.ConstructionCombineResponse;
@@ -27,7 +26,7 @@ private ConstructionCombineRequest getCombineRequest(String fileName) throws IOE
2726
}
2827

2928
@Test
30-
void combineWithMetadataTest() throws IOException, CborException {
29+
void combineWithMetadataTest() throws IOException {
3130
ConstructionCombineRequest combineRequest = getCombineRequest(
3231
"testdata/construction/combine/combine_with_metadata.json");
3332

@@ -38,7 +37,7 @@ void combineWithMetadataTest() throws IOException, CborException {
3837
}
3938

4039
@Test
41-
void combineWithByronAddressTest() throws IOException, CborException {
40+
void combineWithByronAddressTest() throws IOException {
4241
ConstructionCombineRequest combineRequest = getCombineRequest(
4342
"testdata/construction/combine/combine_with_byron_addresses.json");
4443

api/src/test/java/org/cardanofoundation/rosetta/api/construction/service/DeriveApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private ConstructionDeriveRequest getDeriveRequest(String fileName) throws IOExc
2727
}
2828

2929
@Test
30-
void deriveAddressTest() throws IOException, IllegalAccessException {
30+
void deriveAddressTest() throws IOException {
3131
ConstructionDeriveRequest deriveRequest = getDeriveRequest(
3232
"testdata/construction/derive/derive_request.json");
3333
ConstructionDeriveResponse constructionDeriveResponse = constructionApiService.constructionDeriveService(

api/src/test/java/org/cardanofoundation/rosetta/api/construction/service/PayloadsApiTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.util.List;
56

67
import org.springframework.beans.factory.annotation.Autowired;
78
import com.fasterxml.jackson.databind.ObjectMapper;
89
import org.openapitools.client.model.ConstructionPayloadsRequest;
910
import org.openapitools.client.model.ConstructionPayloadsResponse;
11+
import org.openapitools.client.model.Operation;
1012

13+
import org.junit.jupiter.api.Assertions;
1114
import org.junit.jupiter.api.Test;
1215

1316
import org.cardanofoundation.rosetta.api.IntegrationTest;
17+
import org.cardanofoundation.rosetta.common.exception.ApiException;
1418

1519
import static org.junit.jupiter.api.Assertions.assertEquals;
1620

@@ -62,6 +66,18 @@ void stakeKeyDeregistrationTest() throws Exception {
6266
expectedUnsignedTransaction);
6367
}
6468

69+
@Test
70+
void operationsHaveIdentifierTest() {
71+
ConstructionPayloadsRequest request = ConstructionPayloadsRequest
72+
.builder()
73+
.operations(List.of(new Operation()))
74+
.build();
75+
ApiException exception = Assertions.assertThrows(ApiException.class,
76+
() -> constructionApiService.constructionPayloadsService(request));
77+
Assertions.assertEquals("body[0] should have required property operation_identifier",
78+
exception.getError().getDetails().getMessage());
79+
}
80+
6581
private void assertConstructionPayloads(String requestFile, String expectedUnsignedTransaction)
6682
throws Exception {
6783
ConstructionPayloadsRequest request = getPayloadRequest(requestFile);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.cardanofoundation.rosetta.common.services.impl;
2+
3+
import org.mockito.junit.jupiter.MockitoExtension;
4+
import org.openapitools.client.model.PublicKey;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.extension.ExtendWith;
8+
9+
import org.cardanofoundation.rosetta.common.enumeration.AddressType;
10+
import org.cardanofoundation.rosetta.common.exception.ApiException;
11+
12+
import static org.cardanofoundation.rosetta.EntityGenerator.givenPublicKey;
13+
import static org.cardanofoundation.rosetta.common.enumeration.AddressType.BASE;
14+
import static org.cardanofoundation.rosetta.common.enumeration.AddressType.REWARD;
15+
import static org.cardanofoundation.rosetta.common.enumeration.NetworkEnum.PREPROD;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
import static org.openapitools.client.model.CurveType.EDWARDS25519;
19+
20+
@SuppressWarnings("java:S5778")
21+
@ExtendWith(MockitoExtension.class)
22+
class CardanoAddressServiceImplTest {
23+
24+
CardanoAddressServiceImpl genesisService = new CardanoAddressServiceImpl();
25+
26+
@Test
27+
void getCardanoBaseAddressTest() {
28+
PublicKey stakingCredential = givenPublicKey();
29+
PublicKey publicKey = givenPublicKey();
30+
31+
String cardanoAddress = genesisService
32+
.getCardanoAddress(BASE, stakingCredential, publicKey, PREPROD);
33+
34+
assertEquals("addr_test1qza5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7amgrc6v3au3rqm66mn3kuwke340kfxga82tl7kh2nke8aslzyvu5",
35+
cardanoAddress);
36+
}
37+
38+
@Test
39+
void getCardanoBaseAddressMissingPubKeyTest() {
40+
ApiException exception = assertThrows(ApiException.class,
41+
() -> genesisService.getCardanoAddress(BASE, null, null, PREPROD));
42+
43+
assertEquals("Public key is missing", exception.getError().getMessage());
44+
}
45+
46+
@Test
47+
void getCardanoBaseAddressMissingStakingTest() {
48+
ApiException exception = assertThrows(ApiException.class,
49+
() -> genesisService.getCardanoAddress(BASE, null, new PublicKey(), PREPROD));
50+
51+
assertEquals("Staking key is required for this type of address", exception.getError().getMessage());
52+
}
53+
54+
@Test
55+
void getCardanoRewardAddressTest() {
56+
PublicKey stakingCredential = givenPublicKey();
57+
PublicKey publicKey = givenPublicKey();
58+
59+
String cardanoAddress = genesisService
60+
.getCardanoAddress(REWARD, stakingCredential, publicKey, PREPROD);
61+
62+
assertEquals("stake_test1uza5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7c6nuuef", cardanoAddress);
63+
}
64+
65+
@Test
66+
void getCardanoRewardAddressWOStakingTest() {
67+
PublicKey publicKey = givenPublicKey();
68+
69+
String cardanoAddress = genesisService
70+
.getCardanoAddress(REWARD, null, publicKey, PREPROD);
71+
72+
assertEquals("stake_test1uza5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7c6nuuef", cardanoAddress);
73+
}
74+
75+
@Test
76+
void getCardanoNullAddressTest() {
77+
ApiException exception = assertThrows(ApiException.class,
78+
() -> genesisService.getCardanoAddress(AddressType.POOL_KEY_HASH,
79+
null, new PublicKey(), PREPROD));
80+
81+
assertEquals("Provided address type is invalid", exception.getError().getMessage());
82+
}
83+
84+
@Test
85+
void getHdPublicKeyFromRosettaKeyTest() {
86+
PublicKey publicKey = new PublicKey("48656C6C6F2C20776F726C6421", EDWARDS25519);
87+
88+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
89+
() -> genesisService.getHdPublicKeyFromRosettaKey(publicKey));
90+
91+
assertEquals("Invalid public key length", exception.getMessage());
92+
}
93+
94+
}

api/src/test/java/org/cardanofoundation/rosetta/common/services/impl/ProtocolParamServiceImplTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ void getProtocolParameters() {
3333
ReflectionTestUtils.setField(genesisService, "genesisShelleyPath", genesisPath);
3434

3535
assertNotNull(genesisService.getProtocolParameters().getPoolDeposit());
36-
37-
3836
}
3937
}

0 commit comments

Comments
 (0)