Search in sources :

Example 21 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class AddressesTopicsFilterTest method noMatchEmptyBloomWithFilterWithAccount.

@Test
public void noMatchEmptyBloomWithFilterWithAccount() {
    Account account = new AccountBuilder().name("account").build();
    RskAddress address = account.getAddress();
    AddressesTopicsFilter filter = new AddressesTopicsFilter(new RskAddress[] { address }, null);
    Assert.assertFalse(filter.matchBloom(new Bloom()));
}
Also used : Account(org.ethereum.core.Account) Bloom(org.ethereum.core.Bloom) RskAddress(co.rsk.core.RskAddress) AccountBuilder(co.rsk.test.builders.AccountBuilder) Test(org.junit.Test)

Example 22 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class BlockchainVMTest method testSEND_1.

@Test
public void testSEND_1() {
    NewBlockChainInfo binfo = createNewBlockchain();
    Blockchain blockchain = binfo.blockchain;
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock(), null, binfo.repository.getRoot());
    List<Transaction> txs = new ArrayList<>();
    Coin transferAmount = Coin.valueOf(100L);
    // Add a single transaction paying to a new address
    byte[] dstAddress = randomAddress();
    BigInteger transactionGasLimit = new BigInteger("21000");
    Coin transactionGasPrice = Coin.valueOf(1);
    Transaction t = new Transaction(ZERO_BYTE_ARRAY, transactionGasPrice.getBytes(), transactionGasLimit.toByteArray(), dstAddress, transferAmount.getBytes(), null, new RskSystemProperties().getBlockchainConfig().getCommonConstants().getChainId());
    t.sign(binfo.faucetKey.getPrivKeyBytes());
    txs.add(t);
    Block block2 = blockGenerator.createChildBlock(block1, txs, binfo.repository.getRoot());
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
    MinerHelper mh = new MinerHelper(binfo.repository, binfo.blockchain);
    mh.completeBlock(block2, block1);
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
    Assert.assertEquals(blockchain.getBestBlock(), block2);
    Assert.assertEquals(2, block2.getNumber());
    Coin srcAmount = faucetAmount.subtract(transferAmount);
    srcAmount = srcAmount.subtract(transactionGasPrice.multiply(transactionGasLimit));
    Assert.assertEquals(binfo.repository.getBalance(new RskAddress(binfo.faucetKey.getAddress())), srcAmount);
    Assert.assertEquals(binfo.repository.getBalance(new RskAddress(dstAddress)), transferAmount);
}
Also used : ArrayList(java.util.ArrayList) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 23 with RskAddress

use of co.rsk.core.RskAddress in project rskj by rsksmart.

the class ABITest method testSimple2.

@Test
public void testSimple2() {
    logger.info("\n{}", funcJson2);
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson2);
    Transaction ctx = CallTransaction.createCallTransaction(config, 1, 1_000_000_000, 1_000_000_000, new RskAddress("86e0497e32a8e1d79fe38ab87dc80140df5470d9"), 0, function);
    ctx.sign(Keccak256Helper.keccak256("974f963ee4571e86e5f9bc3b493e453db9c15e5bd19829a4ef9a790de0da0015".getBytes()));
    Assert.assertEquals("91888f2e", Hex.toHexString(ctx.getData()));
}
Also used : RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test)

Example 24 with RskAddress

use of co.rsk.core.RskAddress 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 25 with RskAddress

use of co.rsk.core.RskAddress 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)

Aggregations

RskAddress (co.rsk.core.RskAddress)174 Test (org.junit.Test)102 Repository (org.ethereum.core.Repository)60 BigInteger (java.math.BigInteger)47 Coin (co.rsk.core.Coin)38 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 DataWord (org.ethereum.vm.DataWord)27 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)24 RepositoryImpl (co.rsk.db.RepositoryImpl)16 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)15 Transaction (org.ethereum.core.Transaction)15 Program (org.ethereum.vm.program.Program)15 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 AccountState (org.ethereum.core.AccountState)12 HashMapDB (org.ethereum.datasource.HashMapDB)11 ArrayList (java.util.ArrayList)10 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)10 BridgeConstants (co.rsk.config.BridgeConstants)8 RskSystemProperties (co.rsk.config.RskSystemProperties)8 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)8