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()));
}
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);
}
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()));
}
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;
}
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);
}
Aggregations