use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByHashNotInMainBlockchain.
@Test
public void getTransactionByHashNotInMainBlockchain() 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).difficulty(10).parent(genesis).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
Block block1b = new BlockBuilder(world).difficulty(block1.getDifficulty().asBigInteger().longValue() - 1).parent(genesis).build();
Block block2b = new BlockBuilder(world).difficulty(block1.getDifficulty().asBigInteger().longValue() + 1).parent(block1b).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2b));
String hashString = tx.getHash().toHexString();
TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
Assert.assertNull(tr);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceiptNotInMainBlockchain.
@Test
public void getTransactionReceiptNotInMainBlockchain() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
Web3Impl web3 = createWeb3(world, receiptStore);
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).difficulty(3l).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
Block block1b = new BlockBuilder(world).parent(genesis).difficulty(block1.getDifficulty().asBigInteger().longValue() - 1).build();
Block block2b = new BlockBuilder(world).difficulty(2).parent(block1b).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2b));
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
Assert.assertNull(tr);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionCount.
@Test
public void getTransactionCount() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
web3.repository = world.getRepository();
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(100000000)).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 accountAddress = Hex.toHexString(acc1.getAddress().getBytes());
String count = web3.eth_getTransactionCount(accountAddress, "0x1");
Assert.assertNotNull(count);
org.junit.Assert.assertEquals("0x1", count);
count = web3.eth_getTransactionCount(accountAddress, "0x0");
Assert.assertNotNull(count);
org.junit.Assert.assertEquals("0x0", count);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getCodeBlockDoesNotExist.
@Test
public void getCodeBlockDoesNotExist() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
web3.repository = world.getRepository();
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(100000000)).build();
byte[] code = new byte[] { 0x01, 0x02, 0x03 };
world.getRepository().saveCode(acc1.getAddress(), code);
String accountAddress = Hex.toHexString(acc1.getAddress().getBytes());
String resultCode = web3.eth_getCode(accountAddress, "0x100");
org.junit.Assert.assertNull(resultCode);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBalanceWithAccount.
@Test
public void getBalanceWithAccount() throws Exception {
World world = new World();
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000)).build();
Web3Impl web3 = createWeb3();
web3.repository = world.getBlockChain().getRepository();
org.junit.Assert.assertEquals("0x" + Hex.toHexString(BigInteger.valueOf(10000).toByteArray()), web3.eth_getBalance(Hex.toHexString(acc1.getAddress().getBytes())));
}
Aggregations