use of org.ethereum.vm.LogInfo in project rskj by rsksmart.
the class BridgeSupportTest method callUpdateCollectionsGenerateEventLog.
@Test
public void callUpdateCollectionsGenerateEventLog() throws IOException, BlockStoreException {
Repository track = new RepositoryImpl(config).startTracking();
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> blocks = blockGenerator.getSimpleBlockChain(blockGenerator.getGenesisBlock(), 10);
org.ethereum.core.Block rskCurrentBlock = blocks.get(9);
List<LogInfo> eventLogs = new LinkedList<>();
BridgeEventLogger eventLogger = new BridgeEventLoggerImpl(bridgeConstants, eventLogs);
BridgeSupport bridgeSupport = new BridgeSupport(config, track, eventLogger, PrecompiledContracts.BRIDGE_ADDR, rskCurrentBlock);
Transaction tx = Transaction.create(config, TO_ADDRESS, DUST_AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA);
ECKey key = new ECKey();
tx.sign(key.getPrivKeyBytes());
bridgeSupport.updateCollections(tx);
Assert.assertEquals(1, eventLogs.size());
// Assert address that made the log
LogInfo result = eventLogs.get(0);
Assert.assertArrayEquals(PrecompiledContracts.BRIDGE_ADDR.getBytes(), result.getAddress());
// Assert log topics
Assert.assertEquals(1, result.getTopics().size());
Assert.assertEquals(Bridge.UPDATE_COLLECTIONS_TOPIC, result.getTopics().get(0));
// Assert log data
Assert.assertArrayEquals(key.getAddress(), RLP.decode2(result.getData()).get(0).getRLPData());
}
use of org.ethereum.vm.LogInfo in project rskj by rsksmart.
the class SamplePrecompiledContractTest method GetResult.
private int GetResult(Repository repository) {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[], \n" + " 'name':'GetResult', \n" + " 'outputs':[{'name':'result','type':'int'}], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] data = function.encode();
contract.init(null, null, repository, null, null, new ArrayList<LogInfo>());
byte[] result = contract.execute(data);
Object[] results = function.decodeResult(result);
return ((BigInteger) results[0]).intValue();
}
use of org.ethereum.vm.LogInfo in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractIncrementResultOk.
@Test
public void samplePrecompiledContractIncrementResultOk() {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[], \n" + " 'name':'IncrementResult', \n" + " 'outputs':[], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] data = function.encode();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
contract.init(null, null, track, null, null, new ArrayList<LogInfo>());
contract.execute(data);
track.commit();
int result = this.GetResult(repository);
assertEquals(1, result);
}
use of org.ethereum.vm.LogInfo in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractMethodDoesNotExist.
@Test
public void samplePrecompiledContractMethodDoesNotExist() {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[{'name':'param0','type':'int'}, \n" + " {'name':'param1','type':'bytes'}, \n" + " {'name':'param2','type':'int'}], \n" + " 'name':'UnexistentMethod', \n" + " 'outputs':[{'name':'output0','type':'int'}], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] bytes = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
byte[] data = function.encode(111, bytes, 222);
contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
byte[] result = contract.execute(data);
assertNull(result);
}
use of org.ethereum.vm.LogInfo in project rskj by rsksmart.
the class ReceiptStoreImplTest method createReceipt.
// from TransactionTest
private static TransactionReceipt createReceipt() {
byte[] stateRoot = Hex.decode("f5ff3fbd159773816a7c707a9b8cb6bb778b934a8f6466c7830ed970498f4b68");
byte[] gasUsed = Hex.decode("01E848");
Bloom bloom = new Bloom(Hex.decode("0000000000000000800000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
LogInfo logInfo1 = new LogInfo(Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"), null, Hex.decode("a1a1a1"));
List<LogInfo> logs = new ArrayList<>();
logs.add(logInfo1);
// TODO calculate cumulative gas
TransactionReceipt receipt = new TransactionReceipt(stateRoot, gasUsed, gasUsed, bloom, logs, new byte[] { 0x01 });
receipt.setTransaction(new Transaction(null, null, null, null, null, null));
return receipt;
}
Aggregations