Search in sources :

Example 36 with RepositorySnapshot

use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.

the class WorldDslProcessorTest method processAccountNewCommandWithBalance.

@Test
public void processAccountNewCommandWithBalance() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser = new DslParser("account_new acc1 1000000");
    processor.processCommands(parser);
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
    RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(world.getBlockChain().getBestBlock().getHeader());
    Assert.assertEquals(new BigInteger("1000000"), repository.getBalance(account.getAddress()).asBigInteger());
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) RepositorySnapshot(co.rsk.db.RepositorySnapshot) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Example 37 with RepositorySnapshot

use of co.rsk.db.RepositorySnapshot in project rskj by rsksmart.

the class WorldDslProcessorTest method processAccountNewCommandWithBalanceAndCodeWithOtherAccountAddress.

@Test
public void processAccountNewCommandWithBalanceAndCodeWithOtherAccountAddress() throws DslProcessorException {
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    DslParser parser0 = new DslParser("account_new acc0");
    processor.processCommands(parser0);
    DslParser parser = new DslParser("account_new acc1 1000000 0102[acc0]0304");
    processor.processCommands(parser);
    Account account0 = world.getAccountByName("acc0");
    Account account = world.getAccountByName("acc1");
    Assert.assertNotNull(account);
    RepositorySnapshot repository = world.getRepositoryLocator().snapshotAt(world.getBlockChain().getBestBlock().getHeader());
    Assert.assertEquals(new BigInteger("1000000"), repository.getBalance(account.getAddress()).asBigInteger());
    byte[] code = repository.getCode(account.getAddress());
    byte[] expected = new byte[4 + 20];
    expected[0] = 0x01;
    expected[1] = 0x02;
    System.arraycopy(account0.getAddress().getBytes(), 0, expected, 2, Address.LENGTH);
    expected[22] = 0x03;
    expected[23] = 0x04;
    Assert.assertNotNull(code);
    Assert.assertArrayEquals(expected, code);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Account(org.ethereum.core.Account) RepositorySnapshot(co.rsk.db.RepositorySnapshot) DslParser(co.rsk.test.dsl.DslParser) BigInteger(java.math.BigInteger) World(co.rsk.test.World) Test(org.junit.Test)

Aggregations

RepositorySnapshot (co.rsk.db.RepositorySnapshot)37 Test (org.junit.Test)25 RepositoryLocator (co.rsk.db.RepositoryLocator)18 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)13 RskAddress (co.rsk.core.RskAddress)12 BlockStore (org.ethereum.db.BlockStore)11 BigInteger (java.math.BigInteger)10 Coin (co.rsk.core.Coin)9 BlockExecutor (co.rsk.core.bc.BlockExecutor)8 World (co.rsk.test.World)7 TestSystemProperties (co.rsk.config.TestSystemProperties)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)5 Account (org.ethereum.core.Account)5 AccountInformationProvider (co.rsk.core.bc.AccountInformationProvider)3 TransactionGateway (co.rsk.net.TransactionGateway)3 DslParser (co.rsk.test.dsl.DslParser)3 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)3 TrieStore (co.rsk.trie.TrieStore)3 Block (org.ethereum.core.Block)3