Search in sources :

Example 96 with World

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

the class Web3ImplLogsTest method getLogsFromBlockchainWithCallContractAndFilterByUnknownTopic.

@Test
public void getLogsFromBlockchainWithCallContractAndFilterByUnknownTopic() throws Exception {
    World world = new World();
    Web3Impl web3 = getWeb3WithContractCall(world);
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    fr.topics = new Object[1];
    fr.topics[0] = "0102030405060102030405060102030405060102030405060102030405060102";
    Object[] logs = web3.eth_getLogs(fr);
    Assert.assertNotNull(logs);
    Assert.assertEquals(0, logs.length);
}
Also used : World(co.rsk.test.World) Test(org.junit.Test)

Example 97 with World

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

the class Web3ImplLogsTest method getLogsFromBlockchainWithCallContractAndFilterByKnownTopic.

@Test
public void getLogsFromBlockchainWithCallContractAndFilterByKnownTopic() 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.topics = new Object[1];
    fr.topics[0] = GET_VALUED_EVENT_SIGNATURE;
    Object[] logs = web3.eth_getLogs(fr);
    Assert.assertNotNull(logs);
    String address = "0x" + Hex.toHexString(block1.getTransactionsList().get(0).getContractAddress().getBytes());
    Assert.assertEquals(1, logs.length);
    Assert.assertEquals(address, ((LogFilterElement) logs[0]).address);
}
Also used : World(co.rsk.test.World) Test(org.junit.Test)

Example 98 with World

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

the class Web3ImplLogsTest method getLogsFromBlockchainWithCallContractAndFilterByUnknownContractAddress.

@Test
public void getLogsFromBlockchainWithCallContractAndFilterByUnknownContractAddress() throws Exception {
    World world = new World();
    Web3Impl web3 = getWeb3WithContractCall(world);
    Web3.FilterRequest fr = new Web3.FilterRequest();
    fr.fromBlock = "earliest";
    List<String> addresses = new ArrayList<>();
    addresses.add(Hex.toHexString(new byte[20]));
    fr.address = addresses;
    Object[] logs = web3.eth_getLogs(fr);
    Assert.assertNotNull(logs);
    Assert.assertEquals(0, logs.length);
}
Also used : ArrayList(java.util.ArrayList) World(co.rsk.test.World) Test(org.junit.Test)

Example 99 with World

use of co.rsk.test.World 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;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) World(co.rsk.test.World) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 100 with World

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

the class Web3ImplLogsTest method getWeb3WithEventInContractCreation.

private Web3Impl getWeb3WithEventInContractCreation() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = getWorld3WithBlockWithEventInContractCreation(config, receiptStore);
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore)

Aggregations

World (co.rsk.test.World)198 Test (org.junit.Test)169 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)55 DslParser (co.rsk.test.dsl.DslParser)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)46 HashMapDB (org.ethereum.datasource.HashMapDB)45 AccountBuilder (co.rsk.test.builders.AccountBuilder)36 Block (org.ethereum.core.Block)36 ReceiptStore (org.ethereum.db.ReceiptStore)34 BlockBuilder (co.rsk.test.builders.BlockBuilder)31 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)31 Blockchain (org.ethereum.core.Blockchain)30 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)24 Transaction (org.ethereum.core.Transaction)23 BigInteger (java.math.BigInteger)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Account (org.ethereum.core.Account)15 TestSystemProperties (co.rsk.config.TestSystemProperties)14