-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aleksandr Sologub
committed
May 20, 2024
1 parent
db46c38
commit a3ac598
Showing
13 changed files
with
339 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
api/src/test/java/org/cardanofoundation/rosetta/common/mapper/OperationToCborMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.cardanofoundation.rosetta.common.mapper; | ||
|
||
import java.util.List; | ||
|
||
import co.nstant.in.cbor.model.Map; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.openapitools.client.model.AccountIdentifier; | ||
import org.openapitools.client.model.AccountIdentifierMetadata; | ||
import org.openapitools.client.model.Amount; | ||
import org.openapitools.client.model.Currency; | ||
import org.openapitools.client.model.CurrencyMetadata; | ||
import org.openapitools.client.model.Operation; | ||
import org.openapitools.client.model.OperationIdentifier; | ||
import org.openapitools.client.model.OperationMetadata; | ||
import org.openapitools.client.model.PoolMargin; | ||
import org.openapitools.client.model.PoolMetadata; | ||
import org.openapitools.client.model.PoolRegistrationParams; | ||
import org.openapitools.client.model.Relay; | ||
import org.openapitools.client.model.SubAccountIdentifier; | ||
import org.openapitools.client.model.TokenBundleItem; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import org.cardanofoundation.rosetta.common.util.Constants; | ||
|
||
import static org.cardanofoundation.rosetta.common.mapper.OperationToCborMap.convertToCborMap; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class OperationToCborMapTest { | ||
|
||
@Test | ||
void convertToCborMapAndViseVersaTest() { | ||
//given | ||
AccountIdentifier accountIdentifier = new AccountIdentifier("address", new SubAccountIdentifier("address", null), | ||
new AccountIdentifierMetadata()); | ||
PoolRegistrationParams poolRegistrationParams = PoolRegistrationParams | ||
.builder() | ||
.poolOwners(List.of("owner")) | ||
.margin(new PoolMargin("numerator", "denominator")) | ||
.relays(List.of(new Relay("ipv4", "ipv6", "name", 8080, "type"))) | ||
.poolMetadata(new PoolMetadata("url", "hash")) | ||
.build(); | ||
OperationMetadata operationMetadata = OperationMetadata.builder() | ||
.poolRegistrationParams(poolRegistrationParams) | ||
.refundAmount(new Amount("2", new Currency(Constants.ADA, 2, new CurrencyMetadata("policyId")), new Object())) | ||
.tokenBundle(List.of(new TokenBundleItem("tokenBunlePolicyId", List.of(new Amount())))) | ||
.build(); | ||
Operation operation = Operation | ||
.builder() | ||
.operationIdentifier(new OperationIdentifier()) | ||
.account(accountIdentifier) | ||
.type("poolRegistration") | ||
.metadata(operationMetadata) | ||
.build(); | ||
//when | ||
Map map = convertToCborMap(operation); | ||
Operation opr = CborMapToOperation.cborMapToOperation(map); | ||
//then | ||
assertEquals(4, map.getKeys().size()); | ||
assertEquals(operation.getAccount().getAddress(), opr.getAccount().getAddress()); | ||
assertEquals(operation.getAccount().getSubAccount(), opr.getAccount().getSubAccount()); | ||
assertEquals(operation.getOperationIdentifier(), opr.getOperationIdentifier()); | ||
assertEquals(operation.getMetadata().getPoolRegistrationParams().getPoolOwners(), opr.getMetadata().getPoolRegistrationParams().getPoolOwners()); | ||
assertEquals(operation.getMetadata().getPoolRegistrationParams().getRelays().getFirst().getDnsName(), | ||
opr.getMetadata().getPoolRegistrationParams().getRelays().getFirst().getDnsName()); | ||
assertEquals(operation.getMetadata().getPoolRegistrationParams().getMargin(), opr.getMetadata().getPoolRegistrationParams().getMargin()); | ||
assertEquals(operation.getMetadata().getPoolRegistrationParams().getPoolMetadata(), opr.getMetadata().getPoolRegistrationParams().getPoolMetadata()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...est/java/org/cardanofoundation/rosetta/common/mapper/TransactionDataToOperationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.cardanofoundation.rosetta.common.mapper; | ||
|
||
import java.util.List; | ||
|
||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.openapitools.client.model.Operation; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import org.cardanofoundation.rosetta.common.enumeration.NetworkIdentifierType; | ||
|
||
import static org.cardanofoundation.rosetta.common.mapper.TransactionDataToOperations.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TransactionDataToOperationsTest { | ||
|
||
@Test | ||
void getPoolSignersFromOperationWOPoolSigners() { | ||
//given | ||
Operation operation = Operation | ||
.builder() | ||
.type("poolRegistration") | ||
.build(); | ||
//when | ||
List<String> poolSigners = getPoolSigners(NetworkIdentifierType.CARDANO_MAINNET_NETWORK, operation); | ||
//then | ||
Assertions.assertEquals(0, poolSigners.size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.