Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner committed Oct 23, 2023
1 parent 8513d79 commit 48f5c30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ public void shouldSetMemoryWhenLengthGreaterThanSourceLength() {
assertThat(memory.getWord(64)).isEqualTo(Bytes32.ZERO);
}

@Test
public void shouldNotIncreaseActiveWordsIfShadowRead() {
final Bytes value = Bytes.concatenate(WORD1, WORD2);
memory.setBytes(0, value.size(), value);
final int initialActiveWords = memory.getActiveWords();

assertThat(memory.getBytes(64, Bytes32.SIZE, true)).isEqualTo((Bytes32.ZERO));
assertThat(memory.getActiveWords()).isEqualTo(initialActiveWords);

assertThat(memory.getBytes(32, Bytes32.SIZE)).isEqualTo((WORD2));
assertThat(memory.getActiveWords()).isEqualTo(initialActiveWords);

assertThat(memory.getBytes(64, Bytes32.SIZE)).isEqualTo((Bytes32.ZERO));
assertThat(memory.getActiveWords()).isEqualTo(initialActiveWords + 1);

assertThat(memory.getBytes(64, Bytes32.SIZE, false)).isEqualTo((Bytes32.ZERO));
assertThat(memory.getActiveWords()).isEqualTo(initialActiveWords + 1);
}

@Test
public void shouldClearMemoryAfterSourceDataWhenLengthGreaterThanSourceLength() {
memory.setWord(64, WORD3);
Expand Down
4 changes: 3 additions & 1 deletion evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Arrays;

import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes;
Expand Down Expand Up @@ -179,7 +180,8 @@ int getActiveBytes() {
*
* @return The current number of active words stored in memory.
*/
int getActiveWords() {
@VisibleForTesting
public int getActiveWords() {
return activeWords;
}

Expand Down

0 comments on commit 48f5c30

Please sign in to comment.