use of co.rsk.rpc.modules.trace.ProgramSubtrace in project rskj by rsksmart.
the class RemascFeesPayerTest method payMiningFees.
@Test
public void payMiningFees() {
// Setup objects
Repository repositoryMock = Mockito.mock(Repository.class);
RemascFeesPayer feesPayer = new RemascFeesPayer(repositoryMock, PrecompiledContracts.REMASC_ADDR);
byte[] blockHash = { 0x1, 0x2 };
Coin value = Coin.valueOf(7L);
RskAddress toAddress = new RskAddress("6c386a4b26f73c802f34673f7248bb118f97424a");
List<LogInfo> logs = new ArrayList<>();
// Do call
feesPayer.payMiningFees(blockHash, value, toAddress, logs);
Assert.assertEquals(1, feesPayer.getSubtraces().size());
ProgramSubtrace subtrace = feesPayer.getSubtraces().get(0);
Assert.assertEquals(DataWord.valueOf(PrecompiledContracts.REMASC_ADDR.getBytes()), subtrace.getInvokeData().getCallerAddress());
Assert.assertEquals(DataWord.valueOf(toAddress.getBytes()), subtrace.getInvokeData().getOwnerAddress());
Assert.assertEquals(DataWord.valueOf(value.getBytes()), subtrace.getInvokeData().getCallValue());
Assert.assertEquals(1, logs.size());
// Assert address that made the log
LogInfo result = logs.get(0);
Assert.assertArrayEquals(PrecompiledContracts.REMASC_ADDR.getBytes(), result.getAddress());
// Assert log topics
Assert.assertEquals(2, result.getTopics().size());
Assert.assertEquals("000000000000000000000000000000006d696e696e675f6665655f746f706963", result.getTopics().get(0).toString());
Assert.assertEquals("0000000000000000000000006c386a4b26f73c802f34673f7248bb118f97424a", result.getTopics().get(1).toString());
// Assert log data
Assert.assertNotNull(result.getData());
List<RLPElement> rlpData = RLP.decode2(result.getData());
Assert.assertEquals(1, rlpData.size());
RLPList dataList = (RLPList) rlpData.get(0);
Assert.assertEquals(2, dataList.size());
Assert.assertArrayEquals(blockHash, dataList.get(0).getRLPData());
Assert.assertEquals(value, RLP.parseCoin(dataList.get(1).getRLPData()));
// Assert repository calls are made right
verify(repositoryMock, times(1)).addBalance(PrecompiledContracts.REMASC_ADDR, value.negate());
verify(repositoryMock, times(1)).addBalance(toAddress, value);
}
Aggregations