diff --git a/rskj-core/src/test/java/co/rsk/vm/VMExecutionTest.java b/rskj-core/src/test/java/co/rsk/vm/VMExecutionTest.java index 6f2d5b5655..224f245126 100644 --- a/rskj-core/src/test/java/co/rsk/vm/VMExecutionTest.java +++ b/rskj-core/src/test/java/co/rsk/vm/VMExecutionTest.java @@ -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())); @@ -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); } @@ -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()); + } + } diff --git a/rskj-core/src/test/java/org/ethereum/config/blockchain/upgrades/ActivationConfigTest.java b/rskj-core/src/test/java/org/ethereum/config/blockchain/upgrades/ActivationConfigTest.java index d94e90569c..09f2377c27 100644 --- a/rskj-core/src/test/java/org/ethereum/config/blockchain/upgrades/ActivationConfigTest.java +++ b/rskj-core/src/test/java/org/ethereum/config/blockchain/upgrades/ActivationConfigTest.java @@ -126,6 +126,7 @@ class ActivationConfigTest { " rskip428: lovell700", " rskip434: arrowhead631", " rskip438: lovell700", + " rskip445: lovell700", "}" ));