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