Search in sources :

Example 21 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder 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);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 22 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder 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);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) World(co.rsk.test.World) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 23 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder 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);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) World(co.rsk.test.World) TestContract(co.rsk.util.TestContract) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 24 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class Web3ImplTest method getPendingTransactionByHash.

@Test
public void getPendingTransactionByHash() throws Exception {
    World world = new World();
    BlockChainImpl blockChain = world.getBlockChain();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    transactionPool.processBest(blockChain.getBestBlock());
    Web3Impl web3 = createWeb3(world, transactionPool, null);
    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();
    transactionPool.addTransaction(tx);
    String hashString = tx.getHash().toHexString();
    TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
    Assert.assertNotNull(tr);
    org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
    org.junit.Assert.assertEquals("0", tr.nonce);
    org.junit.Assert.assertEquals(null, tr.blockHash);
    org.junit.Assert.assertEquals(null, tr.transactionIndex);
    org.junit.Assert.assertEquals("0x00", tr.input);
    org.junit.Assert.assertEquals("0x" + Hex.toHexString(tx.getReceiveAddress().getBytes()), tr.to);
}
Also used : TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

Example 25 with TransactionBuilder

use of co.rsk.test.builders.TransactionBuilder in project rskj by rsksmart.

the class ContractRunner method runContract.

private ProgramResult runContract(byte[] contractAddress, byte[] encodedCall, BigInteger value) {
    BigInteger nonceExecute = repository.getNonce(sender.getAddress());
    Transaction transaction = new TransactionBuilder().gasLimit(BigInteger.valueOf(10_000_000)).sender(sender).receiverAddress(contractAddress).data(encodedCall).nonce(nonceExecute.longValue()).value(value).build();
    return executeTransaction(transaction).getResult();
}
Also used : BigInteger(java.math.BigInteger) TransactionBuilder(co.rsk.test.builders.TransactionBuilder)

Aggregations

TransactionBuilder (co.rsk.test.builders.TransactionBuilder)29 AccountBuilder (co.rsk.test.builders.AccountBuilder)24 Test (org.junit.Test)17 World (co.rsk.test.World)15 BlockBuilder (co.rsk.test.builders.BlockBuilder)13 Account (org.ethereum.core.Account)10 Transaction (org.ethereum.core.Transaction)9 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)3 BigInteger (java.math.BigInteger)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 ReceiptStore (org.ethereum.db.ReceiptStore)3 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)3 TransactionReceiptDTO (org.ethereum.rpc.dto.TransactionReceiptDTO)2 TestContract (co.rsk.util.TestContract)1 ArrayList (java.util.ArrayList)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1