use of co.rsk.test.World in project rskj by rsksmart.
the class Web3ImplTest method getUnknownTransactionByBlockNumberAndIndex.
@Test
public void getUnknownTransactionByBlockNumberAndIndex() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x1", "0x0");
Assert.assertNull(tr);
}
use of co.rsk.test.World in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByHash.
@Test
public void getTransactionByHash() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
Account acc2 = new AccountBuilder().name("acc2").build();
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String hashString = tx.getHash().toHexString();
TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
String blockHashString = "0x" + block1.getHash();
org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
org.junit.Assert.assertEquals("0x00", tr.input);
org.junit.Assert.assertEquals("0x" + Hex.toHexString(tx.getReceiveAddress().getBytes()), tr.to);
}
use of co.rsk.test.World in project rskj by rsksmart.
the class Web3ImplTest method getBalanceWithAccountAndGenesisBlock.
@Test
public void getBalanceWithAccountAndGenesisBlock() throws Exception {
World world = new World();
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000)).build();
Web3Impl web3 = createWeb3(world);
web3.repository = world.getBlockChain().getRepository();
String accountAddress = Hex.toHexString(acc1.getAddress().getBytes());
String balanceString = "0x" + Hex.toHexString(BigInteger.valueOf(10000).toByteArray());
org.junit.Assert.assertEquals(balanceString, web3.eth_getBalance(accountAddress, "0x0"));
}
use of co.rsk.test.World in project rskj by rsksmart.
the class Web3ImplTest method getBlockByHashWithTransactionsHashAsResult.
@Test
public void getBlockByHashWithTransactionsHashAsResult() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(220000)).build();
Account acc2 = new AccountBuilder().name("acc2").build();
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(0)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
block1.setBitcoinMergedMiningHeader(new byte[] { 0x01 });
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String block1HashString = block1.getHashJsonString();
Web3.BlockResult bresult = web3.eth_getBlockByHash(block1HashString, false);
Assert.assertNotNull(bresult);
org.junit.Assert.assertEquals(block1HashString, bresult.hash);
org.junit.Assert.assertEquals(1, bresult.transactions.length);
org.junit.Assert.assertEquals(tx.getHash().toJsonString(), bresult.transactions[0]);
org.junit.Assert.assertEquals(0, bresult.uncles.length);
}
use of co.rsk.test.World in project rskj by rsksmart.
the class Web3ImplTest method getBlockByNumber.
@Test
public void getBlockByNumber() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).difficulty(10).parent(genesis).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
Block block1b = new BlockBuilder(world).difficulty(2).parent(genesis).build();
block1b.setBitcoinMergedMiningHeader(new byte[] { 0x01 });
Block block2b = new BlockBuilder(world).difficulty(11).parent(block1b).build();
block2b.setBitcoinMergedMiningHeader(new byte[] { 0x02 });
org.junit.Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2b));
Web3.BlockResult bresult = web3.eth_getBlockByNumber("0x1", false);
Assert.assertNotNull(bresult);
String blockHash = "0x" + block1b.getHash();
org.junit.Assert.assertEquals(blockHash, bresult.hash);
bresult = web3.eth_getBlockByNumber("0x2", true);
Assert.assertNotNull(bresult);
blockHash = "0x" + block2b.getHash();
org.junit.Assert.assertEquals(blockHash, bresult.hash);
}
Aggregations