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);
}
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();
}
};
}
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());
}
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());
}
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());
}
Aggregations