Search in sources :

Example 36 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class Web3ImplTest method getUnknownTransactionByBlockNumberAndIndex.

@Test
public void getUnknownTransactionByBlockNumberAndIndex() 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));
    TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x1", "0x0");
    Assert.assertNull(tr);
}
Also used : TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 37 with World

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

Example 38 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class Web3ImplTest method getBalanceWithAccountAndGenesisBlock.

@Test
public void getBalanceWithAccountAndGenesisBlock() 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();
    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, "0x0"));
}
Also used : AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) Test(org.junit.Test)

Example 39 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class Web3ImplTest method getBlockByHashWithTransactionsHashAsResult.

@Test
public void getBlockByHashWithTransactionsHashAsResult() 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, false);
    Assert.assertNotNull(bresult);
    org.junit.Assert.assertEquals(block1HashString, bresult.hash);
    org.junit.Assert.assertEquals(1, bresult.transactions.length);
    org.junit.Assert.assertEquals(tx.getHash().toJsonString(), bresult.transactions[0]);
    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 40 with World

use of co.rsk.test.World in project rskj by rsksmart.

the class Web3ImplTest method getBlockByNumber.

@Test
public void getBlockByNumber() throws Exception {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Block genesis = world.getBlockChain().getBestBlock();
    Block block1 = new BlockBuilder(world).difficulty(10).parent(genesis).build();
    org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
    Block block1b = new BlockBuilder(world).difficulty(2).parent(genesis).build();
    block1b.setBitcoinMergedMiningHeader(new byte[] { 0x01 });
    Block block2b = new BlockBuilder(world).difficulty(11).parent(block1b).build();
    block2b.setBitcoinMergedMiningHeader(new byte[] { 0x02 });
    org.junit.Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
    org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2b));
    Web3.BlockResult bresult = web3.eth_getBlockByNumber("0x1", false);
    Assert.assertNotNull(bresult);
    String blockHash = "0x" + block1b.getHash();
    org.junit.Assert.assertEquals(blockHash, bresult.hash);
    bresult = web3.eth_getBlockByNumber("0x2", true);
    Assert.assertNotNull(bresult);
    blockHash = "0x" + block2b.getHash();
    org.junit.Assert.assertEquals(blockHash, bresult.hash);
}
Also used : World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Aggregations

World (co.rsk.test.World)134 Test (org.junit.Test)114 BlockBuilder (co.rsk.test.builders.BlockBuilder)36 AccountBuilder (co.rsk.test.builders.AccountBuilder)33 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)24 DslParser (co.rsk.test.dsl.DslParser)23 Block (org.ethereum.core.Block)20 Blockchain (org.ethereum.core.Blockchain)19 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)15 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)14 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)14 ArrayList (java.util.ArrayList)13 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)13 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)11 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)11 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)11 BigInteger (java.math.BigInteger)10 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)9 Account (org.ethereum.core.Account)8