-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove encodeAsByteString() and only handle BS to BigInt decoding
- Loading branch information
Showing
4 changed files
with
116 additions
and
66 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
51 changes: 51 additions & 0 deletions
51
plutus/src/test/java/com/bloxbean/cardano/client/plutus/spec/BigIntPlutusDataTest.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,51 @@ | ||
package com.bloxbean.cardano.client.plutus.spec; | ||
|
||
import co.nstant.in.cbor.model.ByteString; | ||
import co.nstant.in.cbor.model.NegativeInteger; | ||
import co.nstant.in.cbor.model.Number; | ||
import co.nstant.in.cbor.model.UnsignedInteger; | ||
import com.bloxbean.cardano.client.common.cbor.CborSerializationUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigInteger; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class BigIntPlutusDataTest { | ||
|
||
@Test | ||
void deserialize_overLongNegative() throws Exception { | ||
NegativeInteger negativeInteger = new NegativeInteger(new BigInteger("-10000000000000000020000003000000004000000")); | ||
var bytes = CborSerializationUtil.serialize(negativeInteger); | ||
|
||
BigIntPlutusData bigIntPlutusData = BigIntPlutusData.deserialize((ByteString) CborSerializationUtil.deserialize(bytes)); | ||
assertThat(bigIntPlutusData.getValue()).isEqualTo(new BigInteger("-10000000000000000020000003000000004000000")); | ||
} | ||
|
||
@Test | ||
void deserialize_longNegative() throws Exception { | ||
NegativeInteger negativeInteger = new NegativeInteger(BigInteger.valueOf(Long.MAX_VALUE).negate()); | ||
var bytes = CborSerializationUtil.serialize(negativeInteger); | ||
|
||
BigIntPlutusData bigIntPlutusData = BigIntPlutusData.deserialize((Number) CborSerializationUtil.deserialize(bytes)); | ||
assertThat(bigIntPlutusData.getValue()).isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).negate()); | ||
} | ||
|
||
@Test | ||
void deserialize_overLong() throws Exception { | ||
UnsignedInteger integer = new UnsignedInteger(new BigInteger("10000000000000000020000003000000004000000")); | ||
var bytes = CborSerializationUtil.serialize(integer); | ||
|
||
BigIntPlutusData bigIntPlutusData = BigIntPlutusData.deserialize((ByteString) CborSerializationUtil.deserialize(bytes)); | ||
assertThat(bigIntPlutusData.getValue()).isEqualTo(new BigInteger("10000000000000000020000003000000004000000")); | ||
} | ||
|
||
@Test | ||
void deserialize_long() throws Exception { | ||
UnsignedInteger integer = new UnsignedInteger(BigInteger.valueOf(Long.MAX_VALUE)); | ||
var bytes = CborSerializationUtil.serialize(integer); | ||
|
||
BigIntPlutusData bigIntPlutusData = BigIntPlutusData.deserialize((Number) CborSerializationUtil.deserialize(bytes)); | ||
assertThat(bigIntPlutusData.getValue()).isEqualTo(BigInteger.valueOf(Long.MAX_VALUE)); | ||
} | ||
} |
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