use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplLogsTest method getWeb3WithContractCreationWithoutEvents.
private Web3Impl getWeb3WithContractCreationWithoutEvents() {
World world = new World();
Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
Block genesis = world.getBlockByName("g00");
/* contract compiled in data attribute of tx
contract greeter {
address owner;
modifier onlyOwner { if (msg.sender != owner) throw; _ ; }
function greeter() public {
owner = msg.sender;
}
function greet(string param) onlyOwner constant returns (string) {
return param;
}
} */
Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(100000)).gasPrice(BigInteger.ONE).data(compiledGreeter).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
BlockChainImpl blockChain = world.getBlockChain();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
blockChain.tryToConnect(block1);
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
web3.personal_newAccountWithSeed("notDefault");
return web3;
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByBlockHashAndIndex.
@Test
public void getTransactionByBlockHashAndIndex() 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();
String blockHashString = block1.getHash().toHexString();
TransactionResultDTO tr = web3.eth_getTransactionByBlockHashAndIndex(blockHashString, "0x0");
Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
org.junit.Assert.assertEquals("0x" + blockHashString, tr.blockHash);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBalanceWithAccountAndBlockWithTransaction.
@Test
public void getBalanceWithAccountAndBlockWithTransaction() throws Exception {
World world = new World();
BlockChainImpl blockChain = world.getBlockChain();
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000000)).build();
Account acc2 = new AccountBuilder(world).name("acc2").build();
Block genesis = world.getBlockByName("g00");
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(10000)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
Web3Impl web3 = createWeb3(world, transactionPool, null);
web3.repository = world.getBlockChain().getRepository();
String accountAddress = Hex.toHexString(acc2.getAddress().getBytes());
String balanceString = "0x" + Hex.toHexString(BigInteger.valueOf(10000).toByteArray());
org.junit.Assert.assertEquals("0x0", web3.eth_getBalance(accountAddress, "0x0"));
org.junit.Assert.assertEquals(balanceString, web3.eth_getBalance(accountAddress, "0x1"));
org.junit.Assert.assertEquals(balanceString, web3.eth_getBalance(accountAddress, "pending"));
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByBlockNumberAndIndex.
@Test
public void getTransactionByBlockNumberAndIndex() 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();
String blockHashString = block1.getHash().toHexString();
TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x01", "0x0");
Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
org.junit.Assert.assertEquals("0x" + blockHashString, tr.blockHash);
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBalanceWithAccountAndLatestBlock.
@Test
public void getBalanceWithAccountAndLatestBlock() 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();
org.junit.Assert.assertEquals("0x" + Hex.toHexString(BigInteger.valueOf(10000).toByteArray()), web3.eth_getBalance(Hex.toHexString(acc1.getAddress().getBytes()), "latest"));
}
Aggregations