Skip to content

Commit

Permalink
Merge pull request #1482 from ajlopez/storagenotnull
Browse files Browse the repository at this point in the history
getStorageAt from empty cell now returns 0x0 instead of null
  • Loading branch information
ajlopezrsk authored Apr 14, 2021
2 parents be45938 + d005ff6 commit a025b44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,15 @@ public String eth_getStorageAt(String address, String storageIdx, String blockId

try {
RskAddress addr = new RskAddress(address);

AccountInformationProvider accountInformationProvider =
web3InformationRetriever.getInformationProvider(blockId);

DataWord sv = accountInformationProvider
.getStorageValue(addr, DataWord.valueOf(stringHexToByteArray(storageIdx)));

if (sv == null) {
s = null;
s = "0x0";
} else {
s = toUnformattedJsonHex(sv.getData());
}
Expand Down
19 changes: 19 additions & 0 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ public void eth_getStorageAt() {
result);
}


@Test
public void eth_getStorageAtEmptyCell() {
String id = "id";
String addr = "0x0011223344556677880011223344556677889900";
RskAddress expectedAddress = new RskAddress(addr);
String storageIdx = "0x01";
DataWord expectedIdx = DataWord.valueOf(stringHexToByteArray(storageIdx));

AccountInformationProvider aip = mock(AccountInformationProvider.class);
when(retriever.getInformationProvider(eq(id))).thenReturn(aip);
when(aip.getStorageValue(eq(expectedAddress), eq(expectedIdx)))
.thenReturn(null);

String result = target.eth_getStorageAt(addr, storageIdx, id);
assertEquals("0x0",
result);
}

@Test
public void eth_getBlockTransactionCountByNumber_blockNotFound() {
String id = "id";
Expand Down

0 comments on commit a025b44

Please # to comment.