Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Dec 13, 2024
1 parent 5091668 commit c7c2b2b
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions rskj-core/src/test/java/co/rsk/vm/opcode/MCopyGasTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ private static Stream<Arguments> provideParametersForMCOPYGasTest() {
Arguments.of(new String[]{ "0001020304050607080000000000000000000000000000000000000000000000" }, 0, 1, 8, 6),
Arguments.of(new String[]{ "0001020304050607080000000000000000000000000000000000000000000000" }, 1, 0, 8, 6),
Arguments.of(new String[]{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", "404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f", "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f", "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", "a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "c0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "e0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" }, 256, 256, 1, 9),
Arguments.of(new String[]{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", "404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f", "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f", "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", "a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "c0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "e0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" }, 0, 256, 256, 27)
Arguments.of(new String[]{ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f", "404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f", "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f", "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", "a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf", "c0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf", "e0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" }, 0, 256, 256, 51)
);
}

@ParameterizedTest
@MethodSource("provideParametersForMCOPYOutOfGasExceptionTest")
void testMCopy_ShouldThrowOutOfGasException(String[] initMemory, long dst, long src, long length) {
void testMCopy_ShouldThrowOutOfGasException(String[] initMemory, String dst, String src, String length) {
// Given
byte[] code = compiler.compile("MCOPY");
VM vm = new VM(vmConfig, precompiledContracts);
Expand All @@ -104,9 +104,9 @@ void testMCopy_ShouldThrowOutOfGasException(String[] initMemory, long dst, long
address += 32;
}

program.stackPush(DataWord.valueOf(length)); // Mind the stack order!!
program.stackPush(DataWord.valueOf(src));
program.stackPush(DataWord.valueOf(dst));
program.stackPush(DataWord.valueFromHex(length)); // Mind the stack order!!
program.stackPush(DataWord.valueFromHex(src));
program.stackPush(DataWord.valueFromHex(dst));

// Then
Program.OutOfGasException ex = Assertions.assertThrows(Program.OutOfGasException.class, () -> executeProgram(vm, program));
Expand All @@ -127,23 +127,33 @@ private static Stream<Arguments> provideParametersForMCOPYOutOfGasExceptionTest(
"e0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
};

String maxSingleByte = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // 2**256 - 1
String maxMinusOneSingleByte = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; // 2**256 - 2
String halfMaxSingleByte = "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // 2**255 - 1

return Stream.of(

// From an empty memory
Arguments.of(emptyMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(emptyMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(emptyMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(emptyMemory, 0, 0, Program.MAX_MEMORY + 1),
Arguments.of(emptyMemory, 0, 0, Program.MAX_MEMORY + 1),
Arguments.of(emptyMemory, 0, 0, Program.MAX_MEMORY + 1),
Arguments.of(emptyMemory, maxSingleByte, "00", "01"),
Arguments.of(emptyMemory, maxMinusOneSingleByte, "00", "01"),
Arguments.of(emptyMemory, halfMaxSingleByte, "00", "01"),
Arguments.of(emptyMemory, "00", maxSingleByte, "01"),
Arguments.of(emptyMemory, "00", maxMinusOneSingleByte, "01"),
Arguments.of(emptyMemory, "00", halfMaxSingleByte, "01"),
Arguments.of(emptyMemory, "00", "00", maxSingleByte),
Arguments.of(emptyMemory, "00", "00", maxMinusOneSingleByte),
Arguments.of(emptyMemory, "00", "00", halfMaxSingleByte),

// From existent memory
Arguments.of(existentMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(existentMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(existentMemory, Program.MAX_MEMORY, 0, 1),
Arguments.of(existentMemory, 0, 0, Program.MAX_MEMORY + 1),
Arguments.of(existentMemory, 0, 0, Program.MAX_MEMORY + 1),
Arguments.of(existentMemory, 0, 0, Program.MAX_MEMORY + 1)
Arguments.of(existentMemory, maxSingleByte, "00", "01"),
Arguments.of(existentMemory, maxMinusOneSingleByte, "00", "01"),
Arguments.of(existentMemory, halfMaxSingleByte, "00", "01"),
Arguments.of(existentMemory, "00", maxSingleByte, "01"),
Arguments.of(existentMemory, "00", maxMinusOneSingleByte, "01"),
Arguments.of(existentMemory, "00", halfMaxSingleByte, "01"),
Arguments.of(existentMemory, "00", "00", maxSingleByte),
Arguments.of(existentMemory, "00", "00", maxMinusOneSingleByte),
Arguments.of(existentMemory, "00", "00", halfMaxSingleByte)

);
}
Expand Down

0 comments on commit c7c2b2b

Please sign in to comment.