Search in sources :

Example 6 with EthereumImpl

use of org.ethereum.facade.EthereumImpl in project rskj by rsksmart.

the class MinerServerTest method submitBitcoinBlockTransactionsWhenBlockIsEmpty.

@Test
public void submitBitcoinBlockTransactionsWhenBlockIsEmpty() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    Mockito.when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), blockchain.getBlockStore(), blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlockWithOnlyCoinbase(work);
        findNonce(work, bitcoinMergedMiningBlock);
        // noinspection ConstantConditions
        BtcTransaction coinbase = bitcoinMergedMiningBlock.getTransactions().get(0);
        SubmitBlockResult result = minerServer.submitBitcoinBlockTransactions(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock, coinbase, Collections.singletonList(coinbase.getHashAsString()));
        Assert.assertEquals("OK", result.getStatus());
        Assert.assertNotNull(result.getBlockInfo());
        Assert.assertEquals("0x1", result.getBlockInfo().getBlockIncludedHeight());
        Assert.assertEquals("0x494d504f525445445f42455354", result.getBlockInfo().getBlockImportedResult());
        Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 7 with EthereumImpl

use of org.ethereum.facade.EthereumImpl in project rskj by rsksmart.

the class MinerServerTest method workWithNoTransactionsZeroFees.

@Test
public void workWithNoTransactionsZeroFees() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    minerServer.start();
    try {
        MinerWork work = minerServer.getWork();
        assertEquals("0", work.getFeesPaidToMiner());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 8 with EthereumImpl

use of org.ethereum.facade.EthereumImpl in project rskj by rsksmart.

the class MinerServerTest method submitBitcoinBlock.

@Test
public void submitBitcoinBlock() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    Mockito.when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), blockchain.getBlockStore(), blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlockWithOnlyCoinbase(work);
        findNonce(work, bitcoinMergedMiningBlock);
        SubmitBlockResult result = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
        Assert.assertEquals("OK", result.getStatus());
        Assert.assertNotNull(result.getBlockInfo());
        Assert.assertEquals("0x1", result.getBlockInfo().getBlockIncludedHeight());
        Assert.assertEquals("0x494d504f525445445f42455354", result.getBlockInfo().getBlockImportedResult());
        Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 9 with EthereumImpl

use of org.ethereum.facade.EthereumImpl in project rskj by rsksmart.

the class MinerServerTest method initialWorkTurnsNotifyFlagOn.

@Test
public void initialWorkTurnsNotifyFlagOn() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        assertEquals(true, work.getNotify());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 10 with EthereumImpl

use of org.ethereum.facade.EthereumImpl in project rskj by rsksmart.

the class MinerServerTest method secondWorkWithNoChangesTurnsNotifyFlagOff.

@Test
public void secondWorkWithNoChangesTurnsNotifyFlagOff() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    minerServer.start();
    try {
        MinerWork work = minerServer.getWork();
        assertEquals(true, work.getNotify());
        work = minerServer.getWork();
        assertEquals(false, work.getNotify());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Aggregations

ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)14 EthereumImpl (org.ethereum.facade.EthereumImpl)14 Test (org.junit.Test)14 BlockUnclesValidationRule (co.rsk.validators.BlockUnclesValidationRule)11 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)3 BlockDifficulty (co.rsk.core.BlockDifficulty)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 World (co.rsk.test.World)2 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)2 Genesis (org.ethereum.core.Genesis)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 Keccak256 (co.rsk.crypto.Keccak256)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 File (java.io.File)1 IOException (java.io.IOException)1 BlockchainNetConfig (org.ethereum.config.BlockchainNetConfig)1 Constants (org.ethereum.config.Constants)1 TransactionPool (org.ethereum.core.TransactionPool)1 ECKey (org.ethereum.crypto.ECKey)1