Search in sources :

Example 96 with RskAddress

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

the class BridgeSupportTest method removeLockWhitelistAddress_removeFails.

@Test
public void removeLockWhitelistAddress_removeFails() 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);
    when(mockedWhitelist.remove(any(Address.class))).then((InvocationOnMock m) -> {
        Address address = m.getArgumentAt(0, Address.class);
        Assert.assertEquals("mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", address.toBase58());
        return false;
    });
    Assert.assertEquals(-1, bridgeSupport.removeLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN").intValue());
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with RskAddress

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

the class BridgeSupportTest method removeLockWhitelistAddress_ok.

@Test
public void removeLockWhitelistAddress_ok() 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);
    when(mockedWhitelist.remove(any(Address.class))).then((InvocationOnMock m) -> {
        Address address = m.getArgumentAt(0, Address.class);
        Assert.assertEquals("mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", address.toBase58());
        return true;
    });
    Assert.assertEquals(1, bridgeSupport.removeLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN").intValue());
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 98 with RskAddress

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

the class BridgeSupportTest method addLockWhitelistAddress_notAuthorized.

@Test
public void addLockWhitelistAddress_notAuthorized() throws IOException {
    Transaction mockedTx = mock(Transaction.class);
    byte[] senderBytes = Hex.decode("0000000000000000000000000000000000aabbcc");
    RskAddress sender = new RskAddress(senderBytes);
    when(mockedTx.getSender()).thenReturn(sender);
    LockWhitelist mockedWhitelist = mock(LockWhitelist.class);
    BridgeSupport bridgeSupport = getBridgeSupportWithMocksForWhitelistTests(mockedWhitelist);
    Assert.assertEquals(BridgeSupport.LOCK_WHITELIST_GENERIC_ERROR_CODE.intValue(), bridgeSupport.addLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", BigInteger.valueOf(Coin.COIN.getValue())).intValue());
    verify(mockedWhitelist, never()).put(any(), 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 99 with RskAddress

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

the class BridgeSupportTest method voteFeePerKbChange_successfulVoteWithFeeChange.

@Test
public void voteFeePerKbChange_successfulVoteWithFeeChange() {
    Repository repositoryMock = mock(Repository.class);
    BridgeStorageProvider provider = mock(BridgeStorageProvider.class);
    Transaction tx = mock(Transaction.class);
    BridgeConstants constants = mock(BridgeConstants.class);
    AddressBasedAuthorizer authorizer = mock(AddressBasedAuthorizer.class);
    byte[] senderBytes = ByteUtil.leftPadBytes(new byte[] { 0x43 }, 20);
    when(provider.getFeePerKbElection(any())).thenReturn(new ABICallElection(authorizer));
    when(tx.getSender()).thenReturn(new RskAddress(senderBytes));
    when(constants.getFeePerKbChangeAuthorizer()).thenReturn(authorizer);
    when(authorizer.isAuthorized(tx)).thenReturn(true);
    when(authorizer.isAuthorized(tx.getSender())).thenReturn(true);
    when(authorizer.getRequiredAuthorizedKeys()).thenReturn(1);
    BridgeSupport bridgeSupport = new BridgeSupport(config, repositoryMock, null, constants, provider, null, null);
    assertThat(bridgeSupport.voteFeePerKbChange(tx, Coin.CENT), is(1));
    verify(provider).setFeePerKb(Coin.CENT);
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) BridgeConstants(co.rsk.config.BridgeConstants) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 100 with RskAddress

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

the class BridgeSupportTest method addLockWhitelistAddress_ok.

@Test
public void addLockWhitelistAddress_ok() 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);
    when(mockedWhitelist.put(any(Address.class), any(Coin.class))).then((InvocationOnMock m) -> {
        Address address = m.getArgumentAt(0, Address.class);
        Assert.assertEquals("mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", address.toBase58());
        return true;
    });
    Assert.assertEquals(1, bridgeSupport.addLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", BigInteger.valueOf(Coin.COIN.getValue())).intValue());
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) RskAddress(co.rsk.core.RskAddress) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RskAddress(co.rsk.core.RskAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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