Search in sources :

Example 1 with BtcECKey

use of co.rsk.bitcoinj.core.BtcECKey in project rskj by rsksmart.

the class FederationTest method hasMemberWithRskAddress.

@Test
public void hasMemberWithRskAddress() {
    for (int i = 0; i < federation.getPublicKeys().size(); i++) {
        Assert.assertTrue(federation.hasMemberWithRskAddress(rskAddresses.get(i)));
    }
    BtcECKey nonFederateKey = BtcECKey.fromPrivate(BigInteger.valueOf(1234));
    byte[] nonFederateRskAddress = getRskAddressFromBtcKey(nonFederateKey);
    Assert.assertFalse(federation.hasMemberWithRskAddress(nonFederateRskAddress));
}
Also used : BtcECKey(co.rsk.bitcoinj.core.BtcECKey) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with BtcECKey

use of co.rsk.bitcoinj.core.BtcECKey in project rskj by rsksmart.

the class ActiveFederationTest method buildInitializer.

private BridgeStorageProviderInitializer buildInitializer(boolean genesis) {
    final int minFederators = 10;
    final int maxFederators = 16;
    return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
        if (!genesis) {
            int numFederators = Helper.randomInRange(minFederators, maxFederators);
            List<BtcECKey> federatorKeys = new ArrayList<>();
            for (int i = 0; i < numFederators; i++) {
                federatorKeys.add(new BtcECKey());
            }
            federation = new Federation(federatorKeys, Instant.ofEpochMilli(new Random().nextLong()), Helper.randomInRange(1, 10), networkParameters);
            provider.setNewFederation(federation);
        } else {
            federation = bridgeConstants.getGenesisFederation();
        }
    };
}
Also used : Repository(org.ethereum.core.Repository) Random(java.util.Random) Federation(co.rsk.peg.Federation) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) ArrayList(java.util.ArrayList) List(java.util.List) BtcECKey(co.rsk.bitcoinj.core.BtcECKey)

Example 3 with BtcECKey

use of co.rsk.bitcoinj.core.BtcECKey in project rskj by rsksmart.

the class ReleaseBtcTest method releaseBtc.

@Test
public void releaseBtc() throws IOException {
    int minCentsBtc = 5;
    int maxCentsBtc = 100;
    final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
    BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
        ReleaseRequestQueue queue;
        try {
            queue = provider.getReleaseRequestQueue();
        } catch (Exception e) {
            throw new RuntimeException("Unable to gather release request queue");
        }
        for (int i = 0; i < Helper.randomInRange(10, 100); i++) {
            Coin value = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc));
            queue.add(new BtcECKey().toAddress(parameters), value);
        }
    };
    final byte[] releaseBtcEncoded = Bridge.RELEASE_BTC.encode();
    ABIEncoder abiEncoder = (int executionIndex) -> releaseBtcEncoded;
    TxBuilder txBuilder = (int executionIndex) -> {
        long satoshis = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc)).getValue();
        BigInteger weis = Denomination.satoshisToWeis(BigInteger.valueOf(satoshis));
        ECKey sender = new ECKey();
        return Helper.buildSendValueTx(sender, weis);
    };
    ExecutionStats stats = new ExecutionStats("releaseBtc");
    executeAndAverage("releaseBtc", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats);
    BridgePerformanceTest.addStats(stats);
}
Also used : NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ECKey(org.ethereum.crypto.ECKey) ReleaseRequestQueue(co.rsk.peg.ReleaseRequestQueue) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) IOException(java.io.IOException) Coin(co.rsk.bitcoinj.core.Coin) Repository(org.ethereum.core.Repository) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 4 with BtcECKey

use of co.rsk.bitcoinj.core.BtcECKey in project rskj by rsksmart.

the class RetiringFederationTest method buildInitializer.

private BridgeStorageProviderInitializer buildInitializer(boolean present) {
    final int minFederators = 10;
    final int maxFederators = 16;
    return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
        if (present) {
            int numFederators = Helper.randomInRange(minFederators, maxFederators);
            List<BtcECKey> federatorKeys = new ArrayList<>();
            for (int i = 0; i < numFederators; i++) {
                federatorKeys.add(new BtcECKey());
            }
            retiringFederation = new Federation(federatorKeys, Instant.ofEpochMilli(new Random().nextLong()), Helper.randomInRange(1, 10), networkParameters);
            provider.setNewFederation(bridgeConstants.getGenesisFederation());
            provider.setOldFederation(retiringFederation);
        } else {
            retiringFederation = null;
        }
    };
}
Also used : Repository(org.ethereum.core.Repository) Random(java.util.Random) Federation(co.rsk.peg.Federation) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) ArrayList(java.util.ArrayList) List(java.util.List) BtcECKey(co.rsk.bitcoinj.core.BtcECKey)

Aggregations

BtcECKey (co.rsk.bitcoinj.core.BtcECKey)4 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)3 Repository (org.ethereum.core.Repository)3 Federation (co.rsk.peg.Federation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Random (java.util.Random)2 Test (org.junit.Test)2 Coin (co.rsk.bitcoinj.core.Coin)1 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)1 ReleaseRequestQueue (co.rsk.peg.ReleaseRequestQueue)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 ECKey (org.ethereum.crypto.ECKey)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1