-
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.
fix int128 borsh encoding. add int256.
- Loading branch information
Showing
3 changed files
with
83 additions
and
15 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
37 changes: 26 additions & 11 deletions
37
core/src/test/java/software/sava/core/ecnoding/ByteUtilTests.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 |
---|---|---|
@@ -1,21 +1,36 @@ | ||
package software.sava.core.ecnoding; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import software.sava.core.encoding.ByteUtil; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
final class ByteUtilTests { | ||
|
||
private void testInt128(final BigInteger expected) { | ||
byte[] write = new byte[16]; | ||
ByteUtil.putInt128LE(write, 0, expected); | ||
var read = ByteUtil.getInt128LE(write, 0); | ||
assertEquals(expected, read); | ||
|
||
if (expected.signum() < 0) { | ||
final var abs = expected.negate(); | ||
Arrays.fill(write, (byte) 0); | ||
ByteUtil.putInt128LE(write, 0, abs); | ||
read = ByteUtil.getUInt128LE(write, 0); | ||
assertEquals(abs, read); | ||
} | ||
} | ||
|
||
@Test | ||
void test128BitIntegers() { | ||
// var expected = new BigInteger("-155155494242896723051467122773477245"); | ||
// byte[] write = new byte[16]; | ||
// ByteUtil.putInt128LE(write, 0, expected); | ||
// var read = ByteUtil.getInt128LE(write, 0); | ||
// assertEquals(expected, read); | ||
// | ||
// expected = new BigInteger("-25912721450736272609715131753556298938"); | ||
// write = new byte[16]; | ||
// ByteUtil.putInt128LE(write, 0, expected); | ||
// read = ByteUtil.getInt128LE(write, 0); | ||
// assertEquals(expected, read); | ||
var expected = new BigInteger("-155155494242896723051467122773477245"); | ||
testInt128(expected); | ||
|
||
expected = new BigInteger("-25912721450736272609715131753556298938"); | ||
testInt128(expected); | ||
} | ||
} |