use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.
the class BridgeSupportTestPowerMock method removeLockWhitelistAddress_notAuthorized.
@Test
public void removeLockWhitelistAddress_notAuthorized() {
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.removeLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN").intValue());
verify(mockedWhitelist, never()).remove(any());
}
use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.
the class BridgeSupportTestPowerMock method setLockWhitelistDisableBlockDelay_disableBlockDelayBIBiggerThanInt.
@Test(expected = ArithmeticException.class)
public void setLockWhitelistDisableBlockDelay_disableBlockDelayBIBiggerThanInt() throws IOException, BlockStoreException {
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);
when(mockedWhitelist.isDisableBlockSet()).thenReturn(false);
int bestChainHeight = 10;
BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
StoredBlock storedBlock = mock(StoredBlock.class);
when(storedBlock.getHeight()).thenReturn(bestChainHeight);
when(btcBlockStore.getChainHead()).thenReturn(storedBlock);
BridgeSupport bridgeSupport = getBridgeSupportWithMocksAndBtcBlockstoreForWhitelistTests(mockedWhitelist, btcBlockStore);
// Duplicate Int Max Value by 2 because its signed and add 1 to pass the limit
BigInteger disableBlockDelayBI = BigInteger.valueOf((long) Integer.MAX_VALUE * 2 + 1);
bridgeSupport.setLockWhitelistDisableBlockDelay(mockedTx, disableBlockDelayBI);
verify(mockedWhitelist, never()).put(any(), any());
}
use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.
the class BridgeSupportTestPowerMock method addLockWhitelistAddress_notAuthorized.
@Test
public void addLockWhitelistAddress_notAuthorized() {
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.addOneOffLockWhitelistAddress(mockedTx, "mwKcYS3H8FUgrPtyGMv3xWvf4jgeZUkCYN", BigInteger.valueOf(Coin.COIN.getValue())).intValue());
verify(mockedWhitelist, never()).put(any(), any());
}
use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.
the class BridgeSupportTestPowerMock method setLockWhitelistDisableBlockDelay_negativeDisableBlockBI.
@Test
public void setLockWhitelistDisableBlockDelay_negativeDisableBlockBI() throws IOException, BlockStoreException {
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);
when(mockedWhitelist.isDisableBlockSet()).thenReturn(false);
int bestChainHeight = 10;
BtcBlockStoreWithCache btcBlockStore = mock(BtcBlockStoreWithCache.class);
StoredBlock storedBlock = mock(StoredBlock.class);
when(storedBlock.getHeight()).thenReturn(bestChainHeight);
when(btcBlockStore.getChainHead()).thenReturn(storedBlock);
BtcBlock btcBlock = mock(BtcBlock.class);
doReturn(Sha256Hash.of(Hex.decode("aa"))).when(btcBlock).getHash();
doReturn(btcBlock).when(storedBlock).getHeader();
BridgeSupport bridgeSupport = getBridgeSupportWithMocksAndBtcBlockstoreForWhitelistTests(mockedWhitelist, btcBlockStore);
BigInteger disableBlockDelayBI = BigInteger.valueOf(-2);
Assert.assertEquals(-2, bridgeSupport.setLockWhitelistDisableBlockDelay(mockedTx, disableBlockDelayBI).intValue());
verify(mockedWhitelist, never()).put(any(), any());
}
use of co.rsk.peg.whitelist.LockWhitelist in project rskj by rsksmart.
the class BridgeSupport method verifyLockSenderIsWhitelisted.
private boolean verifyLockSenderIsWhitelisted(Address senderBtcAddress, Coin totalAmount, int height) {
// If the address is not whitelisted, then return the funds
// using the exact same utxos sent to us.
// That is, build a release transaction and get it in the release transaction set.
// Otherwise, transfer SBTC to the sender of the BTC
// The RSK account to update is the one that matches the pubkey "spent" on the first bitcoin tx input
LockWhitelist lockWhitelist = provider.getLockWhitelist();
if (!lockWhitelist.isWhitelistedFor(senderBtcAddress, totalAmount, height)) {
logger.info("Rejecting lock. Address {} is not whitelisted.", senderBtcAddress);
return false;
}
// Consume this whitelisted address
lockWhitelist.consume(senderBtcAddress);
return true;
}
Aggregations