Search in sources :

Example 11 with RskAddress

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

the class BridgeSupportTest method removeLockWhitelistAddress_invalidAddress.

@Test
public void removeLockWhitelistAddress_invalidAddress() throws IOException {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = ECKey.fromPublicOnly(Hex.decode(// Public key hex of the authorized whitelist admin in regtest, taken from BridgeRegTestConstants
    "04641fb250d7ca7a1cb4f530588e978013038ec4294d084d248869dd54d98873e45c61d00ceeaeeb9e35eab19fa5fbd8f07cb8a5f0ddba26b4d4b18349c09199ad")).getAddress();
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksForWhitelistTests(mockedWhitelist);
    Assert.assertEquals(-2, bridgeSupport.removeLockWhitelistAddress(mockedTx, "i-am-invalid").intValue());
    verify(mockedWhitelist, never()).remove(any());
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with RskAddress

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

the class BridgeSupportTest method voteFederationChange_notAuthorized.

@Test
public void voteFederationChange_notAuthorized() throws IOException {
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksForFederationTests(false, null, null, null, null, null, null);
    ABICallSpec spec = new ABICallSpec("create", new byte[][] {});
    Transaction mockedTx = mock(Transaction.class);
    when(mockedTx.getSender()).thenReturn(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(12L)).getAddress()));
    Assert.assertEquals(BridgeSupport.FEDERATION_CHANGE_GENERIC_ERROR_CODE, bridgeSupport.voteFederationChange(mockedTx, spec));
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with RskAddress

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

the class RskForksBridgeTest method before.

@Before
public void before() throws IOException, ClassNotFoundException {
    World world = new World();
    blockChain = world.getBlockChain();
    repository = blockChain.getRepository();
    whitelistManipulationKey = ECKey.fromPrivate(Hex.decode("3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc0563c371fa88259c"));
    genesis = (Genesis) blockChain.getBestBlock();
    keyHoldingRSKs = new ECKey();
    co.rsk.core.Coin balance = new co.rsk.core.Coin(new BigInteger("10000000000000000000"));
    repository.addBalance(new RskAddress(keyHoldingRSKs.getAddress()), balance);
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockChain.getBlockStore().saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    Transaction whitelistAddressTx = buildWhitelistTx();
    Transaction receiveHeadersTx = buildReceiveHeadersTx();
    Transaction registerBtctransactionTx = buildRegisterBtcTransactionTx();
    blockBase = buildBlock(genesis, whitelistAddressTx, receiveHeadersTx, registerBtctransactionTx);
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(blockBase));
}
Also used : org.ethereum.core(org.ethereum.core) Coin(co.rsk.bitcoinj.core.Coin) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) World(co.rsk.test.World) Before(org.junit.Before)

Example 14 with RskAddress

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

the class MinerUtilsTest method harmfulTransactionTest.

@Test
public void harmfulTransactionTest() {
    Transaction tx = Tx.create(config, 0, 50000, 1, 0, 0, 0);
    List<Transaction> txs = new LinkedList<>();
    txs.add(tx);
    Mockito.when(tx.getGasPrice()).thenReturn(null);
    Map<RskAddress, BigInteger> accountNounces = new HashMap();
    byte[] addressBytes = ByteUtil.leftPadBytes(BigInteger.valueOf(new Random(0).nextLong()).toByteArray(), 20);
    accountNounces.put(new RskAddress(addressBytes), BigInteger.valueOf(0));
    Repository repository = Mockito.mock(Repository.class);
    Coin minGasPrice = Coin.valueOf(2L);
    LinkedList<Transaction> txsToRemove = new LinkedList<>();
    List<Transaction> res = new MinerUtils().filterTransactions(txsToRemove, txs, accountNounces, repository, minGasPrice);
    Assert.assertEquals(0, res.size());
    Assert.assertEquals(1, txsToRemove.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 15 with RskAddress

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

the class MinerUtilsTest method invalidGasPriceTransactionTest.

@Test
public void invalidGasPriceTransactionTest() {
    Transaction tx = Tx.create(config, 0, 50000, 1, 0, 0, 0);
    List<Transaction> txs = new LinkedList<>();
    txs.add(tx);
    Map<RskAddress, BigInteger> accountNounces = new HashMap();
    byte[] addressBytes = ByteUtil.leftPadBytes(BigInteger.valueOf(new Random(0).nextLong()).toByteArray(), 20);
    accountNounces.put(new RskAddress(addressBytes), BigInteger.valueOf(0));
    Repository repository = Mockito.mock(Repository.class);
    Coin minGasPrice = Coin.valueOf(2L);
    LinkedList<Transaction> txsToRemove = new LinkedList<>();
    List<Transaction> res = new MinerUtils().filterTransactions(txsToRemove, txs, accountNounces, repository, minGasPrice);
    Assert.assertEquals(0, res.size());
    Assert.assertEquals(1, txsToRemove.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)

Aggregations

RskAddress (co.rsk.core.RskAddress)174 Test (org.junit.Test)102 Repository (org.ethereum.core.Repository)60 BigInteger (java.math.BigInteger)47 Coin (co.rsk.core.Coin)38 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 DataWord (org.ethereum.vm.DataWord)27 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)24 RepositoryImpl (co.rsk.db.RepositoryImpl)16 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)15 Transaction (org.ethereum.core.Transaction)15 Program (org.ethereum.vm.program.Program)15 InvocationOnMock (org.mockito.invocation.InvocationOnMock)14 AccountState (org.ethereum.core.AccountState)12 HashMapDB (org.ethereum.datasource.HashMapDB)11 ArrayList (java.util.ArrayList)10 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)10 BridgeConstants (co.rsk.config.BridgeConstants)8 RskSystemProperties (co.rsk.config.RskSystemProperties)8 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)8