Search in sources :

Example 16 with RepositoryImpl

use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.

the class SamplePrecompiledContractTest method samplePrecompiledContractIncrementResultOk.

@Test
public void samplePrecompiledContractIncrementResultOk() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[], \n" + "    'name':'IncrementResult', \n" + "   'outputs':[], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] data = function.encode();
    Repository repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    contract.init(null, null, track, null, null, new ArrayList<LogInfo>());
    contract.execute(data);
    track.commit();
    int result = this.GetResult(repository);
    assertEquals(1, result);
}
Also used : Repository(org.ethereum.core.Repository) LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 17 with RepositoryImpl

use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.

the class SamplePrecompiledContractTest method samplePrecompiledContractMethodDoesNotExist.

@Test
public void samplePrecompiledContractMethodDoesNotExist() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[{'name':'param0','type':'int'}, \n" + "               {'name':'param1','type':'bytes'}, \n" + "               {'name':'param2','type':'int'}], \n" + "    'name':'UnexistentMethod', \n" + "   'outputs':[{'name':'output0','type':'int'}], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] bytes = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
    byte[] data = function.encode(111, bytes, 222);
    contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
    byte[] result = contract.execute(data);
    assertNull(result);
}
Also used : LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 18 with RepositoryImpl

use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis) {
    RskSystemProperties config = new RskSystemProperties();
    config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {

        @Override
        public BlockDifficulty getMinimumDifficulty() {
            return new BlockDifficulty(BigInteger.ONE);
        }
    }));
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
    EthereumListenerAdapter listener = new EthereumListenerAdapter();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setTransactionPool(transactionPool);
    Repository track = repository.startTracking();
    for (RskAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) AdminInfo(org.ethereum.manager.AdminInfo) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties) ReceiptStore(org.ethereum.db.ReceiptStore) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig)

Example 19 with RepositoryImpl

use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.

the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.

@Test
public void testLoadBlockchainEmptyBlockchain() throws IOException {
    String jsonFile = "blockchain_loader_genesis.json";
    RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
    Constants constants = Mockito.mock(Constants.class);
    Mockito.when(constants.getInitialNonce()).thenReturn(BigInteger.ZERO);
    BlockchainNetConfig blockchainNetConfig = Mockito.mock(BlockchainNetConfig.class);
    Mockito.when(blockchainNetConfig.getCommonConstants()).thenReturn(constants);
    Mockito.when(systemProperties.databaseDir()).thenReturn(new RskSystemProperties().databaseDir());
    Mockito.when(systemProperties.getBlockchainConfig()).thenReturn(blockchainNetConfig);
    Mockito.when(systemProperties.genesisInfo()).thenReturn(jsonFile);
    BlockStore blockStore = Mockito.mock(BlockStore.class);
    Mockito.when(blockStore.getBestBlock()).thenReturn(null);
    EthereumListener ethereumListener = Mockito.mock(EthereumListener.class);
    Repository repository = new RepositoryImpl(systemProperties, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
    ;
    BlockChainLoader blockChainLoader = new BlockChainLoader(systemProperties, repository, blockStore, null, null, ethereumListener, null, null);
    blockChainLoader.loadBlockchain();
    Assert.assertEquals(5, repository.getAccountsKeys().size());
    Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
    Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
    Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
    Assert.assertEquals(BigInteger.ZERO, repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
    Assert.assertEquals(Coin.valueOf(10), repository.getBalance(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
    Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
    Assert.assertEquals(DataWord.ONE, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ZERO));
    Assert.assertEquals(new DataWord(3), repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ONE));
    Assert.assertEquals(274, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).getCode().length);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) Constants(org.ethereum.config.Constants) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) BlockchainNetConfig(org.ethereum.config.BlockchainNetConfig) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 20 with RepositoryImpl

use of co.rsk.db.RepositoryImpl in project rskj by rsksmart.

the class RemascStorageProviderTest method setAndGetBrokenSelectionRule.

@Test
public void setAndGetBrokenSelectionRule() {
    RskAddress accountAddress = randomAddress();
    Repository repository = new RepositoryImpl(config);
    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
    provider.setBrokenSelectionRule(Boolean.TRUE);
    Assert.assertEquals(Boolean.TRUE, provider.getBrokenSelectionRule());
}
Also used : Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Aggregations

RepositoryImpl (co.rsk.db.RepositoryImpl)62 Test (org.junit.Test)54 Repository (org.ethereum.core.Repository)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RskAddress (co.rsk.core.RskAddress)19 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)16 HashMapDB (org.ethereum.datasource.HashMapDB)15 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)13 org.ethereum.core (org.ethereum.core)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)12 LogInfo (org.ethereum.vm.LogInfo)12 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)11 BridgeConstants (co.rsk.config.BridgeConstants)10 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)10 DataWord (org.ethereum.vm.DataWord)9 ArrayList (java.util.ArrayList)8 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)7 ECKey (org.ethereum.crypto.ECKey)7 Keccak256 (co.rsk.crypto.Keccak256)6 SimpleBlockChain (co.rsk.peg.simples.SimpleBlockChain)6