Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarev committed Nov 21, 2023
1 parent 20f89b5 commit a574096
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 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 @@ -901,6 +901,7 @@ private void executePush0(ActivationConfig.ForBlock activations){
Assertions.assertEquals(1, stack.size());
Assertions.assertEquals(DataWord.valueFromHex("0000000000000000000000000000000000000000000000000000000000000000"), stack.peek());
}

@Test
void testPUSH0Activation() {
ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class);
Expand All @@ -917,6 +918,33 @@ void testPUSH0NoActivation() {
Assertions.assertThrows(Program.IllegalOperationException.class, () -> {
executePush0(activations);
});
}

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

executeBASEFEE(activations);
}

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

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

private void executeBASEFEE(ActivationConfig.ForBlock activations) {
Program program = executeCodeWithActivationConfig("BASEFEE", 1, activations);
Stack stack = program.getStack();

Assertions.assertEquals(1, stack.size());

// See ProgramInvokeMockImpl.getMinimumGasPrice()
Assertions.assertEquals(DataWord.valueFromHex("000000000000000000000000000000000000000000000000000003104e60a000"), stack.peek());
}
}
14 changes: 14 additions & 0 deletions rskj-core/src/test/java/org/ethereum/vm/VMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,20 @@ void testScriptVersion3() {
}
}

@Test
void testBASEFEE() {
// Given
program = getProgram(compile("BASEFEE"));
when(program.getActivations().isActive(ConsensusRule.RSKIP412)).thenReturn(true);

// When
program.fullTrace();
vm.step(program);

// Then (See ProgramInvokeMockImpl.getMinimumGasPrice())
assertEquals("000000000000000000000000000000000000000000000000000003104e60a000", ByteUtil.toHexString(program.getStack().peek().getData()));
}

private VM getSubject() {
return new VM(vmConfig, precompiledContracts);
}
Expand Down

0 comments on commit a574096

Please sign in to comment.