Search in sources :

Example 16 with DataWord

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());
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 17 with DataWord

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));
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 18 with DataWord

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());
}
Also used : Program(org.ethereum.vm.program.Program) DataWord(org.ethereum.vm.DataWord) Stack(org.ethereum.vm.program.Stack) Test(org.junit.Test)

Example 19 with DataWord

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);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) BlockStore(org.ethereum.db.BlockStore) Constants(org.ethereum.config.Constants) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) BlockchainNetConfig(org.ethereum.config.BlockchainNetConfig) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 20 with DataWord

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);
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

DataWord (org.ethereum.vm.DataWord)133 Test (org.junit.Test)88 Repository (org.ethereum.core.Repository)41 RskAddress (co.rsk.core.RskAddress)25 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)22 BigInteger (java.math.BigInteger)19 LogInfo (org.ethereum.vm.LogInfo)17 HashMapDB (org.ethereum.datasource.HashMapDB)14 Program (org.ethereum.vm.program.Program)13 Stack (org.ethereum.vm.program.Stack)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RepositoryImpl (co.rsk.db.RepositoryImpl)9 ContractDetails (org.ethereum.db.ContractDetails)9 Trie (co.rsk.trie.Trie)8 CallTransaction (org.ethereum.core.CallTransaction)8 TrieImpl (co.rsk.trie.TrieImpl)7 TrieStore (co.rsk.trie.TrieStore)7 Coin (co.rsk.core.Coin)5