use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getUnknownTransactionByBlockHashAndIndex.
@Test
public void getUnknownTransactionByBlockHashAndIndex() 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));
String blockHashString = block1.getHash().toString();
TransactionResultDTO tr = web3.eth_getTransactionByBlockHashAndIndex(blockHashString, "0x0");
Assert.assertNull(tr);
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBlockByHashWithFullTransactionsAsResult.
@Test
public void getBlockByHashWithFullTransactionsAsResult() 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, true);
Assert.assertNotNull(bresult);
org.junit.Assert.assertEquals(block1HashString, bresult.hash);
org.junit.Assert.assertEquals(1, bresult.transactions.length);
org.junit.Assert.assertEquals(block1HashString, ((TransactionResultDTO) bresult.transactions[0]).blockHash);
org.junit.Assert.assertEquals(0, bresult.uncles.length);
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method callFromDefaultAddressInWallet.
@Test
public void callFromDefaultAddressInWallet() throws Exception {
World world = new World();
Account acc1 = new AccountBuilder(world).name("default").balance(Coin.valueOf(10000000)).build();
Block genesis = world.getBlockByName("g00");
TestContract greeter = TestContract.greeter();
Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(100000)).gasPrice(BigInteger.ONE).data(greeter.runtimeBytecode).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
world.getBlockChain().tryToConnect(block1);
Web3Impl web3 = createWeb3Mocked(world);
Web3.CallArguments argsForCall = new Web3.CallArguments();
argsForCall.to = TypeConverter.toJsonHex(tx.getContractAddress().getBytes());
argsForCall.data = TypeConverter.toJsonHex(greeter.functions.get("greet").encodeSignature());
String result = web3.eth_call(argsForCall, "latest");
org.junit.Assert.assertEquals("0x0000000000000000000000000000000000000000000000000000000064617665", result);
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBlockByNumberRetrieveEarliestBlock.
@Test
public void getBlockByNumberRetrieveEarliestBlock() 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));
Web3.BlockResult blockResult = web3.eth_getBlockByNumber("earliest", false);
Assert.assertNotNull(blockResult);
String blockHash = genesis.getHashJsonString();
org.junit.Assert.assertEquals(blockHash, blockResult.hash);
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBalanceWithAccountAndBlock.
@Test
public void getBalanceWithAccountAndBlock() throws Exception {
World world = new World();
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000)).build();
Block genesis = world.getBlockByName("g00");
Block block1 = new BlockBuilder().parent(genesis).build();
world.getBlockChain().tryToConnect(block1);
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, "0x1"));
}
Aggregations