Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Trintinalia committed Apr 21, 2023
1 parent d0ef217 commit 0e4325d
Showing 1 changed file with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -35,33 +36,6 @@
class ExtTracerTest extends AbstractModuleTracerTest {
static final Random rand = new Random();

@Test
public void testExactValue() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(6));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(7));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(13));
runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3));
}

@Test
public void testMAXExactValue() {
Bytes32 arg1 = UInt256.MAX_VALUE;
Bytes32 arg2 = UInt256.MAX_VALUE;
Bytes32 arg3 = UInt256.MAX_VALUE;
runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3));
}

@Test
public void testRandomExactValue() {
Bytes32 arg1 =
UInt256.fromHexString("0xcb694eaa08d8cb30a26a74edc8ced2cc0d7f453c6df96307bf3d9336784aba26");
Bytes32 arg2 =
UInt256.fromHexString("0xb1f3d8555ff1d8e1d1db41eb8640cdc0b5dc1ea19a87bd0cb046b634ab707409");
Bytes32 arg3 =
UInt256.fromHexString("0x07d761cc7e0bf9770db9d952e5b108c96e6c3f0526218d2bfbef3071b0d776b8");
runTest(OpCode.ADDMOD, List.of(arg1, arg2, arg3));
}

@Override
public Stream<Arguments> provideRandomArguments() {
final List<Arguments> arguments = new ArrayList<>();
Expand Down Expand Up @@ -90,6 +64,68 @@ public Stream<Arguments> provideNonRandomArguments() {
return arguments.stream();
}

@Test
public void argumentZeroValueTestMulModTest() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(0));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(7));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(13));
runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3));
}

@Test
public void argumentZeroValueTestAddModTest() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(0));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(7));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(13));
runTest(OpCode.ADDMOD, List.of(arg1, arg2, arg3));
}

@Test
public void modulusZeroValueTestMulModTest() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(1));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(1));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(0));

Assertions.assertThrows(
ArithmeticException.class, () -> runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3)));
}

@Test
public void modulusZeroValueTestAddModTest() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(1));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(1));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(0));
Assertions.assertThrows(
ArithmeticException.class, () -> runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3)));
}

@Test
public void tinyValueTest() {
Bytes32 arg1 = fromBigInteger(BigInteger.valueOf(6));
Bytes32 arg2 = fromBigInteger(BigInteger.valueOf(7));
Bytes32 arg3 = fromBigInteger(BigInteger.valueOf(13));
runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3));
}

@Test
public void maxExactValueTest() {
Bytes32 arg1 = UInt256.MAX_VALUE;
Bytes32 arg2 = UInt256.MAX_VALUE;
Bytes32 arg3 = UInt256.MAX_VALUE;
runTest(OpCode.MULMOD, List.of(arg1, arg2, arg3));
}

@Test
public void largeValueTest() {
Bytes32 arg1 =
UInt256.fromHexString("0xcb694eaa08d8cb30a26a74edc8ced2cc0d7f453c6df96307bf3d9336784aba26");
Bytes32 arg2 =
UInt256.fromHexString("0xb1f3d8555ff1d8e1d1db41eb8640cdc0b5dc1ea19a87bd0cb046b634ab707409");
Bytes32 arg3 =
UInt256.fromHexString("0x07d761cc7e0bf9770db9d952e5b108c96e6c3f0526218d2bfbef3071b0d776b8");
runTest(OpCode.ADDMOD, List.of(arg1, arg2, arg3));
}

@Override
protected ModuleTracer getModuleTracer() {
return new ExtTracer();
Expand Down

0 comments on commit 0e4325d

Please sign in to comment.