use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class VMExecutionTest method testAdd.
@Test
public void testAdd() {
Program program = executeCode("PUSH1 1 PUSH1 2 ADD", 3);
Stack stack = program.getStack();
Assert.assertEquals(1, stack.size());
Assert.assertEquals(new DataWord(3), stack.peek());
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class VMExecutionTest method dupnTwentiethItem.
@Test
public void dupnTwentiethItem() {
Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x03 PUSH1 0x04 PUSH1 0x05 PUSH1 0x06 PUSH1 0x07 PUSH1 0x08 PUSH1 0x09 PUSH1 0x0a PUSH1 0x0b PUSH1 0x0c PUSH1 0x0d PUSH1 0x0e PUSH1 0x0f PUSH1 0x10 PUSH1 0x11 PUSH1 0x12 PUSH1 0x13 PUSH1 0x14 PUSH1 0x13 DUPN", 22);
Stack stack = program.getStack();
Assert.assertEquals(21, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
for (int k = 0; k < 20; k++) Assert.assertEquals(new DataWord(k + 1), stack.get(k));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class VMExecutionTest method txindexExecution.
@Test
public void txindexExecution() {
invoke.setTransactionIndex(new DataWord(42));
Program program = executeCode("TXINDEX", 1);
Stack stack = program.getStack();
Assert.assertEquals(1, stack.size());
Assert.assertEquals(new DataWord(42), stack.peek());
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainEmptyBlockchain.
@Test
public void testLoadBlockchainEmptyBlockchain() throws IOException {
String jsonFile = "blockchain_loader_genesis.json";
RskSystemProperties systemProperties = Mockito.mock(RskSystemProperties.class);
Constants constants = Mockito.mock(Constants.class);
Mockito.when(constants.getInitialNonce()).thenReturn(BigInteger.ZERO);
BlockchainNetConfig blockchainNetConfig = Mockito.mock(BlockchainNetConfig.class);
Mockito.when(blockchainNetConfig.getCommonConstants()).thenReturn(constants);
Mockito.when(systemProperties.databaseDir()).thenReturn(new RskSystemProperties().databaseDir());
Mockito.when(systemProperties.getBlockchainConfig()).thenReturn(blockchainNetConfig);
Mockito.when(systemProperties.genesisInfo()).thenReturn(jsonFile);
BlockStore blockStore = Mockito.mock(BlockStore.class);
Mockito.when(blockStore.getBestBlock()).thenReturn(null);
EthereumListener ethereumListener = Mockito.mock(EthereumListener.class);
Repository repository = new RepositoryImpl(systemProperties, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
;
BlockChainLoader blockChainLoader = new BlockChainLoader(systemProperties, repository, blockStore, null, null, ethereumListener, null, null);
blockChainLoader.loadBlockchain();
Assert.assertEquals(5, repository.getAccountsKeys().size());
Assert.assertEquals(Coin.valueOf(2000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
Assert.assertEquals(BigInteger.valueOf(24), repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0001")));
Assert.assertEquals(Coin.valueOf(1000), repository.getBalance(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
Assert.assertEquals(BigInteger.ZERO, repository.getNonce(new RskAddress("dabadabadabadabadabadabadabadabadaba0002")));
Assert.assertEquals(Coin.valueOf(10), repository.getBalance(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
Assert.assertEquals(BigInteger.valueOf(25), repository.getNonce(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")));
Assert.assertEquals(DataWord.ONE, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ZERO));
Assert.assertEquals(new DataWord(3), repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).get(DataWord.ONE));
Assert.assertEquals(274, repository.getContractDetails(new RskAddress("77045e71a7a2c50903d88e564cd72fab11e82051")).getCode().length);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class DetailsDataStoreTest method test1.
@Test
public void test1() {
DatabaseImpl db = new DatabaseImpl(new HashMapDB());
DetailsDataStore dds = new DetailsDataStore(config, db);
RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
byte[] code = Hex.decode("60606060");
byte[] key = Hex.decode("11");
byte[] value = Hex.decode("aa");
ContractDetails contractDetails = new ContractDetailsImpl(config);
contractDetails.setAddress(randomAddress().getBytes());
contractDetails.setCode(code);
contractDetails.put(new DataWord(key), new DataWord(value));
dds.update(c_key, contractDetails);
ContractDetails contractDetails_ = dds.get(c_key);
String encoded1 = Hex.toHexString(contractDetails.getEncoded());
String encoded2 = Hex.toHexString(contractDetails_.getEncoded());
assertEquals(encoded1, encoded2);
dds.flush();
contractDetails_ = dds.get(c_key);
encoded2 = Hex.toHexString(contractDetails_.getEncoded());
assertEquals(encoded1, encoded2);
}
Aggregations