Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
FilterIdGenerator fixes (#1544)
Browse files Browse the repository at this point in the history
Don't create a new SecureRandom instance every time a filter ID is generated.
Fix intermittency in FilterIdGeneratorTest - quantity values omit leading 0s.
  • Loading branch information
ajsutton authored Jun 10, 2019
1 parent 2b9451d commit e054095
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import tech.pegasys.pantheon.crypto.SecureRandomProvider;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.Quantity;

import java.security.SecureRandom;

public class FilterIdGenerator {

private final SecureRandom secureRandom = SecureRandomProvider.createSecureRandom();

public String nextId() {
final byte[] randomBytes = new byte[16];
SecureRandomProvider.createSecureRandom().nextBytes(randomBytes);
secureRandom.nextBytes(randomBytes);
return Quantity.create(randomBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import static org.junit.Assert.assertEquals;

import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

import org.junit.Test;

Expand All @@ -24,7 +24,7 @@ public class FilterIdGeneratorTest {
public void idIsAHexString() {
final FilterIdGenerator generator = new FilterIdGenerator();
final String s = generator.nextId();
final BytesValue bytesValue = BytesValue.fromHexString(s);
assertEquals(s, bytesValue.toString());
final UInt256 bytesValue = UInt256.fromHexString(s);
assertEquals(s, bytesValue.toShortHexString());
}
}

0 comments on commit e054095

Please sign in to comment.