Search in sources :

Example 86 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class SamplePrecompiledContractTest method samplePrecompiledContractAddBalanceOk.

@Test
public void samplePrecompiledContractAddBalanceOk() {
    DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
    SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
    String funcJson = "{\n" + "   'constant':false, \n" + "   'inputs':[], \n" + "    'name':'AddBalance', \n" + "   'outputs':[], \n" + "    'type':'function' \n" + "}\n";
    funcJson = funcJson.replaceAll("'", "\"");
    CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
    byte[] data = function.encode();
    Repository repository = new RepositoryImpl(config);
    contract.init(null, null, repository, null, null, new ArrayList<LogInfo>());
    contract.execute(data);
    int balance = this.GetBalance(repository);
    assertEquals(50000, balance);
}
Also used : Repository(org.ethereum.core.Repository) LogInfo(org.ethereum.vm.LogInfo) RepositoryImpl(co.rsk.db.RepositoryImpl) CallTransaction(org.ethereum.core.CallTransaction) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 87 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class ActiveFederationTest method buildInitializer.

private BridgeStorageProviderInitializer buildInitializer(boolean genesis) {
    final int minFederators = 10;
    final int maxFederators = 16;
    return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
        if (!genesis) {
            int numFederators = Helper.randomInRange(minFederators, maxFederators);
            List<BtcECKey> federatorKeys = new ArrayList<>();
            for (int i = 0; i < numFederators; i++) {
                federatorKeys.add(new BtcECKey());
            }
            federation = new Federation(federatorKeys, Instant.ofEpochMilli(new Random().nextLong()), Helper.randomInRange(1, 10), networkParameters);
            provider.setNewFederation(federation);
        } else {
            federation = bridgeConstants.getGenesisFederation();
        }
    };
}
Also used : Repository(org.ethereum.core.Repository) Random(java.util.Random) Federation(co.rsk.peg.Federation) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) ArrayList(java.util.ArrayList) List(java.util.List) BtcECKey(co.rsk.bitcoinj.core.BtcECKey)

Example 88 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class MinerUtilsTest method validTransactionRepositoryNonceTest.

@Test
public void validTransactionRepositoryNonceTest() {
    Transaction tx = Tx.create(config, 0, 50000, 5, 0, 0, 0);
    // Mockito.when(tx.checkGasPrice(Mockito.any(BigInteger.class))).thenReturn(true);
    List<Transaction> txs = new LinkedList<>();
    txs.add(tx);
    Map<RskAddress, BigInteger> accountNounces = new HashMap();
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(repository.getNonce(tx.getSender())).thenReturn(BigInteger.valueOf(0));
    Coin minGasPrice = Coin.valueOf(1L);
    List<Transaction> res = new MinerUtils().filterTransactions(new LinkedList<>(), txs, accountNounces, repository, minGasPrice);
    Assert.assertEquals(1, res.size());
}
Also used : Coin(co.rsk.core.Coin) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 89 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class MinerUtilsTest method validTransactionAccWrapNonceTest.

@Test
public void validTransactionAccWrapNonceTest() {
    Transaction tx = Tx.create(config, 0, 50000, 5, 1, 0, 0);
    // Mockito.when(tx.checkGasPrice(Mockito.any(BigInteger.class))).thenReturn(true);
    List<Transaction> txs = new LinkedList<>();
    txs.add(tx);
    Map<RskAddress, BigInteger> accountNounces = new HashMap();
    accountNounces.put(tx.getSender(), BigInteger.valueOf(0));
    Repository repository = Mockito.mock(Repository.class);
    Coin minGasPrice = Coin.valueOf(1L);
    List<Transaction> res = new MinerUtils().filterTransactions(new LinkedList<>(), txs, accountNounces, repository, minGasPrice);
    Assert.assertEquals(1, res.size());
}
Also used : Coin(co.rsk.core.Coin) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 90 with Repository

use of org.ethereum.core.Repository in project rskj by rsksmart.

the class TransactionPoolImplTest method addAndExecuteTwoPendingTransaction.

@Test
public void addAndExecuteTwoPendingTransaction() {
    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);
    Account receiver = createAccount(2);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Repository repository = transactionPool.getRepository();
    Assert.assertEquals(BigInteger.valueOf(1004000), repository.getBalance(receiver.getAddress()).asBigInteger());
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Aggregations

Repository (org.ethereum.core.Repository)136 Test (org.junit.Test)109 RskAddress (co.rsk.core.RskAddress)59 DataWord (org.ethereum.vm.DataWord)43 BigInteger (java.math.BigInteger)31 RepositoryImpl (co.rsk.db.RepositoryImpl)25 Coin (co.rsk.core.Coin)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 HashMapDB (org.ethereum.datasource.HashMapDB)12 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)11 Transaction (org.ethereum.core.Transaction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)10 ArrayList (java.util.ArrayList)10 Program (org.ethereum.vm.program.Program)10 Block (org.ethereum.core.Block)9 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)9 RskSystemProperties (co.rsk.config.RskSystemProperties)8 IOException (java.io.IOException)8 List (java.util.List)8