use of co.rsk.peg.performance.ExecutionStats in project rskj by rsksmart.
the class DeriveExtendedPublicKeyPerformanceTestCase method estimateDeriveExtendedPublicKey.
private ExecutionStats estimateDeriveExtendedPublicKey(int times, int pathLength, EnvironmentBuilder environmentBuilder) throws VMException {
String name = String.format("%s-%d", function.name, pathLength);
ExecutionStats stats = new ExecutionStats(name);
Random rnd = new Random();
byte[] chainCode = new byte[32];
NetworkParameters networkParameters = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
ABIEncoder abiEncoder = (int executionIndex) -> {
rnd.nextBytes(chainCode);
DeterministicKey key = HDKeyDerivation.createMasterPubKeyFromBytes(new ECKey().getPubKey(true), chainCode);
int[] pathParts = new int[pathLength];
for (int i = 0; i < pathLength; i++) {
pathParts[i] = rnd.nextInt(MAX_CHILD);
}
String path = String.join("/", Arrays.stream(pathParts).mapToObj(i -> String.format("%d", i)).collect(Collectors.toList()));
return function.encode(new Object[] { key.serializePubB58(networkParameters), path });
};
executeAndAverage(name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
Object[] decodedResult = function.decodeResult(result);
Assert.assertEquals(String.class, decodedResult[0].getClass());
String address = (String) decodedResult[0];
Assert.assertTrue(address.startsWith("xpub"));
});
return stats;
}
use of co.rsk.peg.performance.ExecutionStats in project rskj by rsksmart.
the class ToBase58CheckPerformanceTestCase method estimateToBase58Check.
private ExecutionStats estimateToBase58Check(int times, EnvironmentBuilder environmentBuilder) throws VMException {
String name = function.name;
ExecutionStats stats = new ExecutionStats(name);
Random rnd = new Random();
int[] versions = new int[] { // See https://en.bitcoin.it/wiki/Base58Check_encoding for details
0, 5, 111, 196 };
byte[] hash = new byte[20];
ABIEncoder abiEncoder = (int executionIndex) -> {
rnd.nextBytes(hash);
int version = versions[rnd.nextInt(versions.length)];
return function.encode(new Object[] { hash, version });
};
executeAndAverage(name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
Object[] decodedResult = function.decodeResult(result);
Assert.assertEquals(String.class, decodedResult[0].getClass());
String address = (String) decodedResult[0];
Assert.assertTrue(MIN_ADDRESS_LENGTH <= address.length());
Assert.assertTrue(MAX_ADDRESS_LENGTH >= address.length());
});
return stats;
}
use of co.rsk.peg.performance.ExecutionStats in project rskj by rsksmart.
the class ExtractPublicKeyFromExtendedPublicKeyPerformanceTestCase method estimateExtractPublicKeyFromExtendedPublicKey.
private ExecutionStats estimateExtractPublicKeyFromExtendedPublicKey(int times, EnvironmentBuilder environmentBuilder) throws VMException {
ExecutionStats stats = new ExecutionStats(function.name);
Random rnd = new Random();
byte[] chainCode = new byte[32];
NetworkParameters networkParameters = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
byte[] publicKey = new ECKey().getPubKey(true);
String expectedHexPublicKey = ByteUtil.toHexString(publicKey);
ABIEncoder abiEncoder = (int executionIndex) -> {
rnd.nextBytes(chainCode);
DeterministicKey key = HDKeyDerivation.createMasterPubKeyFromBytes(publicKey, chainCode);
return function.encode(new Object[] { key.serializePubB58(networkParameters) });
};
executeAndAverage(function.name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
Object[] decodedResult = function.decodeResult(result);
Assert.assertEquals(byte[].class, decodedResult[0].getClass());
String hexPublicKey = ByteUtil.toHexString((byte[]) decodedResult[0]);
Assert.assertEquals(expectedHexPublicKey, hexPublicKey);
});
return stats;
}
use of co.rsk.peg.performance.ExecutionStats in project rskj by rsksmart.
the class GetMultisigScriptHashPerformanceTestCase method estimateGetMultisigScriptHash.
private ExecutionStats estimateGetMultisigScriptHash(int times, int numberOfKeys, EnvironmentBuilder environmentBuilder) throws VMException {
String name = String.format("%s-%d", function.name, numberOfKeys);
ExecutionStats stats = new ExecutionStats(name);
Random rnd = new Random();
int minimumSignatures = rnd.nextInt(numberOfKeys) + 1;
byte[][] publicKeys = new byte[numberOfKeys][];
for (int i = 0; i < numberOfKeys; i++) {
publicKeys[i] = new ECKey().getPubKey(true);
}
String expectedHashHex = ByteUtil.toHexString(ScriptBuilder.createP2SHOutputScript(minimumSignatures, Arrays.stream(publicKeys).map(BtcECKey::fromPublicOnly).collect(Collectors.toList())).getPubKeyHash());
ABIEncoder abiEncoder = (int executionIndex) -> function.encode(new Object[] { minimumSignatures, publicKeys });
executeAndAverage(name, times, environmentBuilder, abiEncoder, Helper.getZeroValueTxBuilder(new ECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
Object[] decodedResult = function.decodeResult(result);
Assert.assertEquals(byte[].class, decodedResult[0].getClass());
String hexHash = ByteUtil.toHexString((byte[]) decodedResult[0]);
Assert.assertEquals(expectedHashHex, hexHash);
});
return stats;
}
use of co.rsk.peg.performance.ExecutionStats in project rskj by rsksmart.
the class GetCoinbasePerformanceTestCase method getCoinbase.
@Test
public void getCoinbase() throws IOException, VMException {
ExecutionStats stats = new ExecutionStats("getCoinbase");
EnvironmentBuilder environmentBuilder = (int executionIndex, TxBuilder txBuilder, int height) -> {
World world = buildWorld(6000, 500, 6);
BlockHeaderContract contract = new BlockHeaderContract(activationConfig, new RskAddress("0000000000000000000000000000000001000010"));
contract.init(txBuilder.build(executionIndex), world.getBlockChain().getBestBlock(), world.getRepository(), world.getBlockStore(), null, new LinkedList<>());
return EnvironmentBuilder.Environment.withContract(contract);
};
doGetCoinbase(environmentBuilder, stats, 4000);
BlockHeaderPerformanceTest.addStats(stats);
}
Aggregations