Skip to content

Commit

Permalink
Adding mcopy activation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Dec 9, 2024
1 parent 17b719f commit de5d977
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions rskj-core/src/test/java/co/rsk/vm/VMExecutionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,10 @@ private Program executeCodeWithActivationConfig(String code, int nsteps, Activat
return executeCodeWithActivationConfig(compiler.compile(code), nsteps, activations);
}

private Program executeCodeWithActivationConfig(String code, DataWord[] stack, int nsteps, ActivationConfig.ForBlock activations) {
return executeCodeWithActivationConfig(compiler.compile(code), stack, nsteps, activations);
}

private Program executeCodeWithActivationConfig(byte[] code, int nsteps, ActivationConfig.ForBlock activations) {
VM vm = new VM(vmConfig, precompiledContracts);
Program program = new Program(vmConfig, precompiledContracts, blockFactory, activations, code, invoke,null, new HashSet<>(), new BlockTxSignatureCache(new ReceivedTxSignatureCache()));
Expand All @@ -881,6 +885,21 @@ private Program executeCodeWithActivationConfig(byte[] code, int nsteps, Activat
return program;
}

private Program executeCodeWithActivationConfig(byte[] code, DataWord[] stack, int nsteps, ActivationConfig.ForBlock activations) {
VM vm = new VM(vmConfig, precompiledContracts);
Program program = new Program(vmConfig, precompiledContracts, blockFactory, activations, code, invoke,null, new HashSet<>(), new BlockTxSignatureCache(new ReceivedTxSignatureCache()));

for (DataWord element : stack) {
program.stackPush(element);
}

for (int k = 0; k < nsteps; k++) {
vm.step(program);
}

return program;
}

private Program playCodeWithActivationConfig(String code, ActivationConfig.ForBlock activations) {
return playCodeWithActivationConfig(compiler.compile(code), activations);
}
Expand Down Expand Up @@ -947,4 +966,31 @@ private void executeBASEFEE(ActivationConfig.ForBlock activations) {
// See ProgramInvokeMockImpl.getMinimumGasPrice()
Assertions.assertEquals(DataWord.valueFromHex("000000000000000000000000000000000000000000000000000003104e60a000"), stack.peek());
}

@Test
void testMCOPY_WhenActive_ExecutesAsExpected() {
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
when(activations.isActive(RSKIP445)).thenReturn(true);

executeMCOPY(activations);
}

@Test
void testMCOPY_WhenInactive_ExecutesAsExpected() {
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
when(activations.isActive(RSKIP445)).thenReturn(false);

Assertions.assertThrows(Program.IllegalOperationException.class, () -> {
executeMCOPY(activations);
});
}

private void executeMCOPY(ActivationConfig.ForBlock activations) {
DataWord[] stackValues = {DataWord.ZERO, DataWord.ZERO, DataWord.ZERO};
Program program = executeCodeWithActivationConfig("MCOPY", stackValues, 1, activations);
Stack stack = program.getStack();

Assertions.assertEquals(0, stack.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ActivationConfigTest {
" rskip428: lovell700",
" rskip434: arrowhead631",
" rskip438: lovell700",
" rskip445: lovell700",
"}"
));

Expand Down

0 comments on commit de5d977

Please sign in to comment.