Search in sources :

Example 21 with World

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

the class Web3ImplLogsTest method getLogsFromBlockchainWithCallContractAndFilterByContractAddress.

@Test
public void getLogsFromBlockchainWithCallContractAndFilterByContractAddress() throws Exception {
    World world = new World();
    Web3Impl web3 = getWeb3WithContractCall(world);
    Block block1 = world.getBlockChain().getBlockByNumber(1l);
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    fr.address = Hex.toHexString(block1.getTransactionsList().get(0).getContractAddress().getBytes());
    Object[] logs = web3.eth_getLogs(fr);
    Assert.assertNotNull(logs);
    Assert.assertEquals(3, logs.length);
    String address = "0x" + fr.address;
    Assert.assertEquals(address, ((LogFilterElement) logs[0]).address);
    Assert.assertEquals(address, ((LogFilterElement) logs[1]).address);
    Assert.assertEquals(address, ((LogFilterElement) logs[2]).address);
}
Also used : World(co.rsk.test.World) Test(org.junit.Test)

Example 22 with World

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

the class Web3ImplLogsTest method newFilterWithAccountAndTopicsCreatedAfterBlockAndGetLogs.

@Test
public void newFilterWithAccountAndTopicsCreatedAfterBlockAndGetLogs() throws Exception {
    World world = new World();
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), null, null, null, 10, 100);
    SimpleEthereum eth = new SimpleEthereum();
    eth.repository = world.getBlockChain().getRepository();
    eth.blockchain = world.getBlockChain();
    Web3Impl web3 = createWeb3(eth, world.getBlockChain(), transactionPool, WalletFactory.createWallet());
    // TODO tricky link to listener
    world.getBlockChain().setListener(web3.setupListener());
    web3.personal_newAccountWithSeed("notDefault");
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    world.getBlockChain().tryToConnect(block1);
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.address = Hex.toHexString(tx.getContractAddress().getBytes());
    fr.topics = new Object[] { "06acbfb32bcf8383f3b0a768b70ac9ec234ea0f2d3b9c77fa6a2de69b919aad1" };
    String id = web3.eth_newFilter(fr);
    Object[] logs = web3.eth_getFilterLogs(id);
    Assert.assertNotNull(id);
    Assert.assertNotNull(logs);
    Assert.assertEquals(1, logs.length);
    Assert.assertEquals("0x" + tx.getContractAddress().toString(), ((LogFilterElement) logs[0]).address);
}
Also used : ArrayList(java.util.ArrayList) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 23 with World

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

the class Web3ImplLogsTest method getWeb3WithContractInvoke.

private Web3Impl getWeb3WithContractInvoke() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    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();
    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));
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("default");
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 24 with World

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

the class Web3ImplLogsTest method getWeb3.

private Web3Impl getWeb3() {
    World world = new World();
    Web3Impl web3 = createWeb3(world.getBlockChain(), null);
    return web3;
}
Also used : World(co.rsk.test.World)

Example 25 with World

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

the class Web3ImplLogsTest method getLogsFromBlockchainWithCallContract.

@Test
public void getLogsFromBlockchainWithCallContract() throws Exception {
    World world = new World();
    Web3Impl web3 = getWeb3WithContractCall(world);
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    Object[] logs = web3.eth_getLogs(fr);
    Assert.assertNotNull(logs);
    Assert.assertEquals(3, logs.length);
}
Also used : World(co.rsk.test.World) 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