use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class HashMapDBTest method putKeyValue.
@Test
public void putKeyValue() {
KeyValueDataSource ds = new HashMapDB();
byte[] key = new byte[] { 0x01, 0x02 };
byte[] value = new byte[] { 0x03, 0x03 };
byte[] result = ds.put(key, value);
Assert.assertNull(result);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class HashMapDBTest method putAndDeleteKeyValue.
@Test
public void putAndDeleteKeyValue() {
KeyValueDataSource ds = new HashMapDB();
byte[] key = new byte[] { 0x01, 0x02 };
byte[] value = new byte[] { 0x03, 0x03 };
ds.put(key, value);
ds.delete(key);
byte[] result = ds.get(key);
Assert.assertNull(result);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByHash.
@Test
public void getTransactionByHash() {
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 block1 = createCanonicalBlock(world, txs);
String hashString = tx.getHash().toHexString();
TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
assertNotNull(tr);
assertEquals("0x" + hashString, tr.getHash());
String blockHashString = "0x" + block1.getHash();
assertEquals(blockHashString, tr.getBlockHash());
assertEquals("0x", tr.getInput());
assertEquals("0x" + ByteUtil.toHexString(tx.getReceiveAddress().getBytes()), tr.getTo());
// Check the v value used to encode the transaction
// NOT the v value used in signature
// the encoded value includes chain id
Assert.assertArrayEquals(new byte[] { tx.getEncodedV() }, TypeConverter.stringHexToByteArray(tr.getV()));
Assert.assertThat(TypeConverter.stringHexToBigInteger(tr.getS()), is(tx.getSignature().getS()));
Assert.assertThat(TypeConverter.stringHexToBigInteger(tr.getR()), is(tx.getSignature().getR()));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceipt.
@Test
public void getTransactionReceipt() {
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 block1 = createCanonicalBlock(world, txs);
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
assertNotNull(tr);
assertEquals("0x" + hashString, tr.getTransactionHash());
String trxFrom = TypeConverter.toJsonHex(tx.getSender().getBytes());
assertEquals(trxFrom, tr.getFrom());
String trxTo = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
assertEquals(trxTo, tr.getTo());
String blockHashString = "0x" + block1.getHash();
assertEquals(blockHashString, tr.getBlockHash());
String blockNumberAsHex = "0x" + Long.toHexString(block1.getNumber());
assertEquals(blockNumberAsHex, tr.getBlockNumber());
String rawTransactionReceipt = web3.rsk_getRawTransactionReceiptByHash(hashString);
String expectedRawTxReceipt = "0xf9010c01825208b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c082520801";
assertEquals(expectedRawTxReceipt, rawTransactionReceipt);
String[] transactionReceiptNodes = web3.rsk_getTransactionReceiptNodesByHash(blockHashString, hashString);
ArrayList<String> expectedRawTxReceiptNodes = new ArrayList<>();
expectedRawTxReceiptNodes.add("0x70078048ee76b19fc451dba9dbee8b3e73084f79ea540d3940b3b36b128e8024e9302500010f");
assertEquals(1, transactionReceiptNodes.length);
assertEquals(expectedRawTxReceiptNodes.get(0), transactionReceiptNodes[0]);
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class Web3ImplTest method checkSendTransaction.
private void checkSendTransaction(Byte chainId) {
BigInteger nonce = BigInteger.ONE;
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockChain = world.getBlockChain();
BlockStore blockStore = world.getBlockStore();
TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutorFactory(blockStore, world.getBlockTxSignatureCache());
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepositoryLocator(), blockStore, blockFactory, null, transactionExecutorFactory, world.getReceivedTxSignatureCache(), 10, 100);
Web3Impl web3 = createWeb3(world, transactionPool, receiptStore);
// **** Initializes data ******************
String[] accounts = web3.personal_listAccounts();
String addr1 = accounts[0];
String addr2 = accounts[1];
transactionPool.processBest(blockChain.getBestBlock());
String toAddress = addr2;
BigInteger value = BigInteger.valueOf(7);
BigInteger gasPrice = BigInteger.valueOf(8);
BigInteger gasLimit = BigInteger.valueOf(300000);
String data = "0xff";
// ***** Executes the transaction *******************
CallArguments args = new CallArguments();
args.setFrom(addr1);
args.setTo(addr2);
args.setData(data);
args.setGas(TypeConverter.toQuantityJsonHex(gasLimit));
args.setGasPrice(TypeConverter.toQuantityJsonHex(gasPrice));
args.setValue(value.toString());
args.setNonce(nonce.toString());
if (chainId != null) {
args.setChainId(TypeConverter.toJsonHex(new byte[] { chainId }));
}
String txHash = web3.eth_sendTransaction(args);
// ***** Verifies tx hash
String to = toAddress.substring(2);
Transaction tx = Transaction.builder().nonce(nonce).gasPrice(gasPrice).gasLimit(gasLimit).destination(Hex.decode(to)).data(args.getData() == null ? null : Hex.decode(args.getData())).chainId(config.getNetworkConstants().getChainId()).value(value).build();
tx.sign(wallet.getAccount(new RskAddress(addr1)).getEcKey().getPrivKeyBytes());
String expectedHash = tx.getHash().toJsonString();
assertEquals("Method is not creating the expected transaction", 0, expectedHash.compareTo(txHash));
}
Aggregations