Skip to content

Commit

Permalink
Merge pull request #2078 from rsksmart/fix-eth-filter-methods
Browse files Browse the repository at this point in the history
Add filterNotFound exception to RskJsonRpcRequestException class
  • Loading branch information
Vovchyk authored Aug 30, 2023
2 parents e5b5f18 + d1546a4 commit 4d8884f
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 66 deletions.
3 changes: 2 additions & 1 deletion rskj-core/src/main/java/org/ethereum/rpc/FilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.ethereum.rpc;

import static org.ethereum.rpc.exception.RskJsonRpcRequestException.filterNotFound;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Object[] getFilterEvents(int id, boolean newevents) {
Filter filter = installedFilters.get(id);

if (filter == null) {
return null;
throw filterNotFound("filter not found");
}

if (newevents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public static RskJsonRpcRequestException blockNotFound(String message) {
public static RskJsonRpcRequestException stateNotFound(String message) {
return new RskJsonRpcRequestException(-32600, message);
}

public static RskJsonRpcRequestException filterNotFound(String message) {
return new RskJsonRpcRequestException(-32000, message);
}
}
21 changes: 21 additions & 0 deletions rskj-core/src/test/java/org/ethereum/rpc/FilterManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.ethereum.rpc;

import org.ethereum.facade.Ethereum;
import org.ethereum.rpc.exception.RskJsonRpcRequestException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class FilterManagerTest {

@Test
void whenGetFilterEvent_throwFilterNotFoundException() {
Ethereum ethMock = Web3Mocks.getMockEthereum();
FilterManager filterManager = new FilterManager(ethMock);

Assertions.assertThrowsExactly(
RskJsonRpcRequestException.class,
() -> filterManager.getFilterEvents(1, false),
"filter not found"
);
}
}
Loading

0 comments on commit 4d8884f

Please sign in to comment.