Search in sources :

Example 11 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class AccountStateTest method encodeDecodeStateWith238InStateFlags.

@Test
public void encodeDecodeStateWith238InStateFlags() {
    AccountState acct = new AccountState(BigInteger.ZERO, new Coin(BigInteger.valueOf(2).pow(200)));
    acct.setStateFlags(238);
    AccountState result = new AccountState(acct.getEncoded());
    assertEquals(BigInteger.ZERO, result.getNonce());
    assertEquals(BigInteger.valueOf(2).pow(200), result.getBalance().asBigInteger());
    assertEquals(238, result.getStateFlags());
}
Also used : Coin(co.rsk.core.Coin) Test(org.junit.Test)

Example 12 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class AccountStateTest method testGetEncoded.

@Test
public void testGetEncoded() {
    String expected = "f85e809" + "a0100000000000000000000000000000000000000000000000000" + "a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + "a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
    AccountState acct = new AccountState(BigInteger.ZERO, new Coin(BigInteger.valueOf(2).pow(200)));
    assertEquals(expected, Hex.toHexString(acct.getEncoded()));
}
Also used : Coin(co.rsk.core.Coin) Test(org.junit.Test)

Example 13 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class AccountStateTest method encodeDecodeStateWith128InStateFlags.

@Test
public void encodeDecodeStateWith128InStateFlags() {
    AccountState acct = new AccountState(BigInteger.ZERO, new Coin(BigInteger.valueOf(2).pow(200)));
    acct.setStateFlags(128);
    AccountState result = new AccountState(acct.getEncoded());
    assertEquals(BigInteger.ZERO, result.getNonce());
    assertEquals(BigInteger.valueOf(2).pow(200), result.getBalance().asBigInteger());
    assertEquals(128, result.getStateFlags());
}
Also used : Coin(co.rsk.core.Coin) Test(org.junit.Test)

Example 14 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class StateTest method test2.

@Ignore
// calc state after applying first tx on genesis
@Test
public void test2() {
    // explanation:
    // 0) create genesis
    // 1) apply cost of tx to cd2a3d9f938e13cd947ec05abc7fe734df8dd826
    // 2) create AccountState for 77045e71a7a2c50903d88e564cd72fab11e82051
    // 3) minner gets the gas + coinbase ==> 6260000000000000 + 1500000000000000000
    // 4) calc the root
    Trie trie = generateGenesisState();
    Keccak256 expected = new Keccak256("c12b4d771fbcc0d56ec106f8d465d24b9d4c36d60275bbafa7d69694d6708660");
    // Get and update sender in world state
    byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
    byte[] rlpEncodedState = trie.get(cowAddress);
    AccountState account_1 = new AccountState(rlpEncodedState);
    final BigInteger value = new BigInteger("-6260000000001000");
    account_1.addToBalance(new Coin(value));
    account_1.incrementNonce();
    trie = trie.put(cowAddress, account_1.getEncoded());
    // Add contract to world state
    byte[] codeData = Hex.decode("61778e600054");
    AccountState account_2 = new AccountState(BigInteger.ZERO, Coin.valueOf(1000));
    account_2.setCodeHash(HashUtil.keccak256(codeData));
    // generated based on sender + nonce
    byte[] contractAddress = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051");
    trie = trie.put(contractAddress, account_2.getEncoded());
    // this is saved in the db
    // trie.update(HashUtil.sha3(codeData), codeData);
    // Update miner in world state
    byte[] minerAddress = Hex.decode("4c5f4d519dff3c16f0d54b6866e256fbbbc1a600");
    final BigInteger bigInteger = new BigInteger("1506260000000000000");
    AccountState account_3 = new AccountState(BigInteger.ZERO, new Coin(bigInteger));
    trie = trie.put(minerAddress, account_3.getEncoded());
    assertEquals(expected, trie.getHash());
    /* *** GROSS DATA ***

        BlockData [
          hash=22cf863ab836a6f5c29389d2e77f4792a3b3b52908c98ed14b1cbe91491a3e36
          parentHash=77ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6cd9225d285c89
          unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
          coinbase=4c5f4d519dff3c16f0d54b6866e256fbbbc1a600
          stateHash=69c21ff84a5af0b53b11c61110a16d6ad43dad37b3eb29ae8e88c936eb06456a
          txTrieHash=a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f
          difficulty=3ff000
          number=1
          minGasPrice=10000000000000
          gasLimit=999023
          gasUsed=626
          timestamp=1401979976 (2014.06.05 15:52:56)
          extraData=null
          nonce=0000000000000000000000000000000000000000000000005d439960040e4505

        TransactionReceipt[
           TransactionData [ hash=1ee6fa3149a5e9c09b54009eb6e108aaa7ecd79483d57eedcf2dff93a1505588  nonce=null,
               gasPrice=09184e72a000, gas=03e8, receiveAddress=0000000000000000000000000000000000000000, value=03e8,
               data=60016000546006601160003960066000f261778e600054, signatureV=27,
               signatureR=2b379f22050e3554c3fa5423d9040bb28dcc7f905300db4e67c03bcf9b27003c,
               signatureS=59f47793e050974e6b5fca2848b19925637b883a012693b54d712f1c4f74def5
          ]
          , postTxState=7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527
          , cumulativeGas=0272]
        ]

        +++  4c5f4d519dff3c16f0d54b6866e256fbbbc1a600:
        +++  77045e71a7a2c50903d88e564cd72fab11e82051: $[61,77,8e,60,0,54] ([])
         *   cd2a3d9f938e13cd947ec05abc7fe734df8dd826: #1 1606938044258990275541962092341162602522202987522792835300376 (-6260000000001000)
          */
    assertEquals(expected, trie.getHash());
}
Also used : Coin(co.rsk.core.Coin) BigInteger(java.math.BigInteger) Keccak256(co.rsk.crypto.Keccak256) Trie(co.rsk.trie.Trie) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method removeObsoletePendingTransactionsByBlock.

@Test
public void removeObsoletePendingTransactionsByBlock() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Assert.assertEquals(10, transactionPool.getOutdatedThreshold());
    List<Transaction> list = transactionPool.getPendingTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    transactionPool.removeObsoleteTransactions(1, 1, 100);
    list = transactionPool.getPendingTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    transactionPool.removeObsoleteTransactions(20, transactionPool.getOutdatedThreshold(), 100);
    list = transactionPool.getPendingTransactions();
    Assert.assertNotNull(list);
    Assert.assertTrue(list.isEmpty());
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Aggregations

Coin (co.rsk.core.Coin)95 Test (org.junit.Test)46 RskAddress (co.rsk.core.RskAddress)37 BigInteger (java.math.BigInteger)32 Repository (org.ethereum.core.Repository)23 Transaction (org.ethereum.core.Transaction)23 Program (org.ethereum.vm.program.Program)12 AccountState (org.ethereum.core.AccountState)10 ArrayList (java.util.ArrayList)9 Ignore (org.junit.Ignore)9 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)8 Account (org.ethereum.core.Account)7 BlockExecutor (co.rsk.core.bc.BlockExecutor)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 Keccak256 (co.rsk.crypto.Keccak256)5 Block (org.ethereum.core.Block)5 DataWord (org.ethereum.vm.DataWord)5 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 RskSystemProperties (co.rsk.config.RskSystemProperties)4