Search in sources :

Example 31 with World

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

the class Web3ImplSnapshotTest method revertToUnknownSnapshot.

@Test
public void revertToUnknownSnapshot() {
    World world = new World();
    Web3Impl web3 = createWeb3(world);
    Assert.assertFalse(web3.evm_revert("0x2a"));
}
Also used : World(co.rsk.test.World) Test(org.junit.Test)

Example 32 with World

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

the class Web3ImplSnapshotTest method increaseTimeTwiceUsingDecimalValues.

@Test
public void increaseTimeTwiceUsingDecimalValues() {
    World world = new World();
    SimpleEthereum ethereum = new SimpleEthereum();
    MinerServer minerServer = getMinerServerForTest(world, ethereum);
    Web3Impl web3 = createWeb3(world, ethereum, minerServer);
    web3.evm_increaseTime("16");
    String result = web3.evm_increaseTime("16");
    Assert.assertEquals("0x20", result);
    Assert.assertEquals(32, minerServer.increaseTime(0));
}
Also used : SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) World(co.rsk.test.World) Test(org.junit.Test)

Example 33 with World

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

the class Web3ImplSnapshotTest method increaseTimeTwice.

@Test
public void increaseTimeTwice() {
    World world = new World();
    SimpleEthereum ethereum = new SimpleEthereum();
    MinerServer minerServer = getMinerServerForTest(world, ethereum);
    Web3Impl web3 = createWeb3(world, ethereum, minerServer);
    web3.evm_increaseTime("0x10");
    String result = web3.evm_increaseTime("0x10");
    Assert.assertEquals("0x20", result);
    Assert.assertEquals(32, minerServer.increaseTime(0));
}
Also used : SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) World(co.rsk.test.World) Test(org.junit.Test)

Example 34 with World

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

the class Web3ImplTest method eth_sendTransaction.

@Test
public void eth_sendTransaction() {
    BigInteger nonce = BigInteger.ONE;
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Web3Impl web3 = createWeb3(world, receiptStore);
    // **** Initializes data ******************
    String addr1 = web3.personal_newAccountWithSeed("sampleSeed1");
    String addr2 = web3.personal_newAccountWithSeed("sampleSeed2");
    String toAddress = addr2;
    BigInteger value = BigInteger.valueOf(7);
    BigInteger gasPrice = BigInteger.valueOf(8);
    BigInteger gasLimit = BigInteger.valueOf(9);
    String data = "0xff";
    // ***** Executes the transaction *******************
    Web3.CallArguments args = new Web3.CallArguments();
    args.from = addr1;
    args.to = addr2;
    args.data = data;
    args.gas = TypeConverter.toJsonHex(gasLimit);
    args.gasPrice = TypeConverter.toJsonHex(gasPrice);
    args.value = value.toString();
    args.nonce = nonce.toString();
    String txHash = null;
    try {
        txHash = web3.eth_sendTransaction(args);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // ***** Verifies tx hash
    Transaction tx = Transaction.create(config, toAddress.substring(2), value, nonce, gasPrice, gasLimit, args.data);
    tx.sign(wallet.getAccount(new RskAddress(addr1)).getEcKey().getPrivKeyBytes());
    String expectedHash = tx.getHash().toJsonString();
    Assert.assertTrue("Method is not creating the expected transaction", expectedHash.compareTo(txHash) == 0);
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) BigInteger(java.math.BigInteger) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 35 with World

use of co.rsk.test.World 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);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionReceiptDTO(org.ethereum.rpc.dto.TransactionReceiptDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) 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