use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplLogsTest method getWeb3WithContractCall.
private Web3Impl getWeb3WithContractCall(World world) {
Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
// acc1 Account created address should be 661b05ca9eb621164906671efd2731ce0d7dd8b4
Block genesis = world.getBlockByName("g00");
Transaction tx;
tx = getContractTransaction(acc1);
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
BlockChainImpl blockChain = world.getBlockChain();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
byte[] contractAddress = tx.getContractAddress().getBytes();
// Now create a transaction that invokes Increment()
Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
List<Transaction> tx2s = new ArrayList<>();
tx2s.add(tx2);
Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
Transaction tx3 = getContractTransactionWithCall(acc1, contractAddress);
List<Transaction> tx3s = new ArrayList<>();
tx3s.add(tx3);
Block block3 = new BlockBuilder(world).parent(block2).transactions(tx3s).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block3));
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
web3.personal_newAccountWithSeed("default");
web3.personal_newAccountWithSeed("notDefault");
return web3;
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class TxPoolModuleImplTest method createSampleTransaction.
private Transaction createSampleTransaction() {
Account sender = new AccountBuilder().name("sender").build();
Account receiver = new AccountBuilder().name("receiver").build();
Transaction tx = new TransactionBuilder().sender(sender).receiver(receiver).value(BigInteger.TEN).build();
return tx;
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class BodyResponseMessageTest method createTransaction.
private static Transaction createTransaction(int number) {
AccountBuilder acbuilder = new AccountBuilder();
acbuilder.name("sender" + number);
Account sender = acbuilder.build();
acbuilder.name("receiver" + number);
Account receiver = acbuilder.build();
TransactionBuilder txbuilder = new TransactionBuilder();
return txbuilder.sender(sender).receiver(receiver).value(BigInteger.valueOf(number * 1000 + 1000)).build();
}
use of co.rsk.test.builders.AccountBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceipt.
@Test
public void getTransactionReceipt() 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).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
org.junit.Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.transactionHash);
String trxFrom = TypeConverter.toJsonHex(tx.getSender().getBytes());
org.junit.Assert.assertEquals(trxFrom, tr.from);
String trxTo = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
org.junit.Assert.assertEquals(trxTo, tr.to);
String blockHashString = "0x" + block1.getHash();
org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
String blockNumberAsHex = "0x" + Long.toHexString(block1.getNumber());
org.junit.Assert.assertEquals(blockNumberAsHex, tr.blockNumber);
}
use of co.rsk.test.builders.AccountBuilder 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);
}
Aggregations