Skip to content

Commit

Permalink
chore: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Sep 5, 2024
1 parent 514da26 commit 3de4d36
Showing 1 changed file with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.bloxbean.cardano.client.plutus.spec.Language;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -14,48 +14,53 @@ class CostModelUtilTest {

@Test
void getCostModelFromProtocolParams() {
Map<String, Long> costModel1 = Map.of("verifyEd25519Signature-cpu-arguments-slope", 1021L,
"addInteger-cpu-arguments-intercept", 205665L,
"verifyEd25519Signature-memory-arguments", 10L,
"unBData-cpu-arguments", 31220L);

Map<String, Long> costModel2 = Map.of("addInteger-cpu-arguments-slope", 812L,
"addInteger-cpu-arguments-intercept", 205665L,
"verifyEd25519Signature-memory-arguments", 10L,
"bData-cpu-arguments", 1000L);

Map<String, Map<String, Long>> costModels = Map.of("PlutusV1", costModel1,
"PlutusV2", costModel2);
LinkedHashMap<String, Long> costModel1 = new LinkedHashMap<>();
costModel1.put("verifyEd25519Signature-cpu-arguments-slope", 1021L);
costModel1.put("addInteger-cpu-arguments-intercept", 205665L);
costModel1.put("verifyEd25519Signature-memory-arguments", 10L);
costModel1.put("unBData-cpu-arguments", 31220L);

LinkedHashMap<String, Long> costModel2 = new LinkedHashMap<>();
costModel2.put("addInteger-cpu-arguments-slope", 812L);
costModel2.put("addInteger-cpu-arguments-intercept", 205665L);
costModel2.put("verifyEd25519Signature-memory-arguments", 10L);
costModel2.put("bData-cpu-arguments", 1000L);

LinkedHashMap<String, LinkedHashMap<String, Long>> costModels = new LinkedHashMap<>();
costModels.put("PlutusV1", costModel1);
costModels.put("PlutusV2", costModel2);
ProtocolParams protocolParams = new ProtocolParams();
protocolParams.setCostModels(costModels);

Optional<CostModel> v1CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V1);
Optional<CostModel> v2CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V2);

assertThat(v1CostModel.get().getCosts()).isEqualTo(new long[]{205665L, 31220L, 1021L, 10L});
assertThat(v2CostModel.get().getCosts()).isEqualTo(new long[]{205665L, 812L, 1000L, 10L});
assertThat(v1CostModel.get().getCosts()).isEqualTo(new long[]{1021L, 205665L, 10L, 31220L});
assertThat(v2CostModel.get().getCosts()).isEqualTo(new long[]{812L, 205665L, 10L, 1000L});
}

@Test
void getCostModelFromProtocolParams_whenNotExists_returnsNull() {
Map<String, Long> costModel1 = Map.of("verifyEd25519Signature-cpu-arguments-slope", 1021L,
"addInteger-cpu-arguments-intercept", 205665L,
"verifyEd25519Signature-memory-arguments", 10L,
"unBData-cpu-arguments", 31220L);

Map<String, Map<String, Long>> costModels = Map.of("PlutusV1", costModel1);
LinkedHashMap<String, Long> costModel1 = new LinkedHashMap<>();
costModel1.put("verifyEd25519Signature-cpu-arguments-slope", 1021L);
costModel1.put("addInteger-cpu-arguments-intercept", 205665L);
costModel1.put("verifyEd25519Signature-memory-arguments", 10L);
costModel1.put("unBData-cpu-arguments", 31220L);

LinkedHashMap<String, LinkedHashMap<String, Long>> costModels = new LinkedHashMap<>();
costModels.put("PlutusV1", costModel1);
ProtocolParams protocolParams = new ProtocolParams();
protocolParams.setCostModels(costModels);

Optional<CostModel> v2CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V2);
Optional<CostModel> v2CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V2);

assertThat(v2CostModel).isEmpty();
}

@Test
void getCostModelFromProtocolParams_whenNoCostModelExists_returnsNull() {
ProtocolParams protocolParams = new ProtocolParams();
Optional<CostModel> v2CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V2);
Optional<CostModel> v2CostModel = CostModelUtil.getCostModelFromProtocolParams(protocolParams, Language.PLUTUS_V2);

assertThat(v2CostModel).isEmpty();
}
Expand Down

0 comments on commit 3de4d36

Please sign in to comment.