Search in sources :

Example 36 with MutableRepository

use of org.ethereum.db.MutableRepository in project rskj by rsksmart.

the class RepositoryUpdateTest method putDataWordZeroAsDeleteValue.

@Test
public void putDataWordZeroAsDeleteValue() {
    ContractDetailsImpl details = buildContractDetails();
    details.put(DataWord.ONE, DataWord.valueOf(42));
    details.put(DataWord.ONE, DataWord.ZERO);
    Repository repo = new MutableRepository(new MutableTrieCache(new MutableTrieImpl(null, new Trie())));
    updateContractDetails(repo, address, details);
    repo.commit();
    byte[] value = repo.getTrie().get(DataWord.ONE.getData());
    Assert.assertNull(value);
    Assert.assertEquals(0, details.getStorageSize());
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 37 with MutableRepository

use of org.ethereum.db.MutableRepository in project rskj by rsksmart.

the class RepositoryUpdateTest method getStorageRoot.

@Test
public void getStorageRoot() {
    ContractDetailsImpl details = buildContractDetails();
    details.put(DataWord.ONE, DataWord.valueOf(42));
    details.put(DataWord.ZERO, DataWord.valueOf(1));
    Repository repo = new MutableRepository(new MutableTrieImpl(null, new Trie()));
    updateContractDetails(repo, address, details);
    Assert.assertNotNull(repo.getTrie().getHash().getBytes());
}
Also used : Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 38 with MutableRepository

use of org.ethereum.db.MutableRepository in project rskj by rsksmart.

the class BridgeStateTest method recreateFromEmptyStorageProvider.

@Test
public void recreateFromEmptyStorageProvider() throws IOException {
    TestSystemProperties config = new TestSystemProperties();
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
    BridgeConstants bridgeConstants = config.getNetworkConstants().getBridgeConstants();
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, config.getActivationConfig().forBlock(0L));
    BridgeState state = new BridgeState(42, provider, null);
    BridgeState clone = BridgeState.create(bridgeConstants, state.getEncoded(), null);
    Assert.assertNotNull(clone);
    Assert.assertEquals(42, clone.getBtcBlockchainBestChainHeight());
    Assert.assertTrue(clone.getActiveFederationBtcUTXOs().isEmpty());
    Assert.assertTrue(clone.getRskTxsWaitingForSignatures().isEmpty());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BridgeConstants(co.rsk.config.BridgeConstants) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 39 with MutableRepository

use of org.ethereum.db.MutableRepository in project rskj by rsksmart.

the class RemascStorageProviderTest method setSaveRetrieveAndGetRewardBalance.

@Test
public void setSaveRetrieveAndGetRewardBalance() throws IOException {
    RskAddress accountAddress = randomAddress();
    Repository repository = new MutableRepository(new MutableTrieImpl(null, new Trie()));
    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);
    provider.setRewardBalance(Coin.valueOf(255));
    provider.save();
    RemascStorageProvider newProvider = new RemascStorageProvider(repository, accountAddress);
    Assert.assertEquals(Coin.valueOf(255), newProvider.getRewardBalance());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) Trie(co.rsk.trie.Trie) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 40 with MutableRepository

use of org.ethereum.db.MutableRepository in project rskj by rsksmart.

the class DslFilesTest method runCreate02Resource.

@Test
public void runCreate02Resource() throws FileNotFoundException, DslProcessorException {
    // byte[] code2 =Hex.decode("608060405234801561001057600080fd5b504361001a61017b565b80828152602001915050604051809103906000f080158015610040573d6000803e3d6000fd5b506000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507f80ae3ec8027d0c5d1f3e47fb4bf1d9fc28225e7f4bcb1971b36efb81fe40574d6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663209652556040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15801561012657600080fd5b505af115801561013a573d6000803e3d6000fd5b505050506040513d602081101561015057600080fd5b81019080805190602001909291905050506040518082815260200191505060405180910390a161018b565b6040516101e38061028283390190565b60e9806101996000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806361bc221a146044575b600080fd5b348015604f57600080fd5b5060566098565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff16815600a165627a7a7230582091284634a2c8e5cbd0e4153a1422a41670914d8ef8b4f7dc71bd54cf80baf8f50029608060405234801561001057600080fd5b506040516020806101e383398101806040528101908080519060200190929190505050806000819055507f06acbfb32bcf8383f3b0a768b70ac9ec234ea0f2d3b9c77fa6a2de69b919aad16000546040518082815260200191505060405180910390a150610160806100836000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632096525514610051578063d09de08a1461007c575b600080fd5b34801561005d57600080fd5b50610066610093565b6040518082815260200191505060405180910390f35b34801561008857600080fd5b506100916100d6565b005b60007f1ee041944547858a75ebef916083b6d4f5ae04bea9cd809334469dd07dbf441b6000546040518082815260200191505060405180910390a1600054905090565b600080815460010191905081905550600160026000548115156100f557fe5b061415157f6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad6000546040518082815260200191505060405180910390a25600a165627a7a7230582041617f72986040ac8590888e68e070d9d05aeb99361c0c77d1f67540db5ff6b10029");
    // System.out.print(Program.stringifyMultiline(code2));
    DslParser parser = DslParser.fromResource("dsl/create02.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Assert.assertNotNull(world.getBlockChain().getBlockByHash(world.getBlockByName("g00").getHash().getBytes()));
    Assert.assertNotNull(world.getBlockChain().getBlockByHash(world.getBlockByName("b01").getHash().getBytes()));
    Assert.assertNotNull(world.getBlockChain().getBlockByHash(world.getBlockByName("b01b").getHash().getBytes()));
    Assert.assertNotNull(world.getBlockChain().getBlockByHash(world.getBlockByName("b02b").getHash().getBytes()));
    Block top1 = world.getBlockByName("b01");
    Block top2 = world.getBlockByName("b02b");
    // Creates a new view of the repository, standing on top1 state
    Repository repo1 = new MutableRepository(world.getTrieStore(), world.getTrieStore().retrieve(top1.getStateRoot()).get());
    // Creates a new view of the repository, standing on top2 state
    Repository repo2 = new MutableRepository(world.getTrieStore(), world.getTrieStore().retrieve(top2.getStateRoot()).get());
    // addr1: sender's account
    RskAddress addr1 = new RskAddress("a0663f719962ec10bb57865532bef522059dfd96");
    // addr2: Parent Contract account
    RskAddress addr2 = new RskAddress("6252703f5ba322ec64d3ac45e56241b7d9e481ad");
    // add3: child contract account
    RskAddress addr3 = new RskAddress("8bdb1bf28586425b976b06a3079bd2c09a6f8e8b");
    // Sender account in branch 1
    // Null means no code
    Assert.assertNull(repo1.getCode(addr1));
    Assert.assertFalse(repo1.isContract(addr1));
    // "Creator" Contract account in branch 1
    // This contract has storage.
    Assert.assertTrue(repo1.isContract(addr2));
    Assert.assertNotNull(repo1.getCode(addr2));
    Assert.assertNotEquals(0, repo1.getCode(addr2).length);
    // Subcontract account in branch 1.
    Assert.assertNotNull(repo1.getCode(addr3));
    Assert.assertNotEquals(0, repo1.getCode(addr3).length);
    // Sender account in branch 2
    Assert.assertNull(repo2.getCode(addr1));
    Assert.assertFalse(repo2.isContract(addr1));
    // "Creator" Contract account in branch 2
    // This contract has no childs?
    Assert.assertTrue(repo2.isContract(addr2));
    Assert.assertNotNull(repo2.getCode(addr2));
    Assert.assertNotEquals(0, repo2.getCode(addr2).length);
    // Subcontract account in branch 2
    Assert.assertTrue(repo2.isContract(addr3));
    Assert.assertNotNull(repo2.getCode(addr3));
    Assert.assertNotEquals(0, repo2.getCode(addr3).length);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) Test(org.junit.Test)

Aggregations

MutableRepository (org.ethereum.db.MutableRepository)40 Test (org.junit.Test)31 Trie (co.rsk.trie.Trie)26 RskAddress (co.rsk.core.RskAddress)21 Repository (org.ethereum.core.Repository)15 TrieStore (co.rsk.trie.TrieStore)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)12 HashMapDB (org.ethereum.datasource.HashMapDB)12 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 BigInteger (java.math.BigInteger)8 Coin (co.rsk.core.Coin)7 DataWord (org.ethereum.vm.DataWord)7 MutableTrieImpl (co.rsk.db.MutableTrieImpl)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)5 MutableTrie (co.rsk.trie.MutableTrie)4 ArrayList (java.util.ArrayList)4 Block (org.ethereum.core.Block)4 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)2 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)2 CountDownLatch (java.util.concurrent.CountDownLatch)2