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"));
}
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));
}
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));
}
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);
}
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);
}
Aggregations